Post Reply

[HOW TO] Add screenshot option in power menu for every rom

OP Tof37

4th June 2012, 08:45 PM   |  #1  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
Here it is ....
As some people here asked for it I'll try to explain how I learned to add screenshot option in power menu.

First I'd like to thank some special members that helped me a lot for doing this :
Championswimmer, Barath_000, Achotjan

First you need to know it's not an easy thing to do and you may have bootloop, reboot etc ... that's why you need time and most of everything backup to restore the modded files.

You'll need tools to do this.
I used a "all in one tool": android utility (thanks to tommytomatoe)
http://forum.xda-developers.com/show....php?t=1167623
It can be used on linux / mac laptop

If you don't want to use it or using windows laptop you'll need apktool and dex2jar


Before beginning :
Make a backup of these 2 files in system/framework :

framework-res.apk

android.poilicy.jar

Why ? you'll work on these files so if it doesn't work you'll have a "safe working base" ...

Ready ?

1.Framework-res.apk
Decompile this file (with android utility or apktool)

In the "drawable-hpdi" folder place the png attached, and named it "whateveryouwant".
I advice you to keep the name it got as all my how to will name it like that

Then go in the values folder,

You'll find several xml files, with notepad ++ or other xml editor open*: strings.xml and public*.xml

In strings.xml:

Add this line at the end of the file just above </resources> add the line*:

<string name="global_action_screenshot_txt">Take screenshot</string>

It must look like that*:

Quote:

<string name="add_region_in_locale_picker_dummy_string">+</string>
<string name="global_action_sleep">Sleep mode</string>
<string name="global_action_screenshot_txt">Take screenshot</string>
</resources>


Save and close strings.xml

Open public.xml

In the fitting section (drawable and strings) add these lines :

<public type="string" name="global_action_screenshot_txt" id="0x010403da" />

<public type="drawable" name="semc_ic_dialog_screenshot" id="0x0108057f" />

Little tip for "how to" choose the id's (0x010403da and 0x0108057f)

- Search for the last ID for the category (for drawable the last one was0x0108057e)
- write the next letter or number ... (last one was 0x0108057e so the next one is 0x0108057f)

Tip number 2 for the ID ...
the letter list begin to a and finish to f
the number list begins to 0 and finish to 9
Finding the fitting ID can take time so stay calm and relax

Once you've done that, save public.xml but don't close it you'll need it later ....

Now you can compile your framework-res.apk
If you did something wrong apktool will write it .. just read and repair what's wrong.

Now the framework is set, you need now to tell the device wich action you want to run when you tap the option on screen.

2. Andorid.policy.jar

Decompile this file.
Go to com/android/internal/policy/impl folder

Here you'll fond some smali files.
Find the smali named GlobalActions.smali and open it.

In the # annotations thread add this line
Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;,

in must look like this :
Quote:

# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;,
Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;,
Lcom/android/internal/policy/impl/GlobalActions$Action;,
Lcom/android/internal/policy/impl/GlobalActions$MyAdapter;
}
.end annotation

In the # instance fields thread add this line :
.field private mCaptureScreenshot:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;

It must look like this :

Quote:

# instance fields
.field private mAdapter:Lcom/android/internal/policy/impl/GlobalActions$MyAdapter;

.field private mAirplaneModeOn:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

.field private mAirplaneState:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction$State;

.field private final mAudioManager:Landroid/media/AudioManager;

.field private mBroadcastReceiver:Landroid/content/BroadcastReceiver;

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

.field private final mContext:Landroid/content/Context;

.field private mDeviceProvisioned:Z

.field private mDialog:Landroid/app/AlertDialog;

.field private mHandler:Landroid/os/Handler;

.field private mIsWaitingForEcmExit:Z

.field private mItems:Ljava/util/ArrayList;
.annotation system Ldalvik/annotation/Signature;
value = {
"Ljava/util/ArrayList",
"<",
"Lcom/android/internal/policy/impl/GlobalActions$Action;",
">;"
}
.end annotation
.end field

Is that all ??? No !!!!!

Search the line 195
It must be like this in stock rom :

Quote:

.line 195
const/4 v0, 0x3

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

const/4 v1, 0x0

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

aput-object v2, v0, v1

If there's const/4 v0, 0x4 : this tell the system how many options you've got in the power menu (here 4)

Just under .line 195 add these lines :

Quote:

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

const v1, 0x108057f

const v2, 0x10403da

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

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

Now it must look like this

Quote:

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

