Related
Hi guys,i translated the key part of this guide,untill now,this guide is not completed ,if it updated ,i'll update this thread too
and until now,our MIUI PORT TEAM have these guys:
me,gabwerkz,redy2006
N00BY0815 and SquaDrive after read this post and if you want to join in plz let me know anyone else wants to join in are welcomed
===========================================line
1.A Sample For Smali
imagane that there's a Hello worlk application,we install the apk and open it,we can see a blackscreen and at the first line written:Hello world!
ok,this is a simple app.now we decompile it.
===================
we get a folder,then find the HelloActivity.smali,there's its content:
Code:
.class public Lcom/example/android/helloactivity/HelloActivity;
.super Landroid/app/Activity;
.source "HelloActivity.java"
# direct methods
.method public constructor <init>()V
.locals 0
.prologue
.line 27
invoke-direct {p0}, Landroid/app/Activity;-><init>()V
return-void
.end method
# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
.locals 2
.parameter "savedInstanceState"
.prologue
.line 33
invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
.line 37
const/high16 v1, 0x7f03
invoke-virtual {p0, v1},
Lcom/example/android/helloactivity/HelloActivity;->setContentView(I)V
.line 38
const/high16 v1, 0x7f05
invoke-virtual {p0, v1},
Lcom/example/android/helloactivity/HelloActivity;->findViewById(I)Landroid/view/View;
move-result-object v0
check-cast v0, Landroid/widget/TextView;
.line 39
.local v0, txtView:android/widget/TextView;
const/high16 v1, 0x7f04
invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(I)V
.line 40
return-void
.end method
"#" refers to notes.
begin with a dot named "annotations".
".line" means line number,it mainly used for debug.
.metho and .end method means a method's starting and endding.
more code plz goto http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html
now we want to change the "Hello,world!" into "Happy,Craker!",what should we do?
in this smali
.lne 39 is
Code:
.local v0, txtView:android/widget/TextView;
const/high16 v1, 0x7f04
invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(I)V
and actually the source code is
Code:
txtView.setText(R.string.hello_activity_text_text)
here we can see it define a textview with R.string.hello_activity_text_text ,and i guess the string "Hello world!" is in it.
now we could not change the string,but we can replace it by change it directly
but how we do it in smali?
here we go
Code:
.line 39
.local v0, txtView:android/widget/TextView;
const-string v1, "Happy, Cracker!"
invoke-virtual {v0, v1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V
ps.i can't explane it more clearly,but we can see we replace the id with our string.
==========================
2.Porting MIUI Framework
Before starting i should tell us :all porting is based on deodexed files.and there's a stock android rom and miui rom to show you a example to understand how we make the porting work.
the main idea is change the smali code to port it.cause we can't get the souce code of miui,and by this way we can port it to our phone too.
the three files we should touch is :framework.jar ,android.policy.jar andservices.jar.they are the "core" of android system
there's an attach file download and open it we can see:
porting-miui/
|-----------------android
|------------framework.jar
|------------services.jar
|------------android.policy.jar
|------------------miui
|----------framework.jar
|----------services.jar
|----------android.policy.jar
|-----------framework-res/
|-----------framework-miui-res.apk
the android folder is from stock android ,miui folder is miui's files,and we need your phone's files here too.and in this guide we assume your phone is I9100.now we should decompile all of them and compare,to "patch" miui things to your phone.
that means ,we need to compare stock files with our files,compare stock files with miui files
i.porting resources
decompile framework-res.apk,all the resources in miui we need porting to our rom,so copy them to your compiled framework-res folder and then recompile it.
framework-miui-res.apk is a resouces package,all the miui apps need it.in our rom we can find RES_cappuccino.apk,RES_sui.apk and RES_model.apk.
usually miui's resource's id is started with 0x03,and the stock rom has two resouce package,framework-res.apk is started with 0x01 and another is started with 0x02.so if your phone has more than two package,you need contact with us.in the future we'll considering make the resouce's id started with 0x06 in miui.
ii.after we finish the decompile we can use the script rmline.sh to delete all the lines started with .line to make us more easier to compare the difference with two smali code.but backup the original decomplied files first plz.we can debug from it.
then,if you based on linux,you'd try meld to compare,if you are on windows,use beyoun compare
between stock and miui,we can see there's a lot of new classes which started with Miui,and a new miui folder,just copy those new files and folders to our stock folders(with .line)
in the attach file,there's a change-list file,which list what miui did change.maybe it's a little different with what we compared by ourselves,but it's nop (dummy instruction),it caused by apktool,so we don't need to care it,just compare listed files.
there are 3 solutions
1.ex. ActivityThread.smali,miui changed the method "getTopLevelResources",but i9100's and stock is the same,this is the easiest situation and we can replace the miui code into our files happily
2.also in ActivityThread.smali,miui changed the another method "applyConfigurationToResourcesLocked",and after comparation,we can see miui changed this method,so i9100 does.then what should we do?let's see the miui's code first
Code:
.method final applyConfigurationToResourcesLocked(Landroid/content/res/Configuration;)Z
invoke-virtual {v5, p1}, Landroid/content/res/Configuration;->updateFrom(Landroid/content/res/Configuration;)I
move-result v0
.local v0, changes:I
invoke-static {v0}, Landroid/app/MiuiThemeHelper;->handleExtraConfigurationChanges(I)V
invoke-virtual {p0, v7}, Landroid/app/ActivityThread;->getDisplayMetricsLocked(Z)Landroid/util/DisplayMetrics;
move-result-object v1
.local v1, dm:Landroid/util/DisplayMetrics;
at line 5 is what miui changed.before that,we should know some rule about smali
all the local variable is started with "v"
.locals 8 means this method use 8 local variables.
all the parameters are started by "p".and local variable and parameters started from 0.for all the nonstatic method,p0 means itself,i.e "this" pointer.
here we can see miui added a new static method,the code like this we call it linear code.it as one entry and one exit.and in compiler it called basic block.
so we just need to copy this block and paste into 9100's files at the same position,and we done.
3.for example,in Resources.smali,miui changed the "loadDrawable" method.here's the code
Code:
.method loadDrawable(Landroid/util/TypedValue;I)Landroid/graphics/drawable/Drawable;
.end local v8 #e:Ljava/lang/Exception;
.end local v13 #rnf:Landroid/content/res/Resources$NotFoundException;
:cond_6
invoke-virtual/range {p0 .. p2},
Landroid/content/res/Resources;->loadOverlayDrawable(Landroid/util/TypedValue;I)Landroid/graphics/drawable/Drawable;
move-result-object v6
if-nez v6, :cond_1
:try_start_1
move-object/from16 v0, p0
from line 6 to line 9 is what miui added.then we compare 9100 and stock android,we can find it's totally different.then how should we do now?
the key is find the added code's entry and exit.
at line 4 we see a ":cond_6",it says there should be a goto command to this :cond_6.so we got to find where used the :cond_6 and we finally got this:
Code:
const-string v15, ".xml"
invoke-virtual {v9, v15}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
move-result v15
if-eqz v15, :cond_6
read this code block carefully,and seems it is check if the string "v9" is ending with ".xml",if not,goto :cond_6 .ok ,let's go to see 9100's framework.
so we search ".xml" in the loadDrable method.find this:
Code:
const-string v17, ".xml"
move-object v0, v10
move-object/from16 v1, v17
invoke-virtual {v0, v1}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z
move-result v17
if-eqz v17, :cond_b
the logic is same as which in miui hmm?so goto :cond_b ,what we can see is totally same as miui's :cond_6 right? so we are sure this is where miui changed
look at the exit,miui has two exit point
one is if-nez v6, :cond_1 ,if so,goto :cond_1,if not,go on.so let's see what the :cond_1 did
here's cond_1's code
Code:
:cond_1
:goto_1
if-eqz v6, :cond_2
move-object/from16 v0, p1
iget v0, v0, Landroid/util/TypedValue;->changingConfigurations:I
and in 9100's file we can find this
Code:
:cond_1
:goto_1
if-eqz v7, :cond_2
move-object/from16 v0, p1
iget v0, v0, Landroid/util/TypedValue;->changingConfigurations:I
this time it check the v7's value,so we should add this into 9100
Code:
invoke-virtual/range {p0 .. p2},
Landroid/content/res/Resources;->loadOverlayDrawable(Landroid/util/TypedValue;I)Landroid/graphics/drawable/Drawable;
move-result-object v7
if-nez v7, :cond_1
a little dizzy hmm?take a break time and go back
iii.and the last we'll talk about inner class.
every inner class have a separete smali file.
e. ActivityThread$1.smali
if it is a Anonymous class,the name should be "outer class+$+number",else it should be "outer class+$+inner class"as its name.
if a inner class use outer class's privte method,the compiler will auto fill a static function like this:
Code:
public class Hello {
public class A {
void func() {
setup();
}
}
private void setup() {
}
we use the outer class's setup method in inner class A's "func" method.and we'll get the smali code:
part of Hello$A.smali
Code:
# virtual methods
.method func()V
.locals 1
.prologue
.line 5
iget-object v0, p0, LHello$A;->this$0:LHello;
#calls: LHello;->setup()V
invoke-static {v0}, LHello;->access$000(LHello;)V
.line 6
return-void
.end method
part of Hello.smali
Code:
.method static synthetic access$000(LHello;)V
.locals 0
.parameter
.prologue
.line 1
invoke-direct {p0}, LHello;->setup()V
return-void
.end method
we can see the compiler auto made a access$000 method,if we use a outer class's private method in a more complicate inner class,it'll made a new method,but every class may have various new class name,it changes a lot .compare it carefully,find the private method and find a name that you ever seened.
iiii.Finally there are some advices:
1.careful,find where to add miui's code
2.notice the local variable number
3.step by step,if you done a part of port,recompile it to see if it work
4.find a problem is not neccessary,use adb logcat and find what caused the problem.
5.more practice and you'll handle the smali code
==================================
because of my bad english ,if you can understand what i mean,plz point me out and i'll correct it as i can
if you think this post may help you,press the thanks button
here's the attachment:
http://www.multiupload.com/I33A07PRTF
For God Sake..
ahahahaha...
My head goin crazy...><..
maybe i need a little walk by learn..
after read those stuff i got fired up..
i want to learn Android from this..
can u guys teaching me little by little??
if so, count me on..i'm ready for testing every single build
and ready to burst my brain to learn this stuff..
SquaDrive said:
For God Sake..
ahahahaha...
My head goin crazy...><..
maybe i need a little walk by learn..
after read those stuff i got fired up..
i want to learn Android from this..
can u guys teaching me little by little??
if so, count me on..i'm ready for testing every single build
and ready to burst my brain to learn this stuff..
Click to expand...
Click to collapse
just use search...
after i tranlated this guide,i'd say i've understand a part of the "how to",and i'll gonna have a try based on v20n
dxdiag32 said:
after i tranlated this guide,i'd say i've understand a part of the "how to",and i'll gonna have a try based on v20n
Click to expand...
Click to collapse
Nice... and I'm just waiting here for your progress... LOL
Man, you got moves like jagger.
good luck dxdiag
Is there some progress?
Sent from my LG-P970 using XDA App
I would like to help, but I have too work now...
Good luck!
I think Huexxx should start porting MIUI to ours blacks xd His rom is good at this moment so he can make some break and create MIUI
doooh !
I really would offer my help but the only dev related thing I know is scripting with nsis. I don't know coding even if I'm pretty sure scripting and coding have similar principles. I don't even know what deodexing / zipaligning mean
As I learned everything by myself I know that all guides can't do 100% of the job. Learning is the key.
So I'm not sure if I can contribute but it will be a pleasure to join to your work.
Any news guys ?
Sent from my LG-P970 using xda premium
I can't do CRT animation by my self. Because changing the value of config_animateScreenLights from true to false in framework-res.apk is not working anymore!
The problem is that are some missing commands in the /system/framework/services.jar
After comparing files from GB and ICS, i might have come up with a Method.
This is what have to be done:
First of all decompile classes of services.jar (I won't provide any information to this, there are many tutorials out there how to use the smali tools!)
Then in com/android/server/PowerManagerService.smali we have to make the method nativeStartSurfaceFlingerAnimation(I)V callable from inner classes. To do that, we have to add the following after the last access$XXXX method:
Code:
.method static synthetic access$9000(Lcom/android/server/PowerManagerService;I)V
.registers 2
.parameter "x0"
.parameter "x1"
.prologue
.line 110
invoke-direct {p0, p1}, Lcom/android/server/PowerManagerService;->nativeStartSurfaceFlingerAnimation(I)V
return-void
.end method
Than we have to add some commands to the file com/android/server/PowerManagerService$BrightnessState.smali to trigger the CRT-off-effect. For that add the red part between :cond_38 and iget-object v4, p0, Lcom/a.... like this (its around line 400 in code):
Code:
.line 2679
.restart local v3 #turningOff:Z
:cond_38
iget-object v4, p0, Lcom/android/server/PowerManagerService$BrightnessState;->this$0:Lcom/android/server/PowerManagerService;
const/16 v3, 0x11 # CRT-On and CRT-Off
#calls: Lcom/android/server/PowerManagerService;->nativeStartSurfaceFlingerAnimation(I)
invoke-static {v4, v3}, Lcom/android/server/PowerManagerService;->access$9000(Lcom/android/server/PowerManagerService;I)V
iget-object v4, p0, Lcom/android/server/PowerManagerService$BrightnessState;->this$0:Lcom/android/server/PowerManagerService;
#getter for: Lcom/android/server/PowerManagerService;->mScreenBrightness:Lcom/android/server/PowerManagerService$BrightnessState;
invoke-static {v4}, Lcom/android/server/PowerManagerService;->access$6000(Lcom/android/server/PowerManagerServiceLcom/android/server/PowerManagerService$BrightnessState;
move-result-object v4
Lastly, recompile the file, put it on your phone CRT-off effect will be magically displayed.
Lastly, i really seek the devs help to work on this and bring success to this work.
post
This is for stock Sony I suppose?
You're not getting any animation at all? I ask because stock Sony has a different animation than AOSP/CM. Stock uses a blurred circle like animation which "closes" towards the center of the screen. The opposite direction of movement when you turn on the device.
After searching months for a way to allow Unknown Sources by default on the HTC One, I've finally discovered where to mod it so I thought I would share for the benefit of the community. Its one of the more convenient mods to have and I thought it would be a great for lazy people like me who want to quickly restore their setup while trying other roms and not have to deal with Blocked install messages lol.
You will need to have apktool or similar tools and decompiling knowledge before attempting this.
Previously you would need to mod SettingsProvider.apk but on Sense 5 that is no longer the case. There are two APK's to look at here. PureC_PackageInstaller and Settings.apk. PureC is the main one you want to look at.
Decompile PureC_PackageInstaller and find this directory in smali folder:
\smali\com\android\packageinstaller\PackageInstallerActivity.smali
open up PackageInstallerActivity.smali and look for this method:
Code:
.method private isInstallingUnknownAppsAllowed()Z
.locals 3
.prologue
const/4 v0, 0x0
.line 261
invoke-virtual {p0}, Lcom/android/packageinstaller/PackageInstallerActivity;->getContentResolver()Landroid/content/ContentResolver;
move-result-object v1
const-string v2, "install_non_market_apps"
invoke-static {v1, v2, v0}, Landroid/provider/Settings$Secure;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
move-result v1
if-lez v1, :cond_0
const/4 v0, 0x1
:cond_0
return v0
.end method
change
Code:
.locals 3
.prologue
const/4 v0, 0x0
.line 261
to this
Code:
.locals 3
.prologue
const/4 v0, 0x1
.line 261
recompile and you are done
next decompile Settings.apk(optional!)
the only reason to edit this is to give the mod the appearance that Unknown Sources is visibly checked in Settings menu, otherwise the mod still works fine even if it isn't checked.
find this directory:
\smali\com\android\settings\SecuritySettings.smali
locate this method:
Code:
.method private isNonMarketAppsAllowed()Z
.locals 3
const/4 v0, 0x0
invoke-virtual {p0}, Lcom/android/settings/SecuritySettings;->getContentResolver()Landroid/content/ContentResolver;
move-result-object v1
const-string v2, "install_non_market_apps"
invoke-static {v1, v2, v0}, Landroid/provider/Settings$Secure;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
move-result v1
if-lez v1, :cond_0
const/4 v0, 0x1
:cond_0
return v0
.end method
change the 0x0 to 0x1, and change the 0x1 to 0x0.
recompile and your done.
tested this and working on Sprint HTC One variant, but i'm almost certain this should work on any carrier with version of Sense 5.
also of note: there is a small glitch to this mod while toggling the checkbox on and off. it'll recheck itself if you turn it off and come back to the options screen again. Plus, I turned off the disabled function completely as a temporary solution because there was another glitch where you couldn't install apps while it was checked on if you messed around trying to turn it off, but why would you want to? lol
You can also just edit the default.xml in customize
<item name="def_install_non_market_apps">1</item>
Sent from my HTCONE using Tapatalk 2
is there any way to do this in android10 ?
Hi guys,
Today I'm going to share a method with which you can add apps shortcuts to your SystemUI, well it's called Onclick method and it's not mine it's sir @SpaceCaker's and as I got he's permission to make a separate guide on it I'm posting this, I said separate because this guide is already there on he's 4.2.2 status bar guide but I thought a separate guide would be more helpful for some people so I'm posting this with permission so let's begin
Requirements:
Brain
Patience
Experience
Apktool or anything like it
How to:
1. Decompile your SystemUI.apk
2. Go to smali/com/android/systemui/SystemUIService.smali
3. Now add this:
Code:
.method public settings(Landroid/view/
View;)V
.locals 5
.parameter "view"
.prologue
.line 99
.line 100
:try_start_0
new-instance v1, Landroid/content/Intent;
invoke-direct {v1}, Landroid/content/Intent;-
><init>()V
.line 102
.local v1, intent:Landroid/content/Intent;
const-string v2, "android.intent.action.MAIN"
invoke-virtual {v1, v2}, Landroid/content/
Intent;->setAction(Ljava/lang/String;)Landroid/
content/Intent;
.line 105
const/high16 v2, 0x1000
invoke-virtual {v1, v2}, Landroid/content/
Intent;->setFlags(I)Landroid/content/Intent;
.line 107
const-string v2, "com.android.settings"
const-string v3,
"com.android.settings.Settings"
invoke-virtual {v1, v2, v3}, Landroid/content/
Intent;->setClassName(Ljava/lang/String;Ljava/
lang/String;)Landroid/content/Intent;
invoke-virtual {p0, v1}, Lcom/android/systemui/
SystemUIService;->startActivity(Landroid/
content/Intent;)V
:try_end_0
.catch Ljava/lang/Exception; {:try_start_
0 .. :try_end_0} :catch_0
.line 109
.line 112
.end local v1 #intent:Landroid/content/
Intent;
:goto_0
return-void
.line 115
:catch_0
move-exception v0
.line 117
.local v0, e:Ljava/lang/Exception;
invoke-virtual {v0}, Ljava/lang/Exception;-
>printStackTrace()V
goto :goto_0
.end method
4. Now you can edit 3 things in it and they are:
1. The Onclick title: "settings" above here or in easy words the one below between "****"
Code:
.method public "anything"(Landroid/view/View;)V
2. The package: const-string v2, "anything"
3. The activity: const-string v3, "anything"
4. So now you need to edit these 3 things to whatever you want, give your Onclick a title, change the package and than the activity, do note you have to edit both and you can add any shortcut with this but if you're adding user installed apps shortcuts than make sure you have the app installed
5. Now add this to res/layout/"wherever you want "
Code:
android:onClick="anything"
This is what adds the onclick method to something
6. Now recompile your SystemUI.apk, sign, push, reboot and enjoy a shortcut which will save some valuable time of yours
Credits:
@SpaceCaker
Use this app to get the activities:
https://play.google.com/store/apps/details?id=de.szalkowski.activitylauncher&hl=en
If your browser has problems with coping the code from the first post download this and copy:
https://www.androidfilehost.com/?fid=673368273298942983
Screenshot:
[Guide] How to add a SettingsObserver to your Rom
This will allow you to add a settings observer to existing smali.
Adding a settings observer allows you to create a real-time update to an existing mod such as colors and toggles so the modification takes effect instantly without any other user intervention such as reboots, etc.
Huge credits @remuntada for all the information included in this guide.
Probably the most utilized settings observer is present for the PhoneStatusBar.smali in SystemUI.apk so we will provide this as an example:
Also see here for example of how to add a RegObserver to QSPanel
RegObserver Guide
SettingsObserver Guide
SystemUI.apk smali edits:
\smali\com\android\systemui\statusbar\phone\PhoneStatusBar.smali
New code is in BLUE
Code:
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$PmsBrightnessEnableObserver;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$EasyModeEnableObserver;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$BrightnessEnableObserver;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$BatteryTextObserver;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$DozeServiceHost;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$ShadeUpdates;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$FastColorDrawable;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$MyTicker;,
[COLOR="Blue"]Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;,[/COLOR]
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$H;,
Lcom/android/systemui/statusbar/phone/PhoneStatusBar$EmergencyModeObserver;,
}
.end annotation
Same smali, add new code in BLUE
The edit is about halfway into the smali. Make sure the values of the new code match the surrounding values. Note that after that :cond_0 there may be additional code in your smali. Just insert the new code where indicated.
Code:
.method public start()V
.
.
.
:cond_0[COLOR="Blue"]
new-instance v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;
iget-object v1, p0, Lcom/android/systemui/statusbar/BaseStatusBar;->mHandler:Lcom/android/systemui/statusbar/BaseStatusBar$H;
invoke-direct {v0, p0, v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;-><init>(Lcom/android/systemui/statusbar/phone/PhoneStatusBar;Landroid/os/Handler;)V
invoke-virtual {v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->observe()V[/COLOR]
new-instance v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBarPolicy;
iget-object v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mContext:Landroid/content/Context;
iget-object v2, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mCastController:Lcom/android/systemui/statusbar/policy/CastControllerImpl;
invoke-direct {v0, v1, v2}, Lcom/android/systemui/statusbar/phone/PhoneStatusBarPolicy;-><init>(Landroid/content/Context;Lcom/android/systemui/statusbar/policy/CastController;)V
iput-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mIconPolicy:Lcom/android/systemui/statusbar/phone/PhoneStatusBarPolicy;
Same smali, add YOUR new method.
This is just an example method of a mod I added to change the dateview color that gets invoked from the SettingsObserver:
Code:
.method setDateTextViewColor()V
.locals 8
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 v2
const-string v3, "pulldown_date_color"
const v1, -0x111112
invoke-static {v2, v3, v1}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
move-result v7
iget-object v5, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarWindow:Lcom/android/systemui/statusbar/phone/StatusBarWindowView;
const v6, 0x7f0d02b8 ## [COLOR="Green"]<public type="id" name="date_expanded"
[/COLOR]
invoke-virtual {v5, v6}, Lcom/android/systemui/statusbar/phone/StatusBarWindowView;->findViewById(I)Landroid/view/View;
move-result-object v4
check-cast v4, Landroid/widget/TextView;
invoke-virtual {v4, v7}, Landroid/widget/TextView;->setTextColor(I)V
return-void
.end method
Add the PhoneStatusBar$SettingsObserver.smali file already attached at the bottom of this post to the same folder as PhoneStatusBar.smali.
Now lets look in the PhoneStatusBar$SettingsObserver.smali to see how we made the changes to it.
Note the text in BLUE, this where we check for changes to the key string and in the second method is where the new method gets launched to update the view if changes have been detected to that key.
Note the text in GREEN, this is how you would add two more mods to the settings observer with two additional methods to invoke in PhoneStatusBar. They are only present as an example.
Code:
.class Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;
.super Landroid/database/ContentObserver;
.source "PhoneStatusBar.java"
# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
value = Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x0
name = "SettingsObserver"
.end annotation
# instance fields
.field final synthetic this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
# direct methods
.method constructor <init>(Lcom/android/systemui/statusbar/phone/PhoneStatusBar;Landroid/os/Handler;)V
.locals 0
iput-object p1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
invoke-direct {p0, p2}, Landroid/database/ContentObserver;-><init>(Landroid/os/Handler;)V
return-void
.end method
# virtual methods
.method observe()V
.locals 3
const/4 v2, 0x0
iget-object v1, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
iget-object v1, v1, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mContext:Landroid/content/Context;
invoke-virtual {v1}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
move-result-object v0
[COLOR="Blue"]const-string v1, "pulldown_date_color"
invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;
move-result-object v1
invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver[/COLOR](Landroid/net/Uri;ZLandroid/database/ContentObserver;)V
[COLOR="Green"]const-string v1, "second_settings_key_goes_here"
invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;
move-result-object v1
invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;)V
const-string v1, "third_settings_key_goes_here"
invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;
move-result-object v1
invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;)V[/COLOR]
return-void
.end method
.method public onChange(Z)V
.locals 1
[COLOR="Blue"] iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
invoke-virtual {v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->setDateTextViewColor()V
[/COLOR]
[COLOR="Green"]iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
invoke-virtual {v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->setSecondMethod()V
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/statusbar/phone/PhoneStatusBar;
invoke-virtual {v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->setThirdMethod()V
[/COLOR] return-void
.end method
Modifying and adding a Settings Observer to most other smalis:
For smali where #annotations does not exist, add a new one right below the .source line like in this example. If #annotations already exist, add the line to #annotations as in the PhoneStatusBar.smali example above.
Note the highlighted text in RED, this path must match the smali you are working in (the green highlighted path).
Code:
.class public [COLOR="Green"]Lcom/android/incallui/dialpad/DialpadView[/COLOR];
.super Landroid/widget/LinearLayout;
.source "DialpadView.java"
[COLOR="Blue"]# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
[COLOR="Red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR]$SettingsObserver;
}
.end annotation[/COLOR]
Search for either one of these methods:
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
And add the new code in BLUE (and Red) before the return-void at the end of the method.
Note that the paths in RED have to match the smali you're working in.
Note that I had to increase the .locals value to accommodate the new entry which I did in this example.
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
[COLOR="Blue"].locals 3[/COLOR]
const/4 v0, 0x0
invoke-direct {p0, p1, p2, v0}, Lcom/android/incallui/dialpad/DialpadView;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
[COLOR="blue"]new-instance v1, [COLOR="red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR]$SettingsObserver;
new-instance v2, Landroid/os/Handler;
invoke-direct {v2}, Landroid/os/Handler;-><init>()V
invoke-direct {v1, p0, v2}, [COLOR="red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR]$SettingsObserver;-><init>([COLOR="Red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR];Landroid/os/Handler;)V
invoke-virtual {v1}, [COLOR="red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR]$SettingsObserver;->observe()V
[/COLOR]
return-void
.end method
Important note:
Wouldn't you know it, the smali I chose to use as an example does not support mcontext so I used getContext here and in the attached DateView$SettingsObserver.smali
After the last .method public constructor method (or with the rest of the access$xxx methods, if they exist) insert this method.
Note the path highlighted in RED must match the smali you are working with.
Code:
.method static synthetic access$001([COLOR="Red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR];)Landroid/content/Context;
.locals 1
invoke-virtual {p0}, [COLOR="red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR];->getContext()Landroid/content/Context;
move-result-object v0
return-object v0
.end method
Important note:
Use this one instead if your smali DOES support mcontext:
Code:
.method static synthetic access$001([COLOR="red"]Lcom/android/keyguard/sec/SecKeyguardClockSingleView[/COLOR];)Landroid/content/Context;
.locals 1
iget-object v0, p0, [COLOR="red"]Lcom/android/keyguard/sec/SecKeyguardClockSingleView[/COLOR];->mContext:Landroid/content/Context;
return-object v0
.end method
How to create a new YourFile$SettingsObserver
I don't recommend using
PhoneStatusBar$SettingsObserver.smali or DateView$SettingsObserver.smali
as your templates. The first is specifically for PhoneStatusBar.smali and use DateView$SettingsObserver.smali if your smali does not support mcontext.
Using one of the attached $SettingsObserver files as a template, do the following edits throughout the ENTIRE $SettingsObserver.smali (only highlighting first few lines for brevity).
Find and replace all 14 of the paths to correspond with the smali you are working in.
The .source line is the smali name only. Change this to match the smali you are working in also.
The completed SettingsObserver.smali gets placed in the same folder as the parent smali we are working with.
Code:
.class public [COLOR="Red"]Lcom/android/incallui/dialpad/DialpadView[/COLOR]$SettingsObserver;
.super Landroid/database/ContentObserver;
.source "[COLOR="red"]DialpadView[/COLOR].java"
SettingsObserver example files have been attached to this post.
** some MM guide discussions begin here: http://forum.xda-developers.com/showpost.php?p=66480317&postcount=70
Reserved
I am totally open to alternate methods and critique on improving on this folks so don't be shy with the input.
tdunham said:
I am totally open to alternate methods and critique on improving on this folks so don't be shy with the input.
Click to expand...
Click to collapse
Are you??? tomorrow we will add our observer then ???
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Are you??? tomorrow we will add our observer then ???
Click to expand...
Click to collapse
Awesome!
I am fairly new to adding observers but I thought it was necessary to start this discussion with the established method and work our way up from there.
How would it be to change in real time with this guide ?: [How-to Guide] Colorize main dialpad Android letters & digits L
Do I have to create the settings observer?
tdunham said:
Awesome!
I am fairly new to adding observers but I thought it was necessary to start this discussion with the established method and work our way up from there.
Click to expand...
Click to collapse
No doubt!!! Keep it up! You're making xda tolerable again!
Sent from my awesome g920f powered by 6thGear
I have to say most of the work comes from the suggestion given to me by @CNexus here http://forum.xda-developers.com/showpost.php?p=50961314&postcount=527
Add the smali DateView$SettingsObserver to smali/com/android/dialer/dialpad and change all the routes to which it belongs.
Changing the .class public.
Should I do anything else?
aceqott said:
Add the smali DateView$SettingsObserver to smali/com/android/dialer/dialpad and change all the routes to which it belongs.
Changing the .class public.
Should I do anything else?
Click to expand...
Click to collapse
Its going to be pretty tough to add an observer to SecContacts, they chose to use letters for every single method so its going to be difficult to figure out where to place anything.
I'll look at it when I can but its probably not going to happen right away and like I said, I'm not having the dialpad color not changing instantly even without an observer so it is hard to tell if it will even work if I do find something.
tdunham said:
Its going to be pretty tough to add an observer to SecContacts, they chose to use letters for every single method so its going to be difficult to figure out where to place anything.
I'll look at it when I can but its probably not going to happen right away and like I said, I'm not having the dialpad color not changing instantly even without an observer so it is hard to tell if it will even work if I do find something.
Click to expand...
Click to collapse
Well, too bad, anyway I do not understand, I have seen now a video of other ROMs where if the digit is changed and letters SecContact real time.
While I catch a cold and am having a fever, honestly cannot convince myself to lay down and tell myself read this thread later. Thanks for amazing guide.:good:
kmokhtar79 said:
While I catch a cold and am having a fever, honestly cannot convince myself to lay down and tell myself read this thread later. Thanks for amazing guide.:good:
Click to expand...
Click to collapse
Get to bed and read on Tapatalk. ..
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Get to bed and read on Tapatalk. ..
Sent from my awesome g920f powered by 6thGear
Click to expand...
Click to collapse
I need wide screen [emoji16]
OK for start, I am asking to see whether if in theory I am understanding it correctly or not.
I am trying adding a new observe for battery color as once shared by @remuntada78.
I added this in my settings observer
Code:
const-string v1, "battery_color"
invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;
move-result-object v1
invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;)V
and
Code:
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/BatteryMeterView;
invoke-virtual {v0}, Lcom/android/systemui/BatteryMeterView;->setBatteryColor()V
and then in
BatteryMeterView.smali
Code:
.class public Lcom/android/systemui/BatteryMeterView;
.super Landroid/view/View;
.source "BatteryMeterView.java"
# interfaces
.implements Lcom/android/systemui/DemoMode;
.implements Lcom/android/systemui/statusbar/policy/BatteryController$BatteryStateChangeCallback;
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
[COLOR="Red"] Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;,[/COLOR]
Lcom/android/systemui/BatteryMeterView$BatteryTracker;
}
.end annotation
in the same smali:
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
.locals [COLOR="red"]2[/COLOR]
const/4 v0, 0x0
invoke-direct {p0, p1, p2, v0}, Lcom/android/systemui/BatteryMeterView;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
[COLOR="red"] new-instance v1, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;
new-instance v2, Landroid/os/Handler;
invoke-direct {v2}, Landroid/os/Handler;-><init>()V
invoke-direct {v1, p0, v2}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;-><init>(Lcom/android/systemui/BatteryMeterView;Landroid/os/Handler;)V
invoke-virtual {v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->observe()V[/COLOR]
return-void
.end method
and as my smali does not support mcontext I added following method in red
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V [COLOR="SeaGreen"]#last public constructor[/COLOR]
.
.
.
.end method
.method static synthetic access$000(Lcom/android/systemui/BatteryMeterView;)Landroid/os/Handler;
.locals 1
iget-object v0, p0, Lcom/android/systemui/BatteryMeterView;->mPostInvalidateHandler:Landroid/os/Handler;
return-object v0
.end method
[COLOR="red"].method static synthetic access$001(Lcom/android/systemui/BatteryMeterView;)Landroid/content/Context;
.locals 1
invoke-virtual {p0}, Lcom/android/systemui/BatteryMeterView;->getContext()Landroid/content/Context;
move-result-object v0
return-object v0
.end method[/COLOR]
And lastly have done those samli modification described here I don't try it.
kmokhtar79 said:
OK for start, I am asking to see whether if in theory I am understanding it correctly or not.
I am trying adding a new observe for battery color as once shared by @remuntada78.
I added this in my settings observer
Code:
const-string v1, "battery_color"
invoke-static {v1}, Landroid/provider/Settings$System;->getUriFor(Ljava/lang/String;)Landroid/net/Uri;
move-result-object v1
invoke-virtual {v0, v1, v2, p0}, Landroid/content/ContentResolver;->registerContentObserver(Landroid/net/Uri;ZLandroid/database/ContentObserver;)V
and
Code:
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->this$0:Lcom/android/systemui/BatteryMeterView;
invoke-virtual {v0}, Lcom/android/systemui/BatteryMeterView;->setBatteryColor()V
and then in
BatteryMeterView.smali
Code:
.class public Lcom/android/systemui/BatteryMeterView;
.super Landroid/view/View;
.source "BatteryMeterView.java"
# interfaces
.implements Lcom/android/systemui/DemoMode;
.implements Lcom/android/systemui/statusbar/policy/BatteryController$BatteryStateChangeCallback;
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
[COLOR="Red"] Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;,[/COLOR]
Lcom/android/systemui/BatteryMeterView$BatteryTracker;
}
.end annotation
in the same smali:
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
.locals [COLOR="red"]2[/COLOR]
const/4 v0, 0x0
invoke-direct {p0, p1, p2, v0}, Lcom/android/systemui/BatteryMeterView;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
[COLOR="red"] new-instance v1, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;
new-instance v2, Landroid/os/Handler;
invoke-direct {v2}, Landroid/os/Handler;-><init>()V
invoke-direct {v1, p0, v2}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;-><init>(Lcom/android/systemui/BatteryMeterView;Landroid/os/Handler;)V
invoke-virtual {v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar$SettingsObserver;->observe()V[/COLOR]
return-void
.end method
and as my smali does not support mcontext I added following method in red
Code:
.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V [COLOR="SeaGreen"]#last public constructor[/COLOR]
.
.
.
.end method
.method static synthetic access$000(Lcom/android/systemui/BatteryMeterView;)Landroid/os/Handler;
.locals 1
iget-object v0, p0, Lcom/android/systemui/BatteryMeterView;->mPostInvalidateHandler:Landroid/os/Handler;
return-object v0
.end method
[COLOR="red"].method static synthetic access$001(Lcom/android/systemui/BatteryMeterView;)Landroid/content/Context;
.locals 1
invoke-virtual {p0}, Lcom/android/systemui/BatteryMeterView;->getContext()Landroid/content/Context;
move-result-object v0
return-object v0
.end method[/COLOR]
And lastly have done those samli modification described here I don't try it.
Click to expand...
Click to collapse
Look at the red class declaration. You added observer class that belongs to a different class. You need an observer for this class. Not for PhoneStatusBar.smali
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Look at the red class declaration. You added observer class that belongs to a different class. You need an observer for this class. Not for PhoneStatusBar.smali
Sent from my awesome g920f powered by 6thGear
Click to expand...
Click to collapse
You are saying I need another observer to create as BatteryMeterView$SettingsObserver.smali right?
kmokhtar79 said:
You are saying I need another observer to create as BatteryMeterView$SettingsObserver.smali right?
Click to expand...
Click to collapse
Exactly. Observer is in this case an inner class. BatteryMeterView class cannot have an inner class that's called PhoneStatusBar$SettingsObserver.
http://www.javaworld.com/article/2077411/core-java/inner-classes.html
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Are you??? tomorrow we will add our observer then ???
Click to expand...
Click to collapse
@daxgirl
Looking for an alternate method to add an observer where one wouldn't normally work. No rush on this.
tdunham said:
@daxgirl
Looking for an alternate method to add an observer where one wouldn't normally work. No rush on this.
Click to expand...
Click to collapse
Lol... hi there. On this side "looking forward to finishing properly handling assets and scripts for the new custom settings app so I cac concentrate on other things"
Just to clarify the thing...
We have built a settings app a while ago for ourselves. Since we both work with java, we don't need it to be as automated as ficeto's app is. So now the biggest challenge is to make it available for all, by providing a code that wouldn't require an entire forum on xda to couch devs to use it and minimize your exposure to java where possible. Our goal is to provide as clean code is possible, so minimal changes to code would be required to operate the app. That is because we understand that most devs have minimal skills when it comes to original development. We dont want to force people to build special conditions and make huge changes to the java part of the app. So the automating part... It's taking time....
We have so far fully automated and integrative nav drawer, where items can be added easily with little guiding, theme change support, automated preference fragments, automated scripts execution from the app assets and automated preference handling from the get go, no matter how deep the preference tree goes (as many nesting preference screens as you want). Right now I am working on handling those things in separate classes, so the devs wouldn't need to copy huge chunks of code when they want to create another new preference fragment for their drawer.... and as much as it's fun, little time is left for anything else for now...
Sent from my awesome g920f powered by 6thGear