[DEV] How to add EDT Tweaks support in your odexed ROM/Themes - Galaxy S II Android Development

Original Threads (deodexed ROM/Themes)
[MOD] [JVP] Statusbar Tweaks - EDT
[MODS][MORPH] Kahvitahra's mods - EDT TWEAK
How to get it working on an ODEXED ROM!
The only file we are going to modify is /system/app/SystemUI.apk
If you already got this apk deodexed skip to step#2 (you can check for it by opening SystemUI.apk and check if classes.dex is already present)
Step#1 (baksmali)
You need to baksmali SystemUI.apk, i suppose you already know how to do it, if not just use search button!!!
Step#2 (apk-manager)
I am using apk-manager, so before to continue make sure you already have this tool installed and working!
Copy deodexed SystemUI.apk to place-apk-here-for-modding folder
Start Script.bat (don't close this windows we will use it later on)
Select option "19) Select compression level for apk's" and hit 0
Set current project (option 22)
Decompile apk (option 9)
go to projects\SystemUI.apk\res\layout and overwrite status_bar.xml with the file attached
go to projects\SystemUI.apk\smali\com\android\systemui\statusbar and copy the following files from the attached zip file: BatteryText$1.smali, BatteryText$SettingsObserver.smali, BatteryText.smali, Clock$1.smali, Clock.smali, DateView.smali
go to projects\SystemUI.apk\smali\com\android\systemui\statusbar\policy and overwrite StatusBarPolicy.smali with the one inside the zip file attacched
go back to the apk-manager windows (cmd.exe windows started with Script.bat) and select "Compile apk" (option 11)
just answer "yes" to the two questions you will promt!
Now before to go ahead, you will notice that a new folder "keep" has been created, open up that folder and delete "classes.dex" and "resources.arsc" then go to res/layout folder and delete status_bar.xml
Go back to the apk-manager windows and press enter to continue!
At the end you will see in place-apk-here-for-modding folder you modified unsignedSystemUI.apk
Step#3 (odex back)
-Download and copy "dexopt-wrapper" on /system/bin
-In adb just type:
Code:
adb shell echo $BOOTCLASSPATH
you should use the above string later on!
-copy "unsignedSystemUI.apk" from your pc to your /sdcard/mod folder (create this folder) and rename it to SystemUI.apk
-copy /sdcard/mod/SystemUI.apk to /sdcard/mod/done/SystemUI.apk, now open without extract it (use 7zip winrar..) and delete classes.dex.
Code:
> adb remount
> adb shell
# su
# cd /system/bin
# busybox chmod 755 dexopt-wrapper
Now you have right permission for dexopt-wrapper
Let's create a new .odex file from the SystemUI.apk file
Code:
# cd /sdcard/mod
# dexopt-wrapper SystemUI.apk new.odex [BOOTCLASSPATH]
fill in the value of BOOTCLASSPATH, without the []
do NOT continue until this command succeeds!
At this point your new.odex file won't work because dalvik virtual Machine store checksum for each packages which means that your new.odex file cannot pass this check on boot.
We will fix it:
Copy over the "signature" from the current(original one in your /system/app) .odex file into the new .odex file.
Code:
# busybox dd if=/system/app/SystemUI.odex of=new.odex bs=1 count=20 skip=52 seek=52 conv=notrunc
now replace the old .odex file with the new .odex file. Also we will copy the apk without classes.dex to /system/app
Code:
# cd /system/app
# busybox cp /sdcard/mod/new.odex SystemUI.odex
# busybox chmod 644 SystemUI.odex
# busybox cp /sdcard/mod/done/SystemUI.apk SystemUI.apk
# busybox chmod 644 SystemUI.apk
# sync
# reboot
That's it!
NOTE:
Remember to backup your system before you start doing it, because some time your phone won't boot, maybe because you made some mistake in the smali code you have changed...
I usualy prepare a zip package with the original file i am going to replace, therefore if something goes wrong i can flash them back via CWM the original one!
Hope it can help!
Thanks to Kahvitahra for source code and every single one in this community.
View attachment EDT_sources.zip

Hi mate!
I also moded dateview.smali to show clock in pulldownbar

kahvitahra said:
Hi mate!
I also moded dateview.smali to show clock in pulldownbar
Click to expand...
Click to collapse
Thanks Bro!
\Edit
OP has been updated!

Suggestion for thread title:
How to add EDT Tweaks support in your odexed ROM/Themes.

Another suggestion:
Put links for the original threads on first post:
[MOD] [JVP] Statusbar Tweaks - EDT
[MODS][MORPH] Kahvitahra's mods - EDT TWEAK

OK, after the 1st quick overview i must say...i like my LeoMAR ROM as it is now! ;o)
Never done something like that before and i don´t wanna challenge my luck too much...

Just wonderfull Many thanks

Second way
Edited post

mmmh?
Can i have an italian guide to apply this on my odexed rom? i never use this program...i know only how install a rom! now i have a tweaky rom v2 on my sgs
is it possible to do??? grazie infinite!!!

Hy. Can anyone make me this for XWKJ1 odexed rom pls?

Code:
.method private final updateClock()V
.locals 5
.prologue
.line 78
new-instance v0, Ljava/util/Date;
invoke-direct {v0}, Ljava/util/Date;-><init>()V
.line 85
.local v0, now:Ljava/util/Date;
const/4 v1, 0x2
const/4 v2, 0x0
invoke-static {v1, v2}, Ljava/text/DateFormat;->getDateTimeInstance(II)Ljava/text/DateFormat;
move-result-object v1
invoke-virtual {v1, v0}, Ljava/text/DateFormat;->format(Ljava/util/Date;)Ljava/lang/String;
move-result-object v1
invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/DateView;->setText(Ljava/lang/CharSequence;)V
.line 87
return-void
.end method
Sorry for reviving this thread but i have a question.
With this code in DateView.smali i got an am/pm clock and i use a 24h format.
Anyone knows how to edit DateView.smali or StatusBarPolicy.smali to get a 24H format on the clock in the notification pulldown?
I´ve been searching and found some references but it looks a little "grey" to me, because they only refer on removing the am/pm and not displaying 24h format.
Is there a way to get the correct time format from this line?
Code:
invoke-static {v1, v2}, Ljava/text/DateFormat;->getDateTimeInstance(II)Ljava/text/DateFormat;
Thanks
Edit: If i change system language to Portuguese, the clock displays 24h format, but in english it only displays 12h. Still no go, i want to use english.

