yashsingh1/xdaforums huggingface dataset:
[Galaxy S II Android Development] Goldie:
Firstly I am by no means an expert and am just trying to share what i have learnt about smali as its hard to find much info about general smali. Contributions to the thread are always welcome :)

For the last year or so I have been developing AllianceROM on the i9100. During this time I have learnt lots about smali through a combination of trial and error and guides I have found here on XDA. The guides are great but one thing that stands out is that they all follow the same pattern of “Find a certain line in a certain file and copy/paste" to replace methods or chunks of code for the desired outcome. Whilst this is a great means to an end it is only a means to that particular end. Most people wont actually understand what they are doing or how it works and will blindly do as instructed.

So I thought that I would try to write some general guides. The aim is to give you the means to dream up your own mods and know how to go about implementing them from scratch by yourself. I am by no means an expert but hopefully there should be enough here to set you on your way. These are the methods I used to create many of the mods in alliance, lots of which didn’t exist on Touchwiz devices before.

You will need certain tools to do this but I am not going into how to decompile etc. Before attempting this you should have a good knowledge of decompiling apks and modding in general and have the following tools available:

ADB

Notepad ++

A good image editor like Photoshop or GIMP

The guides are in 3 sections:

Coloring stuff with color pickers

Toggling stuff to show or hide

List choices for things like toggles in view etc

For the purposes of these guides I am using an apk from our legendary alliance developer ficeto. He has made this app to enable us to easily add color pickers, checkboxes and lists by adding a single line to an xml. Huge huge thanks to him as he made this a lot easier!! You can use this to test your mods but please dont rename everything from ficeto to "ubermodders" or something and try to pass it off as your own. If you do it will be reported ;) It is to be used as is, not changed or renamed (this causes problems for people installing alliamceMOD) and dont forget to credit ficeto!!

Please feel free to ask general smali questions here too!

So lets get started!!
[Galaxy S II Android Development] Goldie:
USEFUL POSTS:

NOTEPAD++ SMALI HIGHLIGHTING - Thanks to [MENTION=369057]majdinj[/MENTION]

LIST OF DALVIK OPCODES - Thanks to [MENTION=369057]majdinj[/MENTION]
[Galaxy S II Android Development] Goldie:
one more actually
[Galaxy S II Android Development] _FreaK_:
Goldie you are the best. ;) Thanks. :victory:
[Galaxy S II Android Development] remuntada78:
finally, you're the grand master

thank you
[Galaxy S II Android Development] Goldie:
Hope my ramblings make sense! :p
[Galaxy S II Android Development] vhce:
Very good. Thanks for all your hard work
[Galaxy S II Android Development] davidwilson83:
What a fantastic guide. Top work Goldieking :)

Sent from my PurifieD S4
[Galaxy S II Android Development] engloa:
Finally !!

Was thinking you had abandoned the project:p
[Galaxy S II Android Development] Goldie:
Now the challenge is on for who can make the first one thats not dropdown date :D
[Galaxy S II Android Development] avirk:
Sorry buddy for no feedback on your fantastic guide, I got busy with ither stuffs.

But I must say hey you reveal the secreat of samsuck and your hard work with us.
[Galaxy S II Android Development] Goldie:
Ummm.....I always use custom settings for a list which means I only gotta add a single line but in cond_d you have the same lines twice for contextualpage_settings where you move boolean result into v0 then use it as an object in the next lines. Are you sure you didnt change something there? Those four lines were already repeated?

Without looking at the file its difficult to tell but something looks wrong here...

:cond_d
const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, :cond_12

const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

[COLOR="Red"] if-eqz v0, :cond_13[/COLOR]
[Galaxy S II Android Development] remuntada78:
I'm sorry you're right i've add this:

:cond_d
const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, :cond_12

[COLOR="Red"] const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, :cond_13[/COLOR]

so i've to delete this lines?

const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

edit:I tried to change the lines above whit those:

:cond_d
const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, :cond_12

[COLOR="Red"] invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v1

