yashsingh1/xdaforums huggingface dataset:
[XPERIA X10 Themes and Apps] _calum_:
OK, been fishing about a bit. Found this on line 3391 of StatusBarPolicy.smali, looks like it's finally time to learn how to write this stuff ;) (sorta looks similar to msil so shouldn't be too bad.... ).

.method private final updateSignalStrength()V

....
....
....
// LINE NUMBER 3483
.line 896
:goto_44
iget-object v3, p0, Lcom/android/server/status/StatusBarPolicy;->mPhone:Landroid/telephony/TelephonyManager;

invoke-virtual {v3}, Landroid/telephony/TelephonyManager;->isNetworkRoaming()Z

move-result v3

if-eqz v3, :cond_71

.line 897
sget-object v2, Lcom/android/server/status/StatusBarPolicy;->sSignalImages_r:[I

.line 916
.end local v0 #asu:I
.local v2, iconList:[I
:goto_4e
iget-object v3, p0, Lcom/android/server/status/StatusBarPolicy;->mPhoneData:Lcom/android/server/status/IconData;

aget v4, v2, v1

iput v4, v3, Lcom/android/server/status/IconData;->iconId:I

.line 917
iget-object v3, p0, Lcom/android/server/status/StatusBarPolicy;->mService:Lcom/android/server/status/StatusBarService;

iget-object v4, p0, Lcom/android/server/status/StatusBarPolicy;->mPhoneIcon:Landroid/os/IBinder;

iget-object v5, p0, Lcom/android/server/status/StatusBarPolicy;->mPhoneData:Lcom/android/server/status/IconData;

invoke-virtual {v3, v4, v5, v6}, Lcom/android/server/status/StatusBarService;->updateIcon(Landroid/os/IBinder;Lcom/android/server/status/IconData;Lcom/android/server/status/NotificationData;)V

goto :goto_28

.line 890
.end local v2 #iconList:[I
.restart local v0 #asu:I
:cond_5e
const/16 v3, 0x10

if-lt v0, v3, :cond_64

const/4 v1, 0x4

goto :goto_44

.line 891
:cond_64
const/16 v3, 0x8

if-lt v0, v3, :cond_6a

const/4 v1, 0x3

goto :goto_44

.line 892
:cond_6a
const/4 v3, 0x4

if-lt v0, v3, :cond_6f

const/4 v1, 0x2

goto :goto_44

.line 893
:cond_6f
const/4 v1, 0x1

goto :goto_44

....
....
....

.end method

And here's the updateIcon method from StatusBarServices.smali:

.method public updateIcon(Landroid/os/IBinder;Lcom/android/server/status/IconData;Lcom/android/server/status/NotificationData;)V
.registers 10
.parameter "key"
.parameter "data"
.parameter "n"

.prologue
.line 498
const/4 v1, 0x2

const/4 v5, -0x1

move-object v0, p0

move-object v2, p1

move-object v3, p2

move-object v4, p3

invoke-direct/range {v0 .. v5}, Lcom/android/server/status/StatusBarService;->addPendingOp(ILandroid/os/IBinder;Lcom/android/server/status/IconData;Lcom/android/server/status/NotificationData;I)V

.line 499
return-void
.end method

I'll have a look at addPendingOp() later...
[XPERIA X10 Themes and Apps] _calum_:
OK, I need a bit of syntax help. If anyone can point me to a smali reference that would be great, I've looked at the examples here but I really need just a straight out syntax reference.

I've been looking at this code:

.line 890
.end local v2 #iconList:[I -> delete local variable v2
.restart local v0 #asu:I -> reset v0
:cond_5e -> goto marker ?
const/16 v3, 0x10 -> declare variable v3 and set to 16

if-lt v0, v3, :cond_64 -> if (v0 < v3)
-> {
const/4 v1, 0x4 -> v1 = 4;

goto :goto_44 -> goto goto_44;
-> } // does the 'if' end here??
.line 891 -> is this just a marker??
:cond_64 -> next block, repeats with v3 = 8
const/16 v3, 0x8

if-lt v0, v3, :cond_6a

Can anyone answer the questions in the code, or correct me please.
[XPERIA X10 Themes and Apps] MrRusch:
Sorry, I can't help you much with the syntax yet, trying to understand this myself.

However something struck me today.. Modifying this to work like the battery mod, i.e. switching image every state change, is not a good idea here. This will not be efficient as dBm value is constantly fluctuating, making this a crazy resource hog. For the battery this was ok, as it only loads a new image every so often, but this won't be good for the reception. So I was thinking, perhaps replacing the icon completely with a textfield would be better, as updating a text value would be way more efficient than loading images every state change. What do you think?

I'm going through the smali-examples myself, trying to learn how to write this. Because the cross-compilation method I described earlier is probably not gonna work as I hoped.

Anyway, I believe you got the markers switched up..?

:cond_5e - placement marker

if-lt v0, v3, :cond_64 - goto marker
[XPERIA X10 Themes and Apps] _calum_:
OK, thanks. So

if-lt v0, v3, :cond_64

is like

if (v0 < v3) { goto cond_64; }

I was wondering why I couldn't find a clear end to the if block.

The text block idea is good, especially with a signal that goes in and out like mine. To be honest, I probably wouldn't have used this mod myself, it was just a good excuse to mess with things.

Also, we shouldn't have any compilation problems if we modify the smali files from the sony services.jar.
[XPERIA X10 Themes and Apps] MrRusch:
As for your question about IF-statements, perhaps this can be of some help.

I simplified the original Java comparison:

public class StatusBarPolicy {

StatusBarPolicy() {

int asu = 0, iconLevel = 0;

if (asu <= 2 || asu == 99) iconLevel = 0;
else if (asu >= 12) iconLevel = 4;
else if (asu >= 8) iconLevel = 3;
else if (asu >= 5) iconLevel = 2;
else iconLevel = 1;

}

}

And compiled it to smali:

.class public LStatusBarPolicy;
.super Ljava/lang/Object;
.source "StatusBarPolicy.java"

# direct methods
.method constructor <init>()V
.registers 3

.prologue
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V

.line 5
const/4 v0, 0x0

.line 7
const/4 v1, 0x2

if-le v0, v1, :cond_b

const/16 v1, 0x63

if-ne v0, v1, :cond_c

.line 13
:cond_b
:goto_b
return-void

.line 8
:cond_c
const/16 v1, 0xc

if-ge v0, v1, :cond_b

.line 9
const/16 v1, 0x8

if-ge v0, v1, :cond_b

.line 10
const/4 v1, 0x5

if-lt v0, v1, :cond_b

goto :goto_b
.end method

Oddly, no matter what the asu value is set to at init, iconLevel value is never changed... But this is how I understand it:

.class public LStatusBarPolicy;
.super Ljava/lang/Object;
.source "StatusBarPolicy.java"

# direct methods
.method constructor <init>()V
.registers 3

.prologue
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V

.line 5
const/4 v0, 0x0	/evaluates asu, put dec0 in v0

.line 7
const/4 v1, 0x2	/put dec2 in v1

if-le v0, v1, :cond_b	/if v0(asu) <= v1(2) goto cond_b

const/16 v1, 0x63	/put dec99 in v1

if-ne v0, v1, :cond_c	/if v0(asu) != v1(99) goto cond_c

.line 13
:cond_b	/cond_b start
:goto_b	/goto_b start
return-void	/donb_b & goto_b end by return void

.line 8
:cond_c	/cond_c start
const/16 v1, 0xc	/put dec12 in v1

if-ge v0, v1, :cond_b	/if v0(asu) >= v1(12) goto cond_b

.line 9
const/16 v1, 0x8	/put dec8 in v1

if-ge v0, v1, :cond_b	/if v0(asu) >= v1(8) goto cond_b

.line 10
const/4 v1, 0x5	/put dec4 in v1

if-lt v0, v1, :cond_b	/if v0(asu) < v1(4) goto cond_b

goto :goto_b
.end method

From this we can see that it seems to be the .line statements that separate blocks. I.e. .line 7 holds two conditions, asu <= 2 and asu != 99. I'm not sure how the OR is determined here. Will recompile and see.

EDIT: Duh, the jump instruction provides this logic here.
[XPERIA X10 Themes and Apps] _calum_:
Thanks :)

I think I'm getting the hang of it now. I just made some notes on another bit of code here (see section 5): http://xdaforums.com/showthread.php?p=9126650#post9126650

Edit: just saw your edit now. I noted in the post above that I'm pretty sure the .line entries refer to source code lines. All of the blocks I've looked at would be easily written in a single line of code. Another thing is that you don't really need the OR if you split it up: if the first one is true then you will jump to somewhere else and the second condition won't be evaluated.

I'm off for a bit, I'll have a better look at your last edit later.
[XPERIA X10 Themes and Apps] MrRusch:
@ .line entries, yeah seems to be the case.

@ OR, when you put it that way ;) yeah.. I suppose it becomes more interesting with the AND operator, i.e. asu > 1 && asu < 10.