battax said:
Code:
.method private final updateClock()V
.locals 5
.prologue
.line 78
new-instance v0, Ljava/util/Date;
invoke-direct {v0}, Ljava/util/Date;-><init>()V
.line 85
.local v0, now:Ljava/util/Date;
const/4 v1, 0x2
const/4 v2, 0x0
invoke-static {v1, v2}, Ljava/text/DateFormat;->getDateTimeInstance(II)Ljava/text/DateFormat;
move-result-object v1
invoke-virtual {v1, v0}, Ljava/text/DateFormat;->format(Ljava/util/Date;)Ljava/lang/String;
move-result-object v1
invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/DateView;->setText(Ljava/lang/CharSequence;)V
.line 87
return-void
.end method
Sorry for reviving this thread but i have a question.
With this code in DateView.smali i got an am/pm clock and i use a 24h format.
Anyone knows how to edit DateView.smali or StatusBarPolicy.smali to get a 24H format on the clock in the notification pulldown?
I´ve been searching and found some references but it looks a little "grey" to me, because they only refer on removing the am/pm and not displaying 24h format.
Is there a way to get the correct time format from this line?
Code:
invoke-static {v1, v2}, Ljava/text/DateFormat;->getDateTimeInstance(II)Ljava/text/DateFormat;
Thanks
Edit: If i change system language to Portuguese, the clock displays 24h format, but in english it only displays 12h. Still no go, i want to use english.
Click to expand...
Click to collapse
Hi!
Getdatetimeinstance gets time format depending to your locale, like you said. With simpledateformat you can achive that what you are looking for.
Im on phone now so cant paste links, but you can navigate to my thread from my signature. There is edt + custom date format. You can pick code from there or just use that the way its done. There is also moded settings.apk so that you can put any format you like in that notification date/time. Affected files are told in those posts.

Thanks i´ve already used your mod yesterday a awhile after my first post, but i will search the code.
Thanks

I believe you can have a deodexed app on your odexed rom. Just remember to remove (backup) the 2 odexed files and clear dalvik-cache.
PS: this is true only for files in the app folder! Not in the framework folder!
Pps: I should include some of this mod in my mod
Thanks!
Sent from my GT-I9100 using xda premium

Related

Howto enable Gmail notifications for all new mail with smali/baksmali