if-eqz v1, :cond_13[/COLOR]

but it doesn't work again ,you try to look in my file

View attachment 2340166
[Galaxy S II Android Development] maanz "L":
This is a great guide.

Thanks very much, Goldie...

;)
[Galaxy S II Android Development] Goldie:
Hard on phone but try this...

https://db.tt/ocnydt7E
[Galaxy S II Android Development] remuntada78:
i changed GlobalAction.smali i followed this guide http://xdaforums.com/showpost.php?p=47555418&postcount=5but why color changed only in airplanemode and in data

edit:

I may have found the solution,in GlobalAction.smali I've this

iget-object v3, v0, Lcom/android/internal/policy/impl/GlobalActions;->mDataModeToggle:Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;

aput-object v3, v1, v2

const/4 v2, 0x3

move-object/from16 v0, p0

iget-object v3, v0, Lcom/android/internal/policy/impl/GlobalActions;->mAirplaneModeOn:Lcom/android/internal/policy/impl/[COLOR="Red"]GlobalActions$ToggleAction;[/COLOR]

aput-object v3, v1, v2

const/4 v2, 0x4

move-object/from16 v0, p0

iget-object v3, v0, Lcom/android/internal/policy/impl/GlobalActions;->mRestart:Lcom/android/internal/policy/impl/[COLOR="Red"]GlobalActions$SinglePressAction;[/COLOR]

aput-object v3, v1, v2

const/4 v2, 0x5

move-object/from16 v0, p0

iget-object v3, v0, Lcom/android/internal/policy/impl/GlobalActions;->mRecovery:Lcom/android/internal/policy/impl/[COLOR="Red"]GlobalActions$SinglePressAction;[/COLOR]

aput-object v3, v1, v2

const/4 v2, 0x6

move-object/from16 v0, p0

iget-object v3, v0, Lcom/android/internal/policy/impl/GlobalActions;->mDownload:Lcom/android/internal/policy/impl/[COLOR="Red"]GlobalActions$SinglePressAction;[/COLOR]

where data and airplane are refered to GlobalActions$ToggleAction while poweroff, restart ect are refered to GlobalActions$SinglePressAction then in GlobalActions$SinglePressAction i need to add code after this

iget v3, p0, Lcom/android/internal/policy/impl/GlobalActions$SinglePressAction;->mMessageResId:I

invoke-virtual {v1, v3}, Landroid/widget/TextView;->setText(I)V

it's right?

edit:

yessss:laugh::laugh:was right thanks again
[Galaxy S II Android Development] Goldie:
Thats the ticket! :D

Good job man. Exactly as I wished this guide to be used. Thanks :)
[Galaxy S II Android Development] Goldie:
Nice explanation and good luck :)
[Galaxy S II Android Development] Biftor:
Thanks great explain!

I said it many page ago and I don't know why Goldie said me we don't need edit for use register more than v15 ...

Goodluck

Armin.
[Galaxy S II Android Development] Goldie:
Ffs. I didnt say that. I said its best to reuse. Which it is. As majdinj says in his post. The guy could reuse. And he did. Why would you go to all that trouble?

Please read my post before you make accusations. Did you really need to write that in your post? You could have just said thanks to majdinj for the explanation but ohhhhhh no....you have to say "Goldie said blah blah". How many times you want to do this....
[Galaxy S II Android Development] Biftor:
:D ahan I got you now mate!

I think that's because for my bad English, I was meaning from " all method " all register from that method we work on it.

No all method of that smali file :D I mean this...

Anyway Goldie you are the best. if I have time I will want work on Android 4.4 open source but I have any problems I can't access to good Internet connection and download source is very hard for me.

Can you help on java codes ? Because I was started learning java if you know java maybe we will have consultation :) .

Goodluck

Armin.
[Galaxy S II Android Development] Goldie:
Thats what I mean. For that one method. Not all. There was no need to move registers. He could just reuse some. Like I say...ive never ever had to do it.

