[GUIDE]SystemUi.apk Control Widgets Porting

Search This thread

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
I'm editing this thread to now be a guide on how I was able port the QP from the i9000.

Here's how it was ported:
First I downloaded the i9000's (SGS) stock deodexed Systemui.apk and decompiled
Next I decompiled the SystemUI.apk from the Nexus S in apk manager 4.7 (4.9 gave me issues when attempting to recompile)

Once you decompile the SystemUI.apk from the i9000, navigate to out/smali/com/android/systemui/statusbar

You'll notice a folder in there called quickpanel. Open the same folder on the decompiled Nexus systemui.apk and copy the entire quickpanel folder to the Nexus. Now you have to edit all the xmls in the res folder, start with status bar expanded.xml in the res/layout. Then ids.xml, then strings.xml, then public.xml in your res/values folder. Basically your going to add in every value from the i9000 that starts with "quickpanel". The public is a doozy, you have to assign the new values their own unique hex value. You should really be familiar with the hex naming scheme in public before attempting this, it's easy to screw up but worse case scenario is it won't compile for you. The status_bar_expanded in the layout folder, you only want to add the top line to your file don't overwrite any of the xml files from the i9000, only merge the pieces of code that call the widget into display.


Next you have to move on to the smali code. Navigate to the decompiled folder res/values/ from both phones and open public.xml. After, navigate to /out/smali/com/android/systemui/statusbar/quickpanel/ from both phones, and open the autorotationsettingbutton.smali. What your going to be looking for first, is the hex codes that appear in public.xml.

Code:
.line 67
    .local v2, rootView:Landroid/view/View;
    const v5, 0x7f090023
Code:
    .line 68
    .local v0, icon:Landroid/widget/ImageView;
    const v5, 0x7f090025
Code:
.line 82
    return-void

    .line 72
    :pswitch_0
    const v1, 0x7f020087

    .line 73
    const v4, 0x7f020085

    .line 74
    goto :goto_0

    .line 76
    :pswitch_1
    const v1, 0x7f020086

    .line 77
    const v4, 0x7f020084

    goto :goto_0

Each of these hex codes "0x7f0200xx" match up to a drawable in publix.xml. Start with the i9000 systemui.apk and see what picture it's pointing to by searching the number in the public.xml, then move over to the Nexus S systemui.apk and open the public (That you already modded and added the values in for the quickpanel items) and match to the name of the drawable in the i9000, to the name in public from Nexus, then copy the New hex code from the Nexus public to the autorotationsettingbutton.smali. This way your new smali file will be pointing to the correct drawable in the Nexus systemui.apk. Note all the way at the bottom of the smali file in both phones is 1 more hex value to change. Just scroll down to almost the bottom and look for another number that looks like the previous ones. Change that final hex and save your work. Now open all the other files ie bluetoothsettingsbutton gpssettingsbutton soundsettingsbutton, wifisettingsbutoon. Repeat the same steps for changing the hex values for picture display.

Now open the wifisettingsbutton.smali and we have to mod the code since our phones don't access the wifi the same.

Code:
    .line 63
    nop

    :pswitch_data_0
    .packed-switch 0x0
        :pswitch_2
        :pswitch_1
        :pswitch_2
        :pswitch_0
	[B]:pswitch_1[/B]
    .end packed-switch
.end method
In this code in wifisettingsbutton, the final line :pswitch_1 is added, it's not present in the original. You must adjust this value.


Code:
    .line 123
    iget-object v1, p0, Lcom/android/systemui/statusbar/quickpanel/WifiSettingButton;->mWifiManager:Landroid/net/wifi/WifiManager;

    const/4 v2, 0x1

    invoke-virtual {v1, v2}, Landroid/net/wifi/WifiManager;->setWifiEnabledDialog(Z)Z

    goto :goto_0
.end method


Code:
    .line 123
    iget-object v1, p0, Lcom/android/systemui/statusbar/quickpanel/WifiSettingButton;->mWifiManager:Landroid/net/wifi/WifiManager;

    const/4 v2, 0x1

    invoke-virtual {v1, v2}, Landroid/net/wifi/WifiManager;->setWifiEnabled(Z)Z

    goto :goto_0