The Gmail app on my Hero (possibly on all Android devices?) has one big annoyance: I only get audio and vibration notifications for the first mail received after clearing notifications. If I missed the first notification for some reason, the phone will sit quiet for all subsequent incoming mail until I attend to the existing notification (the notification text will be updated on subsequent mail but no vibration/sound).
This is reported here
http://code.google.com/p/android/issues/detail?id=4190
Since Google seems to ignore this issue I decided to fix it my self. Here is a summary of how I did it, in case someone is interested in doing something similar.
Required knowledge is basic understanding of the Android SDK and some basic knowledge of the concepts of assembler. The latter is required since this involves modifying Dalvik assembly. Don't worry too much, it's MUCH easier than assembly for real CPUs.
Download smali/baksmali from http://code.google.com/p/smali/ (Thank you JesusFreke, you ROCK!).
Get hold of Gmail.apk either by pulling from your device or extracting it from your current ROM update.zip. Disassemble it with
Code:
java -jar baksmali.jar Gmail.apk
Now you have the Gmail source code in a subfolder called out. Use a descent search tool to search for a relevant section in the resulting files. I searched for "NotificationManager" since that handles Android notifications (using UltraEdit's Find in files).
There is one line found
Code:
invoke-virtual {v4, p0, v5}, Landroid/app/NotificationManager;->notify(ILandroid/app/Notification;)V
Register v5 contains the notification to be set (check SDK docs, it's the last argument of the method call). Scroll up to see what's being done to the Notification prior to showing it.
Code:
iget p0, v5, Landroid/app/Notification;->flags:I
or-int/lit8 p0, p0, 0x1
iput p0, v5, Landroid/app/Notification;->flags:I
This is the manipulation of the flags controlling notification properties. Here I cleared the FLAG_ONLY_ALERT_ONCE (check SDK docs) flag by adding a line:
Code:
iget p0, v5, Landroid/app/Notification;->flags:I
or-int/lit8 p0, p0, 0x1
[B]and-int/lit8 p0, p0, 0xf7[/B]
iput p0, v5, Landroid/app/Notification;->flags:I
When new mail arrived I noted this with logcat:
Code:
New email for [email protected] unreadCount:5 [B]getAttention:true[/B]
...
New email for [email protected] unreadCount:5 [B]getAttention:false[/B]
The first case gave me notifications, the other didn't. Let's make getAttention always true! Search for "getAttention". It's slightly above the previous edited section.
Code:
invoke-virtual {p2, v1, v2}, Landroid/content/Intent;->getBooleanExtra(Ljava/lang/String;Z)Z
move-result v2
.line 287
.local v2, getAttention:Z
A local variable called getAttention is in register v2. Check some lines later to see that it's used to output the logs above. The right place! Now make the variable always true by loading 0x1 in register v2:
Code:
invoke-virtual {p2, v1, v2}, Landroid/content/Intent;->getBooleanExtra(Ljava/lang/String;Z)Z
move-result v2
[B]const/4 v2, 0x1[/B]
.line 287
.local v2, getAttention:Z
Done! Save the file (Utils.smali) and assemble it back into a classes.dex file. Back at the console:
Code:
java -jar smali.jar -o classes.dex out
You end up with a shiny new classes.dex. Replace the original one in Gmail.apk with the new file using your favorite zip manager. Also, remove the folder "META-INF" found in the apk. Now follow some guide on the net for signing the apk. This process adds a new "META-INF" folder.
Now push it to the phone, and reboot (make a nandroid backup first!).
Code:
adb remount
adb push Gmail.apk /system/app/Gmail.apk
adb shell rm /data/dalvik-cache/*Gmail*
adb shell reboot
Now my phone beeps and vibrates for every incoming mail. This process is not for everyone, but works for me. The adventurous can download my modified apk (based on MCR 3.0, which is based on 2.73.405.66)
http://www.mediafire.com/?uuzwhkc5nzy
http://www.filefactory.com/file/a1h98eh/n/Gmail.apk
http://www.filedropper.com/gmail
Obviously root required and nandroid recomended. No warranties.
Anyone have suggestions for other modifications or want to collaborate on some Dalvik hacking? This turned out to be quite fun
Dalvik info can be found here:
http://www.netmite.com/android/mydroid/dalvik/docs/dalvik-bytecode.html
http://www.netmite.com/android/mydroid/dalvik/docs/instruction-formats.html
this is a really cool hack, and dalvik hacking sounds quite interesting, but too high for me...
good job!
Great hack.... however having tried to do this myself ...... I'll leave it for you experts lol
This is an old thread - but super work!
"Gmail Notifier" in Android store now replaces this (I think that is also from you?) but your detective skills are an inspiration!
Thanks

ref: Add Reboot Mod

EDIT: post #3 now includes the steps so a guide to add it to your own files this information is from http://forum.xda-developers.com/showthread.php?t=811532 only modified to work with photon
ok guys i got it working im on skinny rev unlocked with dark fire theme so that is the framework apk i used but its easy to modify for the developers wanting to add this to there theme or rom.. just use my files android.policy.jar and framework.jar
to do this decompile and edit this xml in your framework.apk
Code:
"framework-res.apk\res\values\strings.xml"
add
Reboot
Recovery
next add png icons here
"framework-res.apk\res\drawable-hdpi"
make sure they are named
"ic_lock_reboot.png
"ic_lock_recovery.png
then recompile/build etc.. after you have build apk decompile it again
go here
frameworkres.apk\res\values\public.xml
you will see this with different id #s
and
these are what you need to change in the android.policy.jar
com\android\internal\policy\impl\GlobalActions.sma li"
at line 661
const v3, 0x1080501 (reboot icon)
const v4, 0x10404ed (reboot string)
invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$10;->(Lcom/android/internal/policy/impl/GlobalActions;II)V
aput-object v2, v0, v1
const/4 v1, 0x5
new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$11;
const v3, 0x1080502 (recovery icon)
const v4, 0x10404ee (recovery string)
the first set of icon ids are for reboot
first # is drawable icon second is string #
second set is recovery as in the ( ) 's
so now change these numbers to those in the public.xml as i described above
next recompile your android.policy.jar and its ready to add
thanks!
screenie here http://dl.dropbox.com/u/46879286/20120214113758.jpeg
colors are off sorry
chrystal0925 said:
ok guys i got it working im on skinny rev unlocked with dark fire theme so that is the framework apk i used but its easy to modify for the developers wanting to add this to there theme or rom.. just use my files android.policy.jar and framework.jar
download here http://dl.dropbox.com/u/46879286/photon.power.mod.zip
to do this decompile and edit this xml in your framework.apk
"framework-res.apk\res\values\strings.xml"
add
Reboot
Recovery
next add png icons here
"framework-res.apk\res\drawable-hdpi"
make sure they are named
"ic_lock_reboot.png
"ic_lock_recovery.png
then recompile/build etc.. after you have build apk decompile it again
go here
frameworkres.apk\res\values\public.xml
you will see this with different id #s
and
these are what you need to change in the android.policy.jar
com\android\internal\policy\impl\GlobalActions.sma li"
at line 661
const v3, 0x1080501 (reboot icon)
const v4, 0x10404ed (reboot string)
invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$10;->(Lcom/android/internal/policy/impl/GlobalActions;II)V
aput-object v2, v0, v1
const/4 v1, 0x5
new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$11;
const v3, 0x1080502 (recovery icon)
const v4, 0x10404ee (recovery string)
the first set of icon ids are for reboot
first # is drawable icon second is string #
second set is recovery as in the ( ) 's
so now change these numbers to those in the public.xml as i described above
next recompile your android.policy.jar and its ready to add
thanks!
screenie here http://dl.dropbox.com/u/46879286/20120214113758.jpeg
colors are off sorry
Click to expand...
Click to collapse
This is great I was working on it last night did you have to make changes to build prop?
Sent from my MB855 using xda premium
No I didn't and it works fine
edit: above may not work on other roms with my files so heres a guide need to be deodex odex is not working:
use apk_manager to decompile framework-res
open "values\strings.xml add this to it
Code:
<string name="reboot_recovery">Recovery</string>
<string name="reboot">Reboot</string>
next add png icons here (i attached some to use )
"framework-res.apk\res\drawable-hdpi"
make sure they are named
"ic_lock_reboot.png
"ic_lock_recovery.png
recompile then decompile to get it to auto generate the public id's
now to add the option to the shutdown
so decompile framework.jar and open "com\android\internal\app\ShutdownThread.smali
add to line 40 keep the lines spaced(skipping a line between )
Code:
.field public static mReboot:I
then at line 542 before "invoke-static {}, Landroid/os/Power;->shutdown()V" add this
Code:
sget v1, Lcom/android/internal/app/ShutdownThread;->mReboot:I
const/4 v2, 0x1
if-eq v1, v2, :reboot
const/4 v2, 0x2
if-eq v1, v2, :rebootRecovery
then at line 557 or about line 554 after this
.line 512
return-void
add this
Code:
:reboot
const-string v4, "now"
invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V
return-void
:rebootRecovery
const-string v4, "recovery"
invoke-static {v4}, Landroid/os/Power;->reboot(Ljava/lang/String;)V
return-void
next save and recompile
now decompile androidpolicy.jar
open com\android\internal\policy\impl\GlobalActions.smali
look for .method private createDialog()Landroid/app/AlertDialog;
and at line 624 edit to add two more methods
Code:
.line 232
const/4 v0, 0x4
(change the 0x4 to 0x6)
and at line 657 edit out the ids from your public.xml (]do not add this reference here )
add this
Code:
const/4 v1, 0x4
new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$10;
const v3, 0x1080501 ([COLOR="Red"]change this to drawable reboot id[/COLOR])
const v4, 0x10404ed [COLOR="red"](reboot string id[/COLOR])
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
const/4 v1, 0x5
new-instance v2, Lcom/android/internal/policy/impl/GlobalActions$11;
const v3, 0x1080502( [COLOR="red"]drawable recovery id[/COLOR])
const v4, 0x10404ee ([COLOR="red"]recovery string id[/COLOR])
invoke-direct {v2, p0, v3, v4}, Lcom/android/internal/policy/impl/GlobalActions$11;-><init>(Lcom/android/internal/policy/impl/GlobalActions;II)V
aput-object v2, v0, v1
so you need to go back to your framework.apk
open res/values/public to get the id's to change the above..
save and go to
GlobalActions$5.smali and copy it and name it GlobalActions$10.smali
open GlobalActions$10 and replace all instances ( so any where you see) of GlobalActions$5
with GlobalActions$10 then add this code
Code:
sput v2, Lcom/android/internal/app/ShutdownThread;->mReboot:I
to line 52 before
invoke-static {v0, v1}, Lcom/android/internal/app/ShutdownThread;->shutdown(Landroid/content/Context;Z)V
now copy GlobalActions$10.smali and name it GlobalActions$11.smali
replace all instances of GlobalActions$10 with GlobalActions$11
then save recompile and everything is now added to run this mod!
chrystal0925 said:
No I didn't and it works fine
Sent from my MB855 using XDA App
Click to expand...
Click to collapse
Sounds good,and Thanks
Sent from my MB855 using xda premium
Welcome hope it helps!
Sent from my MB855 using XDA App
If anyone needs send me your framework apk and I can mod it for you to use
Sent from my MB855 using XDA App
how to change android.policy.jar. when i open it, its only contain manifest.mf. there is also android.policy.odex.
zeguym said:
how to change android.policy.jar. when i open it, its only contain manifest.mf. there is also android.policy.odex.
Click to expand...
Click to collapse
you need baksmali to decompile it. which rom are you on? if you cant get it send me the policy and framework.. once you decompile the policy it turns it into a classes.dex then you zip the policy using 7zip or winrar and you replace the new classes.dex with the one in the zip..
chrystal0925 said:
you need baksmali to decompile it. which rom are you on? if you cant get it send me the policy and framework.. once you decompile the policy it turns it into a classes.dex then you zip the policy using 7zip or winrar and you replace the new classes.dex with the one in the zip..
Click to expand...
Click to collapse
I use stock rom.
Can you kindly give step by step how to decompile and compile it again.
I already have baksmali, but when trying to decompile it, it always failed.
is this because stock rom is odex ? not deodex ?
zeguym said:
I use stock rom.
Can you kindly give step by step how to decompile and compile it again.
I already have baksmali, but when trying to decompile it, it always failed.
is this because stock rom is odex ? not deodex ?
Click to expand...
Click to collapse
That could be why I'm using deodex files.. I'm not to sure on directions I use a tool like a script its simple it was 2 commands one to decompile other to recompile.. as far as I know deodex is for theming Modding etc..
I was trying to see if you can use my files but your framework I've had people use my reboot mod on the echo on stock but the framework apk was a deodex version and the rest odex I could deodex it n try if you can post the apk I dont think I have a stock file but if so then you would just decompile my files and edit what I listed after adding to the frameworkapk. You can try this way as well
Sent from my MB855 using XDA App
ive tried flashing on top of an odex version with a completely stock version just deodex it dont work it has to many looping issues so recommend that your rom is deodex..
wrong post. deleted.

[GUIDE] Smali coding guide for beginners

BEGINNER'S GUIDE TO SMALI CODING OF SYSTEMUI​​Presenting to you a beginners guide to smali coding. This thread would focus specifically on SystemUI modding. Please keep questions related to other apks out of this thread.
Disclaimer​
This guide is provided "as is" with no warranties with regard to the accuracy and completeness of the information provided herein. I am not responsible for any bad outcomes you or anyone may have because you followed this guide. When I say beginners, I expect you to have
- Knowledge of some programming language (C,java,etc)
- An inquisitive mind to try things out
- The patience to first google and try to find answers to simple questions
Click to expand...
Click to collapse
Background​
I was also a noob at smali coding till few weeks back. What I have learnt through hours of google searching, reading over the internet, figuring things out and experimenting, I will try to write it up in this guide so that it becomes easier for other beginners to get into systemUI smali coding. This guide won't be just a copy paste guide to get certain mods to work in your systemUI. Rather it should get you started to write your own smali codes and edit systemUI. Lastly, I have limited knowledge on smali currently but I'll try to clarigy doubts as much as possible and I sincerely wish that the great devs around who knows smali coding would join up and help make this thread better and I certainly hope that we all get to learn more smali through this thread.
Click to expand...
Click to collapse
Ok cut the crap. Lets get to the real thing.
If you already know what is smali - goto : post_2
If you already know smaling and baksmaling - goto : post_3
If you just wanna know how to implement the my mod (right finger pull for quick panel toggles) of Serajr's JB like SystemUI - goto : post_4
If you already do smali coding and would like some tips to make life easier - goto : post_6
What is smali?
Android programmers write android apps in java. The compilers like eclipse are then used to build apks from these codes by converting the java source code into dalvik executables (.dex files). The dalvik virtual machine (dalvikvm) in Android can then run these executables. So the perfect way to mod systemUI would be to edit the source code of the systemUI and build the modded systemUI. This is possible for AOSP ROMs like cyanogenmod. So anyone who knows java can download the source code of cyanogenmod, do any crazy modification they want and build CM with the new systemUI. This is all possible because the CM is open source. But unfortunately the OEM Roms like Xperia, Sense, etc are not open source as far as I know. So their source code is not available.
But their dex files are available which would be in a totally unreadable. So to edit it we need to convert this .dex files to a more understandable form. This is where smali comes in. To make it easier to understand I can represent it like this:
.dex <------------------> .smali <--------------------- java source code​
Converting a .dex file to smali (called baksmaling) gives us readable code in smali language. Now if you wonder why can't smali be converted into java source, that's because java is a very developed language and smali is more of an assembly based language. And so while going from java source to smali information is lost and that's why smali can't be used to completely reconstruct java source code
How to baksmali SystemUI.apk?
So let us first decode and obtain the smali code from the SystemUI.apk in your phone.
APK Multi-tool: There are many tools out there that can baksmali apks and later recompile them back after you edit the .smali files. I used APK Multi-tool for this purpose and I would say it works really well with SystemUI.apk as the tool handles system apps separately and has a comparatively more decent UI. I used Windows Version v1.0.11
(Don't forget to give thanks to the people who made these tools if these come in handy for you!)
I - Setting up APK Multi-Tool
Download and extract it
Now from your phone copy framework-res.apk from /system/framework and SystemUI.apk from /system/app and paste it in <folder to which you extracted APK-Multitool>\other. Also copy SemcGenericUxpRes.apk from /system/framework. You will need it later. SemcGenericUxpRes.apk is only for Sony stock based ROMs. For ROMs from other OEMs the corresponding file may have different name and/or location
Run Setup.bat (I think it needs to be run as administrator)
Choose option 2. And from there choose the option to install framework-res.apk and SystemUI.apk. After both are installed return to main menu
Choose option 3 to setup directories
Choose 00 to quit
Now that we have APK Multi-Tool setup for use let us do some baksmaling
II - Decompiling and Baksmaling
Run Script.bat (In case you face problems try running it as administrator. But you probably wouldn't need to unless you extracted all this somewhere in your main windows partition)
Place the apk to be modded in 'place-apk-here-for-modding' folder
Choose option 10 in APK Multi-Tool command window
When it asks for the dependee apk as input drag and drop SemcGenericUxpRes.apk you took from your phone earlier at the command input
If all goes well you would return to the main screen. Don't close the script yet. Back at the APK Multi-tool\projects folder you should find a new folder inside which you would find a folder named smali. This folder has all the required smali files
DON'T CLOSE THE SCRIPT YET
The script needs to be open from baksmaling and needs to stay till you smali it again. If you close it in between you will have to start over again​
Trouble?
Try running the scripts as administrator if you get errors
Make sure you have java installed (Latest version recommended. I've used APK MultiTool with v1.6 and 1.7). Open command prompt (Type cmd in run to open command prompt) and type in java. If it says something similar to unknown command, that means you either don't have properly working java or you haven't added java to the command line path. Here is how to add it. The method explained for Vista worked in my Windows 7 laptop
If you get an error similar to wrong dependee then try this. Goto %userprofile%/apktool/framework. You must already be having 1.apk there if you successfully installed framework-res.apk in step I.4 above. Just copy and paste it again in that same folder as a copy (don't overwrite the first 1.apk) and rename this copy to 2.apk and try baksmaling again
III - Coding
This is where the actual work happens. As far as I have understood each class in the java source code would make a seperate smali file. Suppose there is a PhoneStatusBar class in the actual SystemUI source code you will find a PhoneStatusBar.smali somewhere in the smali folder APK Multi-Tool just made. If there was one sub class in the PhoneStatusBar class then that would result in a PhoneStatusBar$1.smali and so on. So you need to figure out which file to edit and do it using any text editor. More help on that in the next post
IV - Smaling and Recompiling
After you finished editing all the smali files and xmls and pngs next the whole thing needs to be smalied and then recompiled into the final apk.
From the APK Multi-tool script choose option 11.
When it asks about y/n enter y
You would now find a new folder named keep in the APK Multi-Tool directory. From that folder delete everything that you changed. Obviously you won't find any smali files as they have already been smalied into dex. So if you made changes in any smali file then delete the .dex file in this folder. If you have made changes in any xml then delete the resources.arsc and also the xml file that you changed. Delete any png or any other file you have changed
Go back to the script and press any key to continue
If all goes well you would now have the modded apk waiting for you in the 'place-apk-here-for-modding' folder with its unsigned added to its file name.
Trouble?
Try running the scripts as administrator if you get errors
In the main window type in option 23 to check the log. Try to figure out what you messed up from the information in the log.
:angel: Welcome to the world of smali coding! ​
Smali is not an easy programming language to master. You can get info about almost all smali commands here and here. These two links are excellent references for you all along the way! Here I'll go through some of the facts about smali and some of the things that I have found which might help you in writing your own smali code
As far as I know Smali resembles java the most. And the best resource to java in android programming is nothing else than developer.android.com
Click to expand...
Click to collapse
As I said earlier its not possible to reconstruct java source code from smali. But this handy tool APK_OneClick would still get you as close to the source code as possible. That said don't expect to get a compilable code out of it. Set up is pretty straight forward. Running the bat file adds few shell extensions to the right click menu including reconstructing java code. This tool has helped me a lot in understanding the code structure in SystemUI and I highly recommend using it. As a warning don't trust it completely. It did make mistakes a few times mostly when loops are involved
Click to expand...
Click to collapse
That said let us talk more about loops. You might have played with for, while loops, etc before. But well you won't find them in smali. Smali being more of an assembly language handles such loops using labels and goto commands.
Example 1 java code
Code:
if (flagx == 1)
flagx = 2
else
flagx = 3
When flagx variable is referenced as v0
Equivalent Example 1 smali code
Code:
const/4 v1, 0x1
if-ne v0, v1, :cond_0
const/4 v2, 0x2
move v0,v2
goto :goto_0
:cond_0
const/4 v2, 0x3
move v0,v2
:goto_0
Click to expand...
Click to collapse
See how much complex the so simple java code became in smali! At this rate how the hell can one figure out the smali for complex java code? Well the easiest way to do it would be starting from the opposite end.
Get Android SDK and Eclipse downloaded and set up
Write the java code which resembles what you want to do as closely as possible for a simple non-system app
Build the apk in eclipse
Decompile and Baksmali the apk and look at the smali code
Through this, if we get to know how the smali code would look, it should be easier to start off. For an example and more details on this check this post and this post
Click to expand...
Click to collapse
Numbers in smali are represented in hex number system and follow IEEE 754 standards. Yeah you guessed right - That's also complicated.
Suppose you want to introduce a number in your smali code. Say in example 1, you want flagx to be 330 instead of 3. The best way to find how 330 would look in smali would be to do what I said in the previous quote about starting from the opposite end. Write a java code with 330 replacing 3 and look into the baksmalied file to see how it looks.
Online Converter - This is an excellent online converter to make things easier. But even this isn't straight forward. Suppose you find a hexadecimal 0x435c in a smali file. Look for what type of variable is it stored in. And you see that that value is stored in smali in a 16 bit variable. Unfortunately the online converter takes only 32,64 and 128 bits. So type in 435c0000 in the input of the online converter. For 64 bit variables you will have to put more zeros. To find the IEEE 754 hex representation of decimal 330, type in 330 in the online converter and get its hex representation for different bit sizes
Click to expand...
Click to collapse
I will update this post as and when I get more stuff to add.
Pulling Status Bar down from the right side for Quick Panel Toggles in Serajr's SystemUI​
This was the first SystemUI mod that I did. I have refined the code a bit after that with suggestions from Serajr (Thanks bro! :good: ) This is a pretty simple edit and do-able for beginners. I will try to explain each step rather than just asking you to copy paste code.
Define a new boolean mTouchRight in PhoneStatusBar class (\SystemUI.apk\smali\com\android\systemui\statusbar\phone\PhoneStatusBar.smali) along with the other .field lines in the beginning part of this smali file.
Code:
.field private mTouchRight:Z
Now define a new method interceptOneFingerStatusBarRightTap to check if the user is touching the statusbar on its right side and make mTouchRight true if he is and false if not. All this is done only if mExpanded is zero
Code:
.method private interceptOneFingerStatusBarRightTap(Landroid/view/MotionEvent;)V
.locals 2
.parameter "event"
.prologue
iget-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mExpanded:Z
if-nez v1, :cond_1
invoke-virtual {p1}, Landroid/view/MotionEvent;->getRawX()F
move-result v0
const/high16 v1, 0x435c
cmpl-float v0, v0, v1
if-ltz v0, :cond_0
const/4 v1, 0x1
iput-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mTouchRight:Z
goto :goto_0
:cond_0
const/4 v1, 0x0
iput-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mTouchRight:Z
:cond_1
:goto_0
return-void
.end method
You can just add such method definitions at the end of the smali file or in between. Just dont add it within another method!
Now we need to call this method in some function that handles touch events. I will talk about how to figure this out in a later post (Hint: coding logic+Names of variables and methods+using logcat).
In this case the method that we are interested in is interceptTouchEvent.
Original
Code:
if-ge v2, v3, :cond_0
iget-boolean v2, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mExpanded:Z
if-nez v2, :cond_5
:goto_2
invoke-virtual {p0, v5, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->prepareTracking(IZ)V
Change to
Code:
if-ge v2, v3, :cond_0
iget-boolean v2, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mExpanded:Z
if-nez v2, :cond_5
:goto_2
[COLOR="Red"]invoke-direct {p0, p1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->interceptOneFingerStatusBarRightTap(Landroid/view/MotionEvent;)V
[/COLOR]
invoke-virtual {p0, v5, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->prepareTracking(IZ)V
Next we need to make another new method to flip To QuickPanel in case mTouchRight is true.
Code:
.method private oneFingerStatusBarRightTapFlipToQuickPanel()V
.locals 1
.prologue
iget-boolean v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mTouchRight:Z
if-eqz v0, :cond_0
invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->fastFlipToQuickPanel()V
:cond_0
return-void
.end method
Now to find out where this method needs to be called, I did the same as what I did with interceptOneFingerStatusBarRightTap (which would be explained in a later post)
I found out that if the call is added in makeExpandedVisible method, as the statusbar starts to get pulled down, the flip-to-quickpanel happens.
Original makeExpandedVisible
Code:
iput-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mExpandedVisible:Z
invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->visibilityChanged(Z)V
const/16 v0, -0x2710
invoke-virtual {p0, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->updateExpandedViewPos(I)V
Change to:
Code:
iput-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mExpandedVisible:Z
[COLOR="Red"]invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->oneFingerStatusBarRightTapFlipToQuickPanel()V[/COLOR]
invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->visibilityChanged(Z)V
const/16 v0, -0x2710
invoke-virtual {p0, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->updateExpandedViewPos(I)V
You can also put the call in updateExpandedViewPos method in which case the flip would happen only after the notification panel is completely open. Don't put the call for the method in both makeExpandedVisible and updateExpandedViewPos. Only one of them
Original code:
Code:
if-ne p1, v8, :cond_5
move v6, v3
.local v6, pos:I
Change to:
Code:
if-ne p1, v8, :cond_5
move v6, v3
[COLOR="Red"]invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->oneFingerStatusBarRightTapFlipToQuickPanel()V[/COLOR]
.local v6, pos:I
Nice Work
Figuring out smali ​
So in the previous post I said we should call interceptOneFingerStatusBarRightTap in interceptTouchEvent method. But how does one find that out? In which function to call and where?
Well first of all look at the names of the methods and variables and try to figure out what they do. Look at the parameters in function calls. Like interceptOneFingerStatusBarRightTap requires MotionEvent as its parameter in the function call to be able to use getRawX(). So now look at all the methods in PhoneStatusBar.smali which has acces to MotionEvent. In simple cases you might then be able to figure out where to put the method call if you understand the smali code and/or through trial and error. But in more complex cases you can take the help of logcat
Send messages to logcat
So here our aim is to add the call to interceptOneFingerStatusBarRightTap to a method in PhoneStatusBar.smali that has access to MotionEvent and is called when the user touches the screen. Goto all such methods and add smali code to send messages to the logcat. The smali code would be like this
Code:
const-string v1, "Message1"
const-string v2, "Message2"
invoke-static {v1, v2}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
Make sure the variables used doesn't interfere with the code. Let us say we want to see when interceptTouchEvent is called. Add the above code at the beginning of the definition for interceptTouchEvent method. Instead of "Message1" write "interceptTouchEvent" and instead of "Message2" write "beginning". Now if you smali+compile the code to get the unsignedSystemUI.apk and get it working in your phone, connect the phone to your PC/laptop with USB debugging and open up logcat in cmd or eclipse. Now the "interceptTouchEvent" and "beginning" would come up in the logcat the moment the beginning part of interceptTouchEvent is executed. Like this you can find out which method is called when the user touches the status bar and where in the method should the code be added so that the right tap check happens only when you want it to
In some cases you would want to see what value a certain variable holds. Suppose you want to know the value in mTouchRight at the beginning of interceptTouchEvent. The following code would do it
Code:
iget-boolean v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mTouchRight:Z
const-string v2, "mTouchRightatbegofITE"
invoke-static {v1}, Ljava/lang/String;->valueOf(Z)Ljava/lang/String;
move-result-object v3
invoke-static {v2, v3}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
The extra line is to convert the boolen value in mTouchRight to string as Log.d() needs string parameters.
Finally get rid of the log.d() commands you wouldn't require before releasing the final version!
Click to expand...
Click to collapse
Starting from the Opposite End
To aid in this I'll share a simple apk source code that my friend (unfortunately he's not a member of xda) and I made with this post. Just import this project into eclipse and you should be able to build it. Suppose you want to know how much 107.0 is in hex. Just change the value at the place where it checks with getRawX in the java code to 107.0 and build the apk. Decompile/Baksmali the apk to check the corresponding smali hex value of 107.0
This is just a starter. You can probably do many things with this. Do complex codes in java in a dummy apk and see how it looks in smali and then try to implement it in the smali code of the actual apk!
Click to expand...
Click to collapse
Notepad++
If you have already gotten into smali coding you might have seen that just the number of all these smali files are enough to cause headache! How do you find out all the places where interceptTouchEvent is being called? Well if you sit and open all smali files and search for the method your patience would soon abandon you (to put it in a decent way ) Don't worry, here's notepad++ to the rescue. Here's why I recommend notepad++
The above mentioned purpose - Notepad++ has a "find in files" feature. It lets you search for "interceptTouchEvent" in every file that notepad++ can handle (of course including smali). It even lets you know which line in the file in the search result has the search string
Smali syntax highlighting - You can get proper syntax highlighted in notepad++ by importing the .xml file for smali. Google for "notepad++ smali user defined language" and find the .xml. Import it in notepad++ as a new user defined language by going to Language>Define you language.. in notepad++. I can't share the .xml file here due to some reasons.
Easy to use with multiple-tabs for multiple files
More minor reasons are there which I would let you discover for yourself :laugh:
Click to expand...
Click to collapse
Great Work!!!
Wow! Great stuff!! :good:
trust me serajr will damn happy seeing this..
This is awesome..
Sent from my GT-S6102 using Xparent ICS Tapatalk 2
Wow. This will be very handy. Thank you so much!
Sent from my Xperia Z using XDA Premium
..Have you tried Tickle My Android yet?
Ticklefish said:
Wow. This will be very handy. Thank you so much!
Sent from my Xperia Z using XDA Premium
..Have you tried Tickle My Android yet?
Click to expand...
Click to collapse
Buddy check serajr's thread.. need some files from u.
Sent from my GT-S6102 using Xparent ICS Tapatalk 2
Thank you very much for this...
Very very useful...
btw, will it work on gb???
---- by ----
Ganesh,
R.C. @ XDA
sandy7 said:
trust me serajr will damn happy seeing this..
Click to expand...
Click to collapse
Sandy bro... It´s been hard to wipe the smile off my face after see this thread!!
Havocgb, you come true an old dream!!! HATS OFF!!! :good:
serajr said:
Sandy bro... It´s been hard to wipe the smile off my face after see this thread!!
Havocgb, you come true an old dream!!! HATS OFF!!! :good:
Click to expand...
Click to collapse
Thanks bro! Now I can't wipe the smile off my face after seeing the response from all you guys! You guys are the best! :highfive:
Ganesh A said:
Thank you very much for this...
Very very useful...
btw, will it work on gb???
---- by ----
Ganesh,
R.C. @ XDA
Click to expand...
Click to collapse
Hmm I have no idea. I haven't done any decompiling/baksmaling for the SystemUI from GB rom but it might work if the tools I have used support GB. Ask in APK-Multi-Tool thread if there is one or try contacting its maker. Or else try it and see As for serajr's systemUI, I don't think it supports GB. Its for ICS. And so you won't be able to use my mod also. But just decompiling/balsmaling your GB systemUI.apk might work
And dont forget to install smali syntax highlightning for notepad++
http://androidcracking.blogspot.com/2011/02/smali-syntax-highlighting-for-notepad.html
Rempty said:
And dont forget to install smali syntax highlightning for notepad++
http://androidcracking.blogspot.com/2011/02/smali-syntax-highlighting-for-notepad.html
Click to expand...
Click to collapse
I was actually in the process of editing that post to mention the xml. xda is acting too slow now. Guess there is some server issue
I didn't wanna put up a direct link for the xml as the website at the link you have given (and where I got it from) is for a not-so-good purpose
New post added for more help with smali coding. Post is in the 1st page. link
wow really need this, thanks bro
WOW! Great job havocgb! I can definitely learn some tricks from this
I generally avoid writing complex methods completely in smali. (Especially ones that involve loops, if / else and switch statements. It is so easy to screw something up )
I prefer to write complex new methods in Java (in a dummy project in Eclipse), compile the project, decompile it to smali and copy-paste the new method.
Example:
If, let's say you want to write the method:
Code:
.method private interceptOneFingerStatusBarRightTap(Landroid/view/MotionEvent;)V
in the file:
Code:
smali/com/sonymobile/some_app/Class1.smali
In an Eclipse project:
1. Create the package com.sonymobile.some_app in the directory src
2. Create a new Java class (Class1) in the package you created in step 1.
3. Add your new method in the newly created Class1.java file
Code:
package com.sonymobile.some_app;
public class Class1
{
private void interceptOneFingerStatusBarRightTap(android.view.MotionEvent event)
{
//...
//add your logic here
//...
// Example
int action = event.getAction();
action = action+1;
}
}
4. Compile the project
5. Decompile the resulting apk file to smali
6. This is what the smali code will look like:
Code:
.class public Lcom/sonymobile/some_app/Class1;
.super Ljava/lang/Object;
.source "Class1.java"
# direct methods
.method public constructor <init>()V
.locals 0
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
#p0=(Reference,Lcom/sonymobile/some_app/Class1;);
return-void
.end method
.method private interceptOneFingerStatusBarRightTap(Landroid/view/MotionEvent;)V
.locals 1
.parameter "event"
.line 12
invoke-virtual {p1}, Landroid/view/MotionEvent;->getAction()I
move-result v0
.line 13
.local v0, action:I
#v0=(Integer);
add-int/lit8 v0, v0, 0x1
.line 14
return-void
.end method
7. Copy the new method from the smali file you've just produced to the original smali file you are trying to modify.
If you think this is off topic or irrelevant, please let me know and I'll delete it
Congrats again for the great thread!

[REQUEST] Disable increasing ringtone

I want to disable increasing ringtone. Is there any MOD available for "S Advance" that can be used?
I dont wanna use any app for this.
There are mods for s3 and s2 but i'm not sure whether they will run on s advance.
Plz help
XXLQB+Cocore 5.0+NOS Turbo
I'm going to add this feature to my ROM... anyways this is more of a Do-It-Yourself thingy.. so here are the steps, follow them and tell me whether they work or not...
1. Decompile SecPhone.apk using APKTOOL
2. Go to Smali\com\android\phone\Ringer$1.smali (note: open it with NotePad++)
3. Search for setStreamVolume. There should be two results. Delete the first one (the whole line in RED, like this):
Code:
.line 394
iget-object v1, p0, Lcom/android/phone/Ringer$1;->this$0:Lcom/android/phone/Ringer;
iget-object v1, v1, Lcom/android/phone/Ringer;->mAudioManager:Landroid/media/AudioManager;
[COLOR="Red"]invoke-virtual {v1, v3, v5, v4}, Landroid/media/AudioManager;->setStreamVolume(III)V[/COLOR]
4. Now search for nop (usually at the end of the file), copy it and hit enter twice and paste again (see code bellow, the blue one). "leave one line space in between each line":
Code:
goto/16 :goto_b
.line 717
nop
[COLOR="Blue"] nop[/COLOR]
:pswitch_data_1ca
.packed-switch 0x1
5. Save the changes
6. Recompile your SecPhone.apk.
7. With 7-Zip or WinRAR, open the the original (stock) SecPhone.apk. Then drag and drop the classes.dex and resources.arsc you just compiled into the (stock) SecPhone.apk.
8. Push the SecPhone.apk to your phone.
(Note that some Line numbers or numbers in the codes may differ)

[Tip] Activating Ink effect with fingers (4.3)

A. android.policy.jar file:
1. Copy the contents of “to android.policy.jar” folder.
2. Decompile android.policy.jar by backsmali/smali program.
3. Go to classout\com\android\internal\policy\impl\sec\ folder open CircleUnlockRippleRenderer.smali and search for "const/16 v1, 0x4002" and change this line.
search
Code:
const/16 v1, 0x4002
if-ne v0, v1, :cond_138
change
Code:
const/16 v1, 0x4002
if-ne v1, v1, :cond_138
Now recompile android.policy.jar and push them to your device.
Credits. majdinj
Sorry for my English
Great! Havent tried it yet, but it should work.. Any other way though? Like to flash via recovery? I have 4.3 leaked, stock, rooted, twrp, odexed
Sent from my GT-N7100 using XDA Premium 4 mobile app
Could you share the files.. TQ
here it is.
please help me.
sorry for bothering you with my newbies question.
i have problem,, i hope you can help me regarding to this thread.
first i used [4.3][MI6]DN3(Ditto Note 3) ROM from Electron Team(E-team)
in that ROM the ripple effect is basically mod like in this thread, what i want to do is to reverse it to the original note 2 which is the ink only out when using s-pen.
i already follow steps like you said on post#1
1. copy my android.policy.jar to my sd and move to my computer
2. decompile with backsmali/smali program
3. unlike you i go to classout\com\android\internal\policy\impl\keyguard\sec folder open CircleUnlockRippleRenderer.smali and search for "const/16 v1, 0x4002" and change
i change the value
Code:
const/16 v1, 0x4002
if-ne v1, v1, :cond_138
into the original
Code:
const/16 v1, 0x4002
if-ne v0, v1, :cond_138
4. Recompile android.policy.jar and copy to my sdcard.
5. move the android.policy.jar with rootbrowser to its original location and replace the original android.policy.jar
but i ended with many error when i push the android.policy.jar that i mod with steps like you said in post#1.
my error is non stop FC and non stop TW, NFC, and etc stopped working.
can you tell me where do i made mistake? please give me solution about this problem, thanks before.
Safe way to replace any files in framework folder is using cwm.zip
Sent from my GT-N7100 using XDA Premium 4 mobile app
ink effect for kitkat 4.4.2 with fingers.
please go here
Thanks.
Hit THANKS button, If I helped You.

Categories

Resources