The time is quickly approaching beer o'clock again, so I'm gonna put this away for tonight as well. But I thought I'd upload a little tool I put together, that may be useful. It's a java2smali converter, sadly the other way around doesn't work too well. Anyway, only prerequisite is that you have JDK installed and properly linked to environmental path variable.

Extract the archive to some folder, shove your *.java files in there, and run the batch file.. When entering the class name e.g. StatusBarPolicy, leave out the file extension.
[XPERIA X10 Themes and Apps] saltorio:
Hey guys. Wish I could be of more help, but I'm having alot of trouble wrapping my head around the code. My coding experience is pretty limited (JavaScript for Adobe Acrobat is the only thing I've worked in in the past 10 years).

As for the icon update being battery hog: I can say I've been using Signal Status for the past few days (it shows the signal dBm in the notification bar) and according to SystemPanel it's used all of 2 sec of CPU time in the past 12 hours. I think it may display as text (vs. icon), but I'll need to look into it's code for that (which I'll do tonight).
[XPERIA X10 Themes and Apps] _calum_:
If I get some time later on, I'll try and add some text next to the signal. I'll just duplicate the bars for the moment i.e. the text will be 1,2,3,4 or 5.

Shouldn't be too hard (I think) it should just be a matter of adding some xml and then duplicating the smali code to change the text as well... OK, so maybe it won't be that easy :p we'll see... ;)

Ans thanks for the converter, now I just need to learn java :D although it's not that far from c++

Can I upload the tool to the themes reference thread?
[XPERIA X10 Themes and Apps] MrRusch:
Sure, no problem.

On another issue, I think we might be screwed.. :( Try extracting and decompiling services.jar's classes.dex, and then recompiling it (baksmali/smali). I get file size difference and total corruption when viewing through HexCompare. I.e. without having made any changes, things get messed up.
[XPERIA X10 Themes and Apps] _calum_:
I get the same file size (EDIT: 8 bytes smaller) - but the contents are different...

I'm just gonna bite the bullet now and push that puppy to my phone :eek:

I'll get back to you....

EDIT: Phone's still alive and it took a lot longer to reboot so I'm pretty sure the push was successfull (the cache was probably being rebuilt).

I'm going to hard code the notification bar text colour now just to make sure the update was OK. I'll post again in a few minutes
[XPERIA X10 Themes and Apps] MrRusch:
Hmm.. I'm loosing 8 bytes :( What version of smali are you using?

I'm on 1.2.5, and commands used are..

Decompile: java -jar baksmali.jar -o out/ classes.dex

Recompile: java -Xmx512 -jar smali.jar out/ -o new-classes.dex
[XPERIA X10 Themes and Apps] untermensch:
I got your pm and think I can shed a little light here, first this is the only smali

reference I could find but it helps:

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

second it is better to think of smali as assembly code than C/Java

things like "||", "&&", "else" are really just macros that get expanded

buy the compiler to what amounts to a bunch of "if" "goto/jump"

statements that are PITA to code by hand.

the data in the array are resource id's which can be found in public.xml in

framework-res.apk

this is the array from my phone:

.array-data 0x4
0xdet 0x2t 0x8t 0x1t
0xe0t 0x2t 0x8t 0x1t
0xe2t 0x2t 0x8t 0x1t
0xe4t 0x2t 0x8t 0x1t
0xe6t 0x2t 0x8t 0x1t
.end array-data

which resolves to these resources in framework-res.apk

<public type="drawable" name="stat_sys_signal_0" id="0x010802de" />
<public type="drawable" name="stat_sys_signal_1" id="0x010802e0" />
<public type="drawable" name="stat_sys_signal_2" id="0x010802e2" />
<public type="drawable" name="stat_sys_signal_3" id="0x010802e4" />
<public type="drawable" name="stat_sys_signal_4" id="0x010802e6" />

the resource id's are little-endian which means read backwards so if you want

to add to the array first add your images to framework-res so you have the

resource id's handy then add the resources to the array

like this:

<public type="drawable" name="example" id="0x11223344" />

0x44t 0x33t 0x22t 0x11t

I hope this helps.
[XPERIA X10 Themes and Apps] _calum_:
sweet, thanks for that untermensch, I hadn't quite made the connection from the array data to the IDs, but it makes perfect sense when you look at it side by side like that.

That link is perfect. I was sort of looking at it like MSIL, it is in fact very similar the deeper I dig. All I really needed was to see what the commands where doing (it took me a while to realise that move x y moves y to x and not the other way around :))

Anyway, thanks again.
[XPERIA X10 Themes and Apps] JesusFreke:
The definitive bytecode reference is the dalvik-bytecode.html document in the dalvik documentation (dalvik/docs/dalvik-bytecode.html - link). Paller's document is the result of reverse engineering the dex files, before android was open sourced.

Also, see my response to MrRusch here
[XPERIA X10 Themes and Apps] untermensch:
I found this code in Settings.apk this shows the signal strength on the

settings-->About Phone-->Status page this will get the signal strength

as ASU and dbm as an integer then you will just have to correlate them with

your array with a loop or some math.

iget-object v4, p0, Lcom/android/settings/deviceinfo/Status;->mPhoneStateReceiver:Lcom/android/internal/telephony/PhoneStateIntentReceiver;

invoke-virtual {v4}, Lcom/android/internal/telephony/PhoneStateIntentReceiver;->getSignalStrengthDbm()I

move-result v2

.line 386
.local v2, signalDbm:I
if-ne v6, v2, :cond_2b

const/4 v2, 0x0

.line 388
:cond_2b
iget-object v4, p0, Lcom/android/settings/deviceinfo/Status;->mPhoneStateReceiver:Lcom/android/internal/telephony/PhoneStateIntentReceiver;

invoke-virtual {v4}, Lcom/android/internal/telephony/PhoneStateIntentReceiver;->getSignalStrength()I

move-result v1
[XPERIA X10 Themes and Apps] _calum_:
Thanks, that should save me a bit of thinking :)