I suck at java. Never had need to try to learn so never done any. :)
[Galaxy S II Android Development] remuntada78:
Good luck for your project and thank for your job here

Inviato dal mio GT-I9100 utilizzando Tapatalk
[Galaxy S II Android Development] Goldie:
Part 2: Coloring images, creating a method and passing context now up in post 2 :)
[Galaxy S II Android Development] remuntada78:
[MENTION=3065070]Goldie[/MENTION]

Hi Godie, i've some issue with powermenu textcolor:

as you can see in the pictures sometime summary text is show other not when i change color of text .

This may depend on what?

ohh:D and thanks for colorimage tutorial
[Galaxy S II Android Development] Goldie:
Assume its on another setText in another cond maybe :)
[Galaxy S II Android Development] Goldie:
How to use a porterduff mode added to bottom of coloring images post :)
[Galaxy S II Android Development] Goldie:
Toggling things on/off, show/hide and calling items by ID added to 3rd post :)
[Galaxy S II Android Development] maskerwsk:
just doing the first mod to date view and when searching for:

invoke-virtual {p0, v5}, Lcom/android/systemui/statusbar/policy/DateView;->setText(Ljava/lang/CharSequenceV

it returns 3 references, and there all in the UpdateClock method.

how do I determine which one to use? or do I apply the mod to all 3?

thanks

EDIT - never mind I had to apply it to all 3 for it to work :)
[Galaxy S II Android Development] maskerwsk:
hey, can you tell me if im barking up the wrong tree here, been trying asll morning with no result.

want to change the text colour for the quick toggles.

using smali 'QuickSettingButton'

searched for 'setText(Ljava/lang/CharSequence;)V'

and found this

'

.line 133
:cond_0
iget-object v0, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mBtnText:Landroid/widget/TextView;

iget-object v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mText:Ljava/lang/String;

invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

goto :goto_0

.line 137

edited that so it ends up like this:

.line 133
:cond_0
iget-object v0, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mBtnText:Landroid/widget/TextView;

iget-object v1, p0, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->mText:Ljava/lang/String;

invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

invoke-virtual {p0}, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->getContext()Landroid/content/Context;

move-result-object v1

invoke-virtual {v1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v1

const-string v2, "toggle_text_color"

const v3, -0xcc4a1a

invoke-static {v1, v2, v3}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/policy/quicksetting/QuickSettingButton;->setTextColor(I)V

goto :goto_0

.line 137

all recompiles fine and no FC after flash, toggles are there and working right but no colour change :S

Obviously ive added the colour picker etc to my rom control but changing colour does nothing
[Galaxy S II Android Development] Goldie:
TextView is in v0 as you can see in setText call. You are invoking color on p0 ;)
[Galaxy S II Android Development] maskerwsk:
ahhh missed that one ;)

still same outcome though :(

think I might be in wrong method/smali
[Galaxy S II Android Development] remuntada78:
Hi Goldie ,if I understand if i implement this tut for my text color when checkbox is not checked I will have defoult text color and when is checked i can change color, is right?
[Galaxy S II Android Development] Goldie:
Right ;)
[Galaxy S II Android Development] remuntada78:
i tried to implement turning things on/off on my set text color for powermenu, i added blu lines

.line 847
iget v6, p0, Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;->mMessageResId:I

invoke-virtual {v2, v6}, Landroid/widget/TextView;->setText(I)V

[COLOR="Blue"] invoke-virtual {v2}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "checkbox_preference"

const v9, 0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result-object v7

if-nez v7, :cond_skip_text

:cond_skip_text[/COLOR]
invoke-virtual {v2}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "text_color"

const v9, -0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v7

invoke-virtual {v2, v7}, Landroid/widget/TextView;->setTextColor(I)V

.line 848
.
.
.
iget v6, p0, Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;->mEnabledStatusMessageResId:I

:goto_5b
invoke-virtual {v4, v6}, Landroid/widget/TextView;->setText(I)V

[COLOR="Blue"] invoke-virtual {v4}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "checkbox_preference"