.end method
In the above two codes, the first is the i9000 wifisettingsbutton, notice the line >setWifiEnabledDialogue(Z)Z and under it the >setWifiEnabled(Z)Z, you must edit out the dialogue to keep it from erroing on the Nexus.


Up to now you have the code in place for this all to work, but you don't have the code in place to actually display the widget. Back out of the /quickpanel/ folder in file explorer and you should be in the /statusbar/ folder. Look for the smali file statusbarservice.smali

Search for the line .method private makeStatusBarView(Landroid/content/Context;)V.

Mod the first line to look like this:

Code:
.locals 12
    .parameter "context"

    .prologue
    const/4 v11, 0x0
	
    const v10, 0x7f09000d

    const/4 v9, 0x0

    const/16 v8, 0x8

then your going to scroll down if your using notepad++ you'll look for line #776, you need to add in this line of code from the i9000

Code:
    .line 371
    const v6, 0x7f030006

    invoke-static {p1, v6, v9}, Landroid/view/View;->inflate(Landroid/content/Context;ILandroid/view/ViewGroup;)Landroid/view/View;

    move-result-object v5

    check-cast v5, Lcom/android/systemui/statusbar/quickpanel/QuickSettingsView;

    .line 373
    .local v5, qsv:Lcom/android/systemui/statusbar/quickpanel/QuickSettingsView;
    iget-object v6, p0, Lcom/android/systemui/statusbar/StatusBarService;->mExpandedView:Lcom/android/systemui/statusbar/ExpandedView;

    invoke-virtual {v6, v5, v11}, Lcom/android/systemui/statusbar/ExpandedView;->addView(Landroid/view/View;I)V

    .line 386
    return-void
.end method

search for the same code inside the statusbarservice.smali from the i9000 source and you'll notice some changes like the last line invoke-virtual{v6, v5, v11} we can't use the same values as the i9000 because there is more code in that file than we need at the moment in the Nexus, so I had to figure out what numbers were compatible to both the phones. Also take note of this line
.line 371
const v6, 0x7f030006
This is calling an XML file into view that controls how the quickpanel looks on your phone. The number 0x7f03006 may very it depends on when you added the quickpanel items into public.xml, what value you gave the item quickpanelsettings. Quick panel settings is an xml file that can be found in the res/layout/ of the i9000 source systemui.apk and must be transferred over to the Nexus S systemui.apk res/layout/ as well.

This is all a broad guide to get you started, if you need more assistance, don't PM me, post here so everyone can learn together.

Here are all the source files from the i9000 and the properly modded files of the Nexus Systemui.apk
QuickPanel.zip



snap20110522_092919.png
 
Last edited:

decalex

Senior Member
Apr 21, 2009
3,101
1,441
Boston, MA
Would the help you're looking for be concurrent with the status bar issues being worked out in cm7?

Sent from my Nexus S 4G using Tapatalk
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
Have no clue tbh

I'm leaning toward the smali not calling the r.layout.quick_panel_settings.xml is it

Sent from my SPH-D700 using Tapatalk
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
Looks like the framework.jar is going to have to be modded to accomplish this. My eyes are bleeding looking all this smali code but I did find one little snippet of code in the framework classes.dex located in com/android/internal/statusbar/
StatusBarNotification.smali

Code:
.method public isMiniCon()Z
    .registers 2

    .prologue
    .line 126
    iget-object v0, p0, Lcom/android/internal/statusbar/StatusBarNotification;->notification:Landroid/app/Notification;

    iget v0, v0, Landroid/app/Notification;->twQuickPanelEvent:I

    and-int/lit8 v0, v0, 0x1f

    if-eqz v0, :cond_a

    const/4 v0, 0x1

    :goto_9
    return v0

    :cond_a
    const/4 v0, 0x0

    goto :goto_9
.end method



I incorporated this into our framework.jar recompiled and flashed. No display in the status bar still but no errors at all from the phone. I'm getting there but have to head to work now
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
I know what you mean, sometimes you need to step back for a bit. Not sure where you're at on it but I'd be glad to have a look.