@MrRusch: after recovering a serious brick (stupid mistake, flashed the framework generated from apktool, realised what I had done in the middle of it, panicked, pulled plug, bricked phone :( - 5 or 6 flashes later, still a paperweight... got it sorted eventually by reflashing 1.6)

Anyway, where was I, oh yeah... all I wanted to do was check that the services.jar was really being updated. I did that just now. I'll add a detailed report on the reference thread tomorrow but here's the short version:

I changed semc_text_color_primary in colors.xml to green, just to see that the time was shown in green before I updated. I also added a new color to the xml and a new style to styles.xml. I added the style with the next free style ID (style IDs must start with 0x0103...) to public.xml. I compiled all this and pushed it to my phone -> green time at the top, and a style in the xml files ready for use (with blue text).

I then changed the code in StatusBarIcon.smali to use the new style ID, compiled and pushed services.jar to my phone.

Now the time is blue :)
[XPERIA X10 Themes and Apps] MrRusch:
Yeah, that's the only one i've found as well..

Awesome, I would'nt have caught this thanks!
[XPERIA X10 Themes and Apps] MrRusch:
Ok, I'm very close to getting this perfect.

FYI: Correction of previous statement.. dBm values go from -113 to -51. And as ASU values arrive in whole ints, we will only get odd values for dBm, meaning there will only be 32 dBm values, just as ASU.