const v9, 0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result-object v7

if-nez v7, :cond_skip

:cond_skip	[/COLOR]
invoke-virtual {v4}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "text_color"

const v9, -0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v7

invoke-virtual {v4, v7}, Landroid/widget/TextView;->setTextColor(I)V

.line 860

but I got this error

I need to use other registers?
[Galaxy S II Android Development] Goldie:
After content resolver should be move result not move result object.

Also....change if-nez to if-eqz. And then move your cond_skip_text to after the setTextColor. As it is it will always color as if its on it will return true to if nez and run the cond_skip_text code and if its off then it will return false and carry on....straight into the cond_skip_text.

Changing to if-eqz and moving the cond will have the effect that if its on it will return false and run the color code and if its off it will return true and skip to the cond_skip_text after the color code.

Make sense?
[Galaxy S II Android Development] remuntada78:
i'm inattentive is written in tutorial too:p
[Galaxy S II Android Development] Goldie:
You changed too many. The first move is object and the second. The third is just move result. Like this...

invoke-virtual {v2}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "checkbox_preference"

const/4 v9, 0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v7

if-nez v7, :cond_skip_text

:cond_skip_text

And you need to change the if-nez etc like I said before. :)
[Galaxy S II Android Development] remuntada78:
i'm not sure if i understand ,you mean like this?

iget v6, p0, Lcom/android/internal/policy/impl/GlobalActions$ToggleAction;->mMessageResId:I

invoke-virtual {v2, v6}, Landroid/widget/TextView;->setText(I)V

[COLOR="Red"]	invoke-virtual {v2}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "checkbox_preference"

const/4 v9, 0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v7

if-eqz v7, :cond_skip_text[/COLOR]

invoke-virtual {v2}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

move-result-object v7

invoke-virtual {v7}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v7

const-string v8, "text_color"

const v9, -0x1

invoke-static {v7, v8, v9}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v7

invoke-virtual {v2, v7}, Landroid/widget/TextView;->setTextColor(I)V

[COLOR="Red"] :cond_skip_text[/COLOR]
[Galaxy S II Android Development] Goldie:
Exactly :)
[Galaxy S II Android Development] remuntada78:
I will need to do like this in GlobalAction $ Singlepress.smali too , because in it i implemented like first way but not report error?

Inviato dal mio GT-I9100 utilizzando Tapatalk
[Galaxy S II Android Development] Goldie:
I guess so yes. Its just the move-result-object and changing to if-eqz and moving the cond :)
[Galaxy S II Android Development] remuntada78:
Ok:thumbup:

Inviato dal mio GT-I9100 utilizzando Tapatalk
[Galaxy S II Android Development] remuntada78:
ok:laugh: it works wonderfully

to implement checkboxpreference in my Settings/Display i folllowed this guidehttp://xdaforums.com/showthread.php?t=2487740thanks to [MENTION=369057]majdinj[/MENTION] too
[Galaxy S II Android Development] sbreen94:
This thread really is awesome [MENTION=3065070]Goldie[/MENTION], so informative and such a valuable resource on smali. Thanks again for writing this up!
[Galaxy S II Android Development] rompnit:
+1000!! Great guide, and presented in a way that's easy to follow and understand. Thank you for this!!
[Galaxy S II Android Development] remuntada78:
Hi Goldie i would like to know if there is some code that has the task of replacing the images?, i thought something like setImageDrawable or similar
[Galaxy S II Android Development] homeslice976:
Hello all and thanks for taking the time to read. I'm the kind of guy who likes to tinker until I figure out what I'm trying to do, but working with smali tends to stop me in my tracks.. I'm currently using an HTC One running GPe KitKat, and it's great, but I've found a few things that I wanted to change. One of these is that by default, long pressing home launched Google Now and double-tapping launched Recent Apps. I like to have a dedicated menu button, so I changed these actions so that long pressing would launch recent items, and added a sendMenuKey method so that i could call it for double press home. This is working great. Then I decided I wanted to try to make this a setting. I have added it to settings, but this is where I get confused. First, I know all the methods are there for launchAssistAction (google now), sendMenuKey (menu), and toggleRecentApps (recent apps) in PhoneWindowManager.smali, but I don't know enough about smali to edit the handleLongPressOnHome and handleDoubleTapOnHome methods to include all of these, and i don't know how to make Settings call upon these methods when selecting their corresponding array-values (I'm guessing this is how it would work?).