I'll make you a zip matter of fact pm your email and I'll invite you in my dropbox share to centralize the work. I'll add in a txt change log of what files are modded tell you where I'm stuck, need to track down quick panel container its referenced in id and public

Sent from my Nexus S 4G using Tapatalk
 

raiderep

Senior Member
Feb 4, 2010
1,527
265
Eureka, CA
I'll make you a zip matter of fact pm your email and I'll invite you in my dropbox share to centralize the work. I'll add in a txt change log of what files are modded tell you where I'm stuck, need to track down quick panel container its referenced in id and public

Sent from my Nexus S 4G using Tapatalk

pm ur way...

Sent from my Nexus S 4G using XDA Premium App
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
Quick question, when you are done.do you think this would work on a nexus s i9100 t? The non 4g version?

I'm sure you'll have to mod the files to match. It won't hurt to flash it and test but you'll have to compare the public.xml hex codes, the smali hex values inthe quick panel smali files.

Sent from my Nexus S 4G using Tapatalk
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
Progress update:

I'm am definitely on the verge of a release. I was hoping to contain all the code right inside the SystemUi.apk and there is still a slim chance I can mod the smali in there to speak with our framework.jar right. If not you'll have to flash SystemUi.apk and a modded framework.jar. Porting this to the non 4g version should be no harder than this was. I'm not going to port it, however I'll help out anyone who is willing to each step of the way. What works, auto rotation is done, works on and off. Gps is done, works just fine. Sound works 100%. Bluetooth, and wifi; however, do not work. Bluetooth turns on and off but the icon jumps over 1 slot and covers up the gps icon. You can then click the gps icon and get it to return to a gps image but I need to work this out. Wifi, don't work at all. It force closes the entire SystemUi.apk and you loose your status bar. I was able to get some good clean logcats and know where all the issues are located. It's only a matter of time to get this 100%. Now the last thing which is non important and will only take a second, is the length of the widget taking up all the real estate. That will be worked out as well.


snap20110524_184029.png
snap20110524_184017.png
 

suomaf

Senior Member
Progress update:

.. Porting this to the non 4g version should be no harder than this was. I'm not going to port it, however I'll help out anyone who is willing to each step of the way....

I would like to have a go at it, but I got no (ZERO/NADA/KAPUT) experience with this at all. I am the sort that believes in learn by doing however, if you are willing to help out, I could always do the grunt work. I have done a few android development tutorials but I don't think that they will help in this.
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
Very nice progress on this, I'm sure you'll get it done for us ;)

I'm trying my ass off I'm using smali compiled for the i9000 sgs, and the handling of bluetooth and wifi are the only two settings that are different however searching through the decompiled frameworks.jar from both I'm just not seeing it.

Sent from my Nexus S 4G using Tapatalk
 

dreamsforgotten

Senior Member
May 4, 2010
5,076
2,522
Louisiana
I would like to have a go at it, but I got no (ZERO/NADA/KAPUT) experience with this at all. I am the sort that believes in learn by doing however, if you are willing to help out, I could always do the grunt work. I have done a few android development tutorials but I don't think that they will help in this.

You can do it with my help you just have to edit what I tell you so far its not too much to edit to point to our phones its hours of searching for the java files that the app is using. When its done there is no searching left I just show you the files. You have to edit public only cause your phone don't have 4g hex codes. Its not hard when you have a guide to do it.

Sent from my Nexus S 4G using Tapatalk
 