Will upload for testing real soon.
[XPERIA X10 Themes and Apps] MrRusch:
Ok, here we go.. This should do it!

Installation:

1. Unrar archive.

2. Copy extracted files to /sdcard, and

3. In terminal emulator:

a) make sure you have super user permissions (su)

b) remount /system partition as read-write (mount -o remount,rw -t yaffs2 /dev/block/mtdblock2 /system)

c) replace services.jar (dd if=/sdcard/services.jar of=/system/framework/services.jar)

d) replace framework-res.apk (dd if=/sdcard/framework-res.apk of=/system/framework/framework-res.apk)

Reboot will take some time, don't get freaked out. And backup your stuff first, just to make sure.

Note: As this replaces framework-res.apk, previous themes and mods will be lost. When we know it is stable I will add battery + reboot mods to the framework.

Thanks untermensch for the information on the id-references in smali's array structure. This will definitly be useful in the future as well. And thanks JesusFreke for quick response on smali problem, turns out it was just me not knowing what I was doing ;)
[XPERIA X10 Themes and Apps] _calum_:
Nice work man. Images or text?

And can you tell me what code you changed?
[XPERIA X10 Themes and Apps] _calum_:
Nice job. I'll have a look at this in detail later this week and try and get it displayed as text (even if it's not really necessary, I'd like to be able to show custom items in the notification bar. I'll post back here if I get it sorted.