Original and edited PhoneWindowManager.smali attached, as well as screenshots of the Settings. Thanks for any information/pointers anyone can provide!
[Galaxy S II Android Development] Goldie:
This ia quite a coincidence as im working on exactly that at the moment! Ive just added a custom app selection for double click home and now trying to do a list selector change function in the same way you mentioned. Will post more when I have more done :)
[Galaxy S II Android Development] Many40:
Hi Goldie :)

First of all congratulations for your amazing guides. I've been waiting especially for the last one (Toggles).

Recently I tried to use your guide "Toggles/Calling things by ID" but I've been stuck - probably (as usuall) I made a newbie mistake

(so far dealing with smali code is for me like blundering in the darkness) ;)

I tried to hide a button's image on statusbar by using your method (a little adjusted for my needs) in PhoneStatusBar.smali:

.method update_power_button()V
.locals 6

iget-object v1, p0, Lcom/android/systemui/SystemUI;->mContext:Landroid/content/Context;

invoke-virtual {v1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v1

const-string v2, "power_button_sb"

const/4 v3, 0x1

invoke-static {v1, v2, v3}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v3

if-nez v3, :cond_1

const/4 v3, 0x8

:cond_1
iget-object v4, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarWindow:Lcom/android/systemui/statusbar/phone/StatusBarWindowView;

const v5, 0x7f020322

invoke-virtual {v4, v5}, Lcom/android/systemui/statusbar/phone/StatusBarWindowView;->findViewById(I)Landroid/view/View;

move-result-object v4

invoke-virtual {v4, v3}, Landroid/widget/FrameLayout;->setVisibility(I)V

return-void
.end method

but I ended up at this error message from apktool:

[11363,4] The literal value must be between -8 and 7 inclusive

where 11363 corresponds with this line:

iget-object v4, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarWindow:Lcom/android/systemui/statusbar/phone/StatusBarWindowView;

Any hints appreciated :)
[Galaxy S II Android Development] Goldie:
Maybe a mistake in the guide. Try to change const/4 v3, 0x8 to just const v3, 0x8? Will have another look later tonight :)
[Galaxy S II Android Development] Many40:
:eek: Compiled :) :good:

Thank you. Now it's time for SecSettings.apk (to make a toggle) and will see if it works.
[Galaxy S II Android Development] Goldie:
Great. Let me know how it goes :)
[Galaxy S II Android Development] Many40:
- SecSettings toggle works

- SystemUI FC :(

A difference between your case and mine is that you hide "recents" button on statusbar expanded and I try to do the same with invisible/transparent ;) button on statusbar. Also I used FrameLayout instead of LinearLayout to set visibility. Does it matter?

BTW I assumed that by hiding the power button the assigned activity also will be off (what is my expected final goal). Or maybe my initial assumption is wrong :confused:

Also I changed registers to this:

iget-object [COLOR="Red"]v4[/COLOR], p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarWindow:Lcom/android/systemui/statusbar/phone/StatusBarWindowView;

const [COLOR="red"]v5[/COLOR], 0x7f020322

invoke-virtual {[COLOR="red"]v4[/COLOR], [COLOR="red"]v5[/COLOR]}, Lcom/android/systemui/statusbar/phone/StatusBarWindowView;->findViewById(I)Landroid/view/View;

because in your explanation they are like above but at the end you increased them by "1". Is it OK?

Edit: or maybe I should use for my case the field mStatusBarView instead of mStatusBarWindow?
[Galaxy S II Android Development] Goldie:
Whats the dump state say? Your edit may be correct :)