Top Liked Posts

  • There are no posts matching your filters.
  • 9
    I'm editing this thread to now be a guide on how I was able port the QP from the i9000.

    Here's how it was ported:
    First I downloaded the i9000's (SGS) stock deodexed Systemui.apk and decompiled
    Next I decompiled the SystemUI.apk from the Nexus S in apk manager 4.7 (4.9 gave me issues when attempting to recompile)

    Once you decompile the SystemUI.apk from the i9000, navigate to out/smali/com/android/systemui/statusbar

    You'll notice a folder in there called quickpanel. Open the same folder on the decompiled Nexus systemui.apk and copy the entire quickpanel folder to the Nexus. Now you have to edit all the xmls in the res folder, start with status bar expanded.xml in the res/layout. Then ids.xml, then strings.xml, then public.xml in your res/values folder. Basically your going to add in every value from the i9000 that starts with "quickpanel". The public is a doozy, you have to assign the new values their own unique hex value. You should really be familiar with the hex naming scheme in public before attempting this, it's easy to screw up but worse case scenario is it won't compile for you. The status_bar_expanded in the layout folder, you only want to add the top line to your file don't overwrite any of the xml files from the i9000, only merge the pieces of code that call the widget into display.


    Next you have to move on to the smali code. Navigate to the decompiled folder res/values/ from both phones and open public.xml. After, navigate to /out/smali/com/android/systemui/statusbar/quickpanel/ from both phones, and open the autorotationsettingbutton.smali. What your going to be looking for first, is the hex codes that appear in public.xml.

    Code:
    .line 67
        .local v2, rootView:Landroid/view/View;
        const v5, 0x7f090023
    Code:
        .line 68
        .local v0, icon:Landroid/widget/ImageView;
        const v5, 0x7f090025
    Code:
    .line 82
        return-void
    
        .line 72
        :pswitch_0
        const v1, 0x7f020087
    
        .line 73
        const v4, 0x7f020085
    
        .line 74
        goto :goto_0
    
        .line 76
        :pswitch_1
        const v1, 0x7f020086
    
        .line 77
        const v4, 0x7f020084
    
        goto :goto_0

    Each of these hex codes "0x7f0200xx" match up to a drawable in publix.xml. Start with the i9000 systemui.apk and see what picture it's pointing to by searching the number in the public.xml, then move over to the Nexus S systemui.apk and open the public (That you already modded and added the values in for the quickpanel items) and match to the name of the drawable in the i9000, to the name in public from Nexus, then copy the New hex code from the Nexus public to the autorotationsettingbutton.smali. This way your new smali file will be pointing to the correct drawable in the Nexus systemui.apk. Note all the way at the bottom of the smali file in both phones is 1 more hex value to change. Just scroll down to almost the bottom and look for another number that looks like the previous ones. Change that final hex and save your work. Now open all the other files ie bluetoothsettingsbutton gpssettingsbutton soundsettingsbutton, wifisettingsbutoon. Repeat the same steps for changing the hex values for picture display.

    Now open the wifisettingsbutton.smali and we have to mod the code since our phones don't access the wifi the same.

    Code:
        .line 63
        nop
    
        :pswitch_data_0
        .packed-switch 0x0
            :pswitch_2
            :pswitch_1
            :pswitch_2
            :pswitch_0
    	[B]:pswitch_1[/B]
        .end packed-switch
    .end method
    In this code in wifisettingsbutton, the final line :pswitch_1 is added, it's not present in the original. You must adjust this value.


    Code:
        .line 123
        iget-object v1, p0, Lcom/android/systemui/statusbar/quickpanel/WifiSettingButton;->mWifiManager:Landroid/net/wifi/WifiManager;
    
        const/4 v2, 0x1
    
        invoke-virtual {v1, v2}, Landroid/net/wifi/WifiManager;->setWifiEnabledDialog(Z)Z
    
        goto :goto_0
    .end method


    Code:
        .line 123
        iget-object v1, p0, Lcom/android/systemui/statusbar/quickpanel/WifiSettingButton;->mWifiManager:Landroid/net/wifi/WifiManager;
    
        const/4 v2, 0x1
    
        invoke-virtual {v1, v2}, Landroid/net/wifi/WifiManager;->setWifiEnabled(Z)Z
    
        goto :goto_0
    .end method
    In the above two codes, the first is the i9000 wifisettingsbutton, notice the line >setWifiEnabledDialogue(Z)Z and under it the >setWifiEnabled(Z)Z, you must edit out the dialogue to keep it from erroing on the Nexus.


    Up to now you have the code in place for this all to work, but you don't have the code in place to actually display the widget. Back out of the /quickpanel/ folder in file explorer and you should be in the /statusbar/ folder. Look for the smali file statusbarservice.smali

    Search for the line .method private makeStatusBarView(Landroid/content/Context;)V.

    Mod the first line to look like this:

    Code:
    .locals 12
        .parameter "context"
    
        .prologue
        const/4 v11, 0x0
    	
        const v10, 0x7f09000d
    
        const/4 v9, 0x0
    
        const/16 v8, 0x8

    then your going to scroll down if your using notepad++ you'll look for line #776, you need to add in this line of code from the i9000

    Code:
        .line 371
        const v6, 0x7f030006
    
        invoke-static {p1, v6, v9}, Landroid/view/View;->inflate(Landroid/content/Context;ILandroid/view/ViewGroup;)Landroid/view/View;
    
        move-result-object v5
    
        check-cast v5, Lcom/android/systemui/statusbar/quickpanel/QuickSettingsView;
    
        .line 373
        .local v5, qsv:Lcom/android/systemui/statusbar/quickpanel/QuickSettingsView;
        iget-object v6, p0, Lcom/android/systemui/statusbar/StatusBarService;->mExpandedView:Lcom/android/systemui/statusbar/ExpandedView;
    
        invoke-virtual {v6, v5, v11}, Lcom/android/systemui/statusbar/ExpandedView;->addView(Landroid/view/View;I)V
    
        .line 386
        return-void
    .end method

    search for the same code inside the statusbarservice.smali from the i9000 source and you'll notice some changes like the last line invoke-virtual{v6, v5, v11} we can't use the same values as the i9000 because there is more code in that file than we need at the moment in the Nexus, so I had to figure out what numbers were compatible to both the phones. Also take note of this line
    .line 371
    const v6, 0x7f030006
    This is calling an XML file into view that controls how the quickpanel looks on your phone. The number 0x7f03006 may very it depends on when you added the quickpanel items into public.xml, what value you gave the item quickpanelsettings. Quick panel settings is an xml file that can be found in the res/layout/ of the i9000 source systemui.apk and must be transferred over to the Nexus S systemui.apk res/layout/ as well.

    This is all a broad guide to get you started, if you need more assistance, don't PM me, post here so everyone can learn together.

    Here are all the source files from the i9000 and the properly modded files of the Nexus Systemui.apk
    QuickPanel.zip



    snap20110522_092919.png
    2
    You are more than welcome, I try my best to help everyone cause most everything I learned I taught myself. This project was my first programming experience. I had no prior knowledge, I just decompiled and stared at the code between the two phones until I could see anomalies and understand what needed to be ported to AOSP. Resource ID's are by far the hugest PITA with the whole process so to help you make that easier in the future, you might want to look into this app. I found it I after I had ported the quickpanel and most of the lockscreens, this would have saved me months of work:
    http://forum.xda-developers.com/showthread.php?t=945637

    You can auto-generate all of the resources in public.xml with the tools you already have.

    If you enter in your string.xml and drawables *before* doing any smali edits, do NOT touch the public.xml, then recompile your entire APK (without the smali edits). Make sure to delete both resources.arsc and classes.dex and anything else you changed (but not public.xml) from the "keep" folder if using apkmanager, so they get rebuilt. If you don't rebuild your classes.dex it the resource ID's might mismatch.

    Once you've re-compiled the APK, then DECOMPILE it again, and look at your public.xml. It will have auto-generated appropriate resource ID's for each and every new resource you added. Now you can go on editing the Smali using those resource Id's.
    1
    Gonna take alot of reading, there are methods called the ns doesn't have easy fix is add them in the framework.jar, but
    I'm taking the long route so we can just flash and theme the system ui apk
    Sent from my Nexus S 4G using Tapatalk
    1
    Theoretically, yes, but the space would still be taken up (I think)... A layout edit would be required to fix that, as well as editing the background image. No big deal I guess, I was able to make the carrier text 1/2 size as one of my (many) projects today....

    Just erase the call to the id that's all

    Sent from my NS4G Pool Party using Tapatalk!