Just out of interest: is there anyway we can see if loading the images has any impact on performance at all?
[XPERIA X10 Themes and Apps] saltorio:
MrRusch, you are awesome!!!

I look forward to giving it a try when I can manage to get it fit into Chewitt's Dark10 theme.

Wonderful job, and thank you very much!
[XPERIA X10 Themes and Apps] MrRusch:
I don't believe it has any effect. The ASU is resolved constantly anyway (at some set interval or state change), and the picture is choosen every time right after doing this, whether it has changed or not. The only difference is that that it used to load the same picture, e.g. 4 bars, over and over again (even tho dBm may flucuate between -89 and -51), while it now loads a few different images within the 4-bar ASU range (12-31!). It's just shocking how innacurate the 4 bar system is.

No problem mate, I'm glad I can contribute somehow. If you can do without the theme for a bit, it would be really nice with some testing help. So that we don't base a bunch of new frameworks on a faulty base. Oh, and please change the thread name to something indicating it has been done, e.g. [MOD] dBm Signal Strength or something..
[XPERIA X10 Themes and Apps] _calum_:
OK, if the image was being reloaded anyway then we have a one-off hit the first time each image is loaded and then it will be cached. Shouldn't be any problem then.

@saltorio:

I will add this mod to the version of chewitts framework that I am running now (alpha 3.0.0 w/ battery mod), just so I know exactly what's going on. I'll post the framework and services.jar here for testing purposes.

Now two questions:

1. What color do you want the clock to be? :D

2. What else would you like to see in the status bar? I'm looking at putting custom elements in. Not sure how complicated the code will get, the xml should be fine though. Problem is, now that MrRusch has sorted this, I don't know what to put in there :p
[XPERIA X10 Themes and Apps] saltorio:
Awesome! That's be great.