const v1, 0x108057f

const v2, 0x10403da

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

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

const/4 v0, 0x4

What that mean ????

Quote:

const v1, 0x108057f

= the ID in public.xml for the Drawable ... ATTENTION : the ID must be written without the 0 (in public.xml = 0x0108057f ; in android policy 0x108057f )

Quote:

const v2, 0x10403da

= the ID in public.xml for the string
respect this order

Quote:

invoke-direct {v0, p0, v1, v2}, Lcom/android/internal/policy/impl/GlobalActions$8

In the IMPL folder of the decompiled android.policy.jar you'll see several files named GlobalActions$1.smali ; GlobalActions$2.smali; etc ....
You'll need to create a smali file, it's name will follow the already existing name ... if the last one is GlobalActions$7.smali then you'll create GlobalActions$8.smali ...

What should I get in this file ?????
Calm down and take the GlobalActions$8.smali attached, rename it if you need, but don't forget to rename inside it all GlobalActions$8 entries in GlobalActions$thenumberyouchoose


Once you've done that get back to GlobalActions.smali ....

Find this line
Quote:

invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/ObjectLjava/util/ArrayList;

just above add

Quote:

const/4 v1, 0x3

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

aput-object v2, v0, v1

const/4 v1, 0x4

Added Globalactions.txt file so you can compare with yours

Here it is, work in android.policy is over ... save and close the GlobalActions file, and recompile android.policy.jar

Ready to flash ? .. so must build a zip file with good permissions and all the files ...

Find a flashing zip and decompress it
Create these folder
system/framework
system/app
system/bin

Inside framework folder get framework-res.apk and android.policy.jar you compiled
inside bin get the screenshot file (see attachement)
inside app get CMscreenshot.apk (see attachement)

edit your update-script to get these line : (translation for edify script can be done easily)

Quote:

copy_dir PACKAGE:system SYSTEM:
set_perm 0 0 04755 SYSTEM:bin/screenshot

permissions are needed or else you'll get error (saved to null ...) will taking screenshot

save, compresss make your zip ...

MAKE A BACKUP

And flash ....

reboot .... and enjoy the screenshot option

Hope it helps ..
Once again take your time ... if you're novice in modding it'll take time ... it took me nearly one month to do it ...
Attached Images
 
Attached Files
File Type: apk CMScreenshot.apk - [Click for QR Code] (9.2 KB, 1276 views)
File Type: zip GlobalActions$8.zip - [Click for QR Code] (2.0 KB, 1436 views)
File Type: zip bin.zip - [Click for QR Code] (2.8 KB, 1002 views)
File Type: txt GlobalActions.txt - [Click for QR Code] (23.9 KB, 1259 views)
Last edited by Tof37; 14th June 2012 at 09:49 PM.
The Following 60 Users Say Thank You to Tof37 For This Useful Post: [ View ]
4th June 2012, 08:46 PM   |  #2  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
FAQ :

Q: Can't find GlobalActions$8.smali in attachment

A: Download GlobalActions$8.zip and rename it GlobalActions$8.smali ....

Q: Can't find the screenshot file to place in bin folder

A : download bin.zip .... it's in

Q: Why can't I use the screencapture.apk from Arc, Neo, Xperia S etc ...

A: We still fighting to make it working ...
Last edited by Tof37; 4th June 2012 at 08:59 PM.
The Following 5 Users Say Thank You to Tof37 For This Useful Post: [ View ]
4th June 2012, 09:04 PM   |  #3  
Recognized Themer
Thanks Meter: 1,072
 
1,180 posts
Join Date:Joined: Nov 2011
More
Thanks Tof, very useful
Just one question, in my decompiled framework-res, in "public.xml", drawable section are totally mixed order, is there an easier way to find the last id?
The Following User Says Thank You to NuriJ For This Useful Post: [ View ]
4th June 2012, 09:06 PM   |  #4  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
Quote:
Originally Posted by LzVebz

Thanks Tof, very useful
Just one question, in my decompiled framework-res, in "public.xml", drawable section are totally mixed order, is there an easier way to find the last id?

To be honest I don't know easier way than writing the ID you want to get and search if it already exist ..
If someone have a useful xml editor that can sort ID by section ...
The Following User Says Thank You to Tof37 For This Useful Post: [ View ]
4th June 2012, 09:52 PM   |  #5  
FeraVolt's Avatar
Senior Member
Thanks Meter: 13,188
 