1. Ideally, I'd love to be able to set it somehow when I install the framework. For now, I kindof like it as white in Dark10, but pure Magenta (255,0,255) would be good.

2. That I have no idea on. I'll have to think about it.

On a side note: MrRusch, you may want to start a new thread of your own regarding this mod, and maybe even link to it (or post it directly) in the main Android development forum rather than the X10 forums. My research into a hack like this didn't turn up anything beyond what they did in CM6, so it's likely to appeal to more than just we X10 users.
[XPERIA X10 Themes and Apps] _calum_:
OK, I've reproduced this with my framework. Two things:

1. The signal strength icon disappears at certain signal strengths, looking into that. At -105 I get the normal 4 bars symbol... - I'm an idiot :o

2. My battery icons dissapeared :eek: I'm looking into this as we may need to do a very similar mod for the batteries to get both working... I've noticed that the old battery icons have id's in public.xml and there is a setBatteryLevel method in StatusBarPolicy. This is not the first time the icons have disappeared. It also happened when I was messing with the smali code to change the color of the clock text...
[XPERIA X10 Themes and Apps] MrRusch:
Ok, I just threw together a similar modification to show WiFi signal strength (RSSI) in 5% increments (i.e. 0%, 5% ... 95%, 100%). Couldn't be fudged making 100 new images, so 5's will have to do for now..

This one includes both dBm and RSSI (WiFi) signal strengths.. Use same procedure as described for last upload.
[XPERIA X10 Themes and Apps] _calum_:
you're on a roll :D

Just for the record, could you edit you're post describing the code you've changed so that it notes that the if block is in the updateSignalStrength method. I didn't have any trouble finding it, but I've linked the post from the references thread and I think if you just add this then it's nice and complete.

I really don't think it needs anymore detail - if someone can't reproduce the mod from that description then they should just walk away :p
[XPERIA X10 Themes and Apps] MrRusch:
Sure thing, done.

Hehe well hopefully it can be of help to someone.

EDIT: Could you perhaps help me out with some testing of the WiFi indicator? Seems there is some bug in it, my phone reboots randomly when on WiFi. Not sure what it could be, seemed simple enough.. but yeah, somethings not 100%.

Hmm maybe you're right.. But I mean Google will find these pages to (http://lmgtfy.com/?q=dbm+signal+strength+mod&l=1) ;)
[XPERIA X10 Themes and Apps] _calum_:
Yeah, I can test that tomorrow maybe, at the moment I'm testing another wifi bug. I've got to have another look at whats happening to the battery indicator to...
[XPERIA X10 Themes and Apps] MrRusch:
Cool. Did some reading and it seems this is a problem with sending a too large number of values to calculate the RSSI based on (I'm sending 20 now instead of 4). It results in a division by zero. Will see if I can make a workaround this afternoon, i.e. if x is 0, x=0.000001 or something..
[XPERIA X10 Themes and Apps] _calum_:
Where's the DivideByZero happening?

BTW, I checked here again today, but the 2.1 source still isn't available.
[XPERIA X10 Themes and Apps] _calum_:
I have attached chewitts latest framework (beta 0.0.1) I added the battery mod to it last night and the signal strength this morning and it seems to be working fine.

I'm not sure what was up with my disappearing battery display, but I deleted all of my working folder and did a fresh decompilation of both the framework and services.jar. Now everything seems to be fine. I think I messed up my working folder by putting other themes in there instead of just the stock framework. From now on I'll only compile the stock framework and pull the necessary files out of it once it's compiled.

Anyway, goes without saying - Backup :) and use at your own risk ;)

And the installation is the same as for MrRusch's original.

EDIT: I've been thinking about modding the Icons to show ASU instead of dBm. I think it would be a bit easier on the brain for most people.... anyway, now that the images are in there and being set properly, this can be done like any other mod.

Right, now to get the CPU and RAM usage up there ;)

EDIT: Linked removed as there are some strange effects with the battery icon at the moment. I'll fix them later tonight and post a new version.