1,764 posts
Join Date:Joined: Dec 2011
Donate to Me
More
I thought..ID's are reading automatically if they miss...only if you add them in strings and xmls…
Finaly here thanks Tof )
The Following 2 Users Say Thank You to FeraVolt For This Useful Post: [ View ]
4th June 2012, 10:02 PM   |  #6  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
Quote:
Originally Posted by FeraVolt

I thought..ID's are reading automatically if they miss...only if you add them in strings and xmls…
Finaly here thanks Tof )

Finally took time to write it
Got me long long nights with my computer to get it working ... hope it wold help people to have more sleep time

For ID you're not wrong .. ID are getting automatically if you compile from sources (I may be wrong but it's what I understood )
The Following User Says Thank You to Tof37 For This Useful Post: [ View ]
5th June 2012, 05:17 PM   |  #7  
dettofatto's Avatar
Senior Member
Flag Roma
Thanks Meter: 130
 
470 posts
Join Date:Joined: May 2006
Donate to Me
More
First: THANK YOU!!!

Then... :)

I've... some issues...
My globalaction now is:

Code:
 .line 232
    new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$11;

    const v1, 0x1080452

    const v2, 0x10404f5

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

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

    const/4 v0, 0x6

    const/4 v0, 0x5

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

    iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions;->mSilentModeToggle:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

    aput-object v1, v0, v10
It is wrong?


Now i'm trying with this, without success:

Code:
.line 232

    const/4 v0, 0x5

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

    iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions;->mSilentModeToggle:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

    aput-object v1, v0, v10

    iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions;->mAirplaneModeOn:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

    aput-object v1, v0, v9

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

    const v2, 0x1080418

    const v3, 0x10403fc

    const v4, 0x10403fd

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

    aput-object v1, v0, v11

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

    const v2, 0x1080030

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

    aput-object v1, v0, v12

    const/4 v1, 0x4

    new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$10;

    const v3, 0x108044e

    const v4, 0x1040508

    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

    invoke-static {v0}, Lcom/google/android/collect/Lists;->newArrayList([Ljava/lang/Object;)Ljava/util/ArrayList;
    const/4 v1, 0x3

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

    aput-object v2, v0, v1

    const/4 v1, 0x4

    move-result-object v0

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

    const/4 v1, 0x5

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

    const v1, 0x1080452

    const v2, 0x10404f5

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

    iput-object v0, p0, Lcom/android/internal/policy/impl/GlobalActions;->mCaptureScreenshot:Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;
Yes, I know there are a lot of things... But I'm sure that there is something in this file...
Last edited by dettofatto; 5th June 2012 at 05:39 PM.
5th June 2012, 06:57 PM   |  #8  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
@dettofatto
Yes there are some errors in your file but can't correctly quote your post since I'm on phone... Recheck with op first until I get back home to show your errors

Sent from my X10s using XDA
5th June 2012, 09:05 PM   |  #9  
Tof37's Avatar
OP Senior Member
Flag Tours
Thanks Meter: 2,670
 
611 posts
Join Date:Joined: Oct 2009
Donate to Me
More
Quote:
Originally Posted by dettofatto

First: THANK YOU!!!

Then... :)

I've... some issues...
My globalaction now is:

Code:
 .line 232
    new-instance v0, Lcom/android/internal/policy/impl/GlobalActions$11;

    const v1, 0x1080452

    const v2, 0x10404f5

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

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

    const/4 v0, 0x6

    const/4 v0, 0x5 ----not needed cause line just above is enough

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

    iget-object v1, p0, Lcom/android/internal/policy/impl/GlobalActions;->mSilentModeToggle:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

    aput-object v1, v0, v10
It is wrong?

See above in red
The Following User Says Thank You to Tof37 For This Useful Post: [ View ]
5th June 2012, 11:53 PM   |  #10  
dettofatto's Avatar
Senior Member
Flag Roma
Thanks Meter: 130
 
470 posts
Join Date:Joined: May 2006
Donate to Me
More
And so I'll have 0x4 and 0x6 without 0x5?

Or I must put all your new lines under 0x5?

Because my. 232 line starts with constant 0x5...
And so I thought that the new screenshot has 0x6...
Or new lines start before 0x5?
Tomorrow I'll try all these options and I'll see!

I'm wrong?

Thank you...

Sent from My Motosola....
Last edited by dettofatto; 5th June 2012 at 11:58 PM.

Post Reply Subscribe to Thread

Tags
power menu, screenshot
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes