FORUMS

HTC’s New Ad Campaign And What It Really Means

HTC has just released three new blind test adverts comparing app loading … more

XDA Picks: Best Apps of the Week (June 27 – July 4)

Apps are at the front and center of any smartphone experience, and with over a … more

HTC One M9 Developer Edition Android 5.1 OTA

The Developer Edition of the HTC One M9 is receiving an over-the-air update to Android 5.1. … more

Index Project For XDA Device Subforums

Another ambitious project from the collaborative efforts of Recognized Contributors and Forum … more

[GUIDE] [JAVA to SMALI] Create SystemUI.apk external settings app - v1.1 - 13/04/14

3,523 posts
Thanks Meter: 13,360
 
By serajr, Recognized Developer / Recognized Themer on 9th April 2014, 08:44 PM
Post Reply Subscribe to Thread Email Thread
9th February 2015, 07:41 AM |#41  
DihaX's Avatar
Member
Flag Sukabumi
Thanks Meter: 58
 
Donate to Me
More
Quote:

--------------------------------------------------------------------------
|Mon 02/09/2015 -- 14:31:04.35|
--------------------------------------------------------------------------
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) Client VM (build 25.31-b07, mixed mode, sharing)
I: Baksmaling...
I: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCD ecoder.java:56)
at brut.androlib.res.AndrolibResources.getResPackages FromApk(AndrolibResources.java:491)
at brut.androlib.res.AndrolibResources.loadMainPkg(An drolibResources.java:74)
at brut.androlib.res.AndrolibResources.getResTable(An drolibResources.java:66)
at brut.androlib.Androlib.getResTable(Androlib.java:5 0)
at brut.androlib.ApkDecoder.getResTable(ApkDecoder.ja va:189)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:11 4)
at brut.apktool.Main.cmdDecode(Main.java:146)
at brut.apktool.Main.main(Main.java:77)
Caused by: java.io.IOException: Expected: 0x001c0001, got: 0x00000000
at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.j ava:48)
at brut.androlib.res.decoder.StringBlock.read(StringB lock.java:44)
at brut.androlib.res.decoder.ARSCDecoder.readPackage( ARSCDecoder.java:102)
at brut.androlib.res.decoder.ARSCDecoder.readTable(AR SCDecoder.java:83)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCD ecoder.java:49)
... 8 more

Fixed problem in android sdk
Very Awesome Guide
Last edited by DihaX; 10th February 2015 at 09:13 AM.
 
 
18th June 2015, 11:37 AM |#42  
Senior Member
Flag CoochBehar
Thanks Meter: 865
 
More
Quote:
Originally Posted by serajr

Here I'm gonna try to show you other mods you can try!!


Change Battery Icons Guide



1. First you need to put new battery resources within your decompiled SystemUI.apk


2. Go to \res\drawable folder and look for:
Code:
stat_sys_battery.xml
stat_sys_battery_charge.xml

3. Found, these two xml files are where all respective png's are mapped!
Let's name them as our "default" preference value (gonna be 0), so we do nothing with them


4. While at \res\drawable folder, create (CTRL+C and CTRL+V) two new files based on above ones, you will get (in red):
Code:
stat_sys_battery.xml
stat_sys_battery_1.xml
stat_sys_battery_charge.xml
stat_sys_battery_charge_1.xml
New red files gonna be our value 1 preference


5. By editing new red files above, you will get something like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<level-list
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/stat_sys_battery_0" android:maxLevel="4" />
    <item android:drawable="@drawable/stat_sys_battery_15" android:maxLevel="15" />
    <item android:drawable="@drawable/stat_sys_battery_28" android:maxLevel="35" />
    <item android:drawable="@drawable/stat_sys_battery_43" android:maxLevel="49" />
    <item android:drawable="@drawable/stat_sys_battery_57" android:maxLevel="60" />
    <item android:drawable="@drawable/stat_sys_battery_71" android:maxLevel="75" />
    <item android:drawable="@drawable/stat_sys_battery_85" android:maxLevel="90" />
    <item android:drawable="@drawable/stat_sys_battery_100" android:maxLevel="100" />
</level-list>

6. Here you need to change the drawables mapping to your new battery png's you put within your \res\drawable\YOUR_DENSITY folder:
E.g.: New png's have _1 suffix!!
Code:
<?xml version="1.0" encoding="utf-8"?>
<level-list
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/stat_sys_battery_0_1" android:maxLevel="4" />
    <item android:drawable="@drawable/stat_sys_battery_15_1" android:maxLevel="15" />
    <item android:drawable="@drawable/stat_sys_battery_28_1" android:maxLevel="35" />
    <item android:drawable="@drawable/stat_sys_battery_43_1" android:maxLevel="49" />
    <item android:drawable="@drawable/stat_sys_battery_57_1" android:maxLevel="60" />
    <item android:drawable="@drawable/stat_sys_battery_71_1" android:maxLevel="75" />
    <item android:drawable="@drawable/stat_sys_battery_85_1" android:maxLevel="90" />
    <item android:drawable="@drawable/stat_sys_battery_100_1" android:maxLevel="100" />
</level-list>

7. Done with new resources!!!
Remember you can put as much as new ones you want, just change their suffix to next integer value!!!


Java

- New "clone" com.android.systemui.statusbar.policy package
- New "clone" BatteryController.java class with two new methods and all related comments there too
- Added into "clone" PhoneStatusBar.java the new handleStatusBarChangeBatteryIcons method and its "calls", take a look at:


Get new Eclipse Project from attachments!!


Smali

1. Get the newly built ExternalPreferences.apk from Eclipse project ( \bin folder )


2. Decompile it


3. Go to ExternalPreferences.apk decompiled folder: ...\smali\com\android\systemui\statusbar\phone\


4. Open PhoneStatusBar.smali

Now let's copy our new method from ExternalPreferences.apk (PhoneStatusBar.smali) file to SystemUI.apk (PhoneStatusBar.smali file)
By copying it you will get (in red):

Under # direct methods
Code:
# direct methods
.method private handleStatusBarChangeBatteryIcons()V
    .locals 9

    .prologue
    const/4 v8, 0x0

    .line 125
    iget-object v4, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mContext:Landroid/content/Context;

    const/4 v5, 0x0

    new-instance v6, Landroid/content/IntentFilter;

    const-string v7, "android.intent.action.BATTERY_CHANGED"

    invoke-direct {v6, v7}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

    invoke-virtual {v4, v5, v6}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

    move-result-object v0

    .line 126
    .local v0, getIntent:Landroid/content/Intent;
    const-string v4, "level"

    invoke-virtual {v0, v4, v8}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v2

    .line 127
    .local v2, level:I
    const-string v4, "plugged"

    invoke-virtual {v0, v4, v8}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

    move-result v3

    .line 131
    .local v3, plugged:I
    new-instance v1, Landroid/content/Intent;

    const-string v4, "android.intent.action.BATTERY_CHANGED"

    invoke-direct {v1, v4}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

    .line 132
    .local v1, intent:Landroid/content/Intent;
    const-string v4, "level"

    invoke-virtual {v1, v4, v2}, Landroid/content/Intent;->putExtra(Ljava/lang/String;I)Landroid/content/Intent;

    .line 133
    const-string v4, "plugged"

    invoke-virtual {v1, v4, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;I)Landroid/content/Intent;

    .line 134
    iget-object v4, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mContext:Landroid/content/Context;

    invoke-virtual {v4, v1}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V

    .line 136
    return-void
.end method

5. Also replace setupExternalSettingsObserver and externalPreferencesObserverCallback whole methods by the new ones


6. While on SystemUI.apk look for our last implemented method (from original guide, but now in blue) inside makeStatusBarView method, and add red lines
Code:
    .line 1005
    const-string v0, "com.sonymobile.notes.NEW_SKETCH"

    invoke-direct {p0, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->isAppInstalled(Ljava/lang/String;)Z

    move-result v0

    iput-boolean v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mRightVisible:Z
	
    .line 34
    invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->setupExternalSettingsObserver()V

    .line 37
    invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->handleStatusBarChangeClockToRed()V
	
    .line 40
    invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->handleStatusBarChangeBatteryIcons()V

    .line 1007
    iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

    return-object v0

    :cond_14
    move v1, v2

    .line 825
    goto/16 :goto_7

7. Go to ExternalPreferences.apk decompiled folder: ...\smali\com\android\systemui\statusbar\policy\


8. Open BatteryController.smali

Now let's copy our new methods from ExternalPreferences.apk (BatteryController.smali) file to SystemUI.apk (BatteryController.smali file)
By copying them you will get (in red):

Under # direct methods
Code:
# direct methods
.method private getStatSysBatteryChargeResId()I
    .locals 6

    .prologue
    .line 62
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    const-string v3, "stat_sys_battery_charge"

    const-string v4, "drawable"

    iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

    move-result v0

    .line 65
    .local v0, resId:I
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

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

    move-result-object v2

    const-string v3, "status_bar_change_battery_icons"

    const/4 v4, 0x0

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

    move-result v1

    .line 66
    .local v1, value:I
    packed-switch v1, :pswitch_data_0

    .line 77
    :goto_0
    return v0

    .line 71
    :pswitch_0
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    const-string v3, "stat_sys_battery_charge_1"

    const-string v4, "drawable"

    iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

    move-result v0

    goto :goto_0

    .line 66
    :pswitch_data_0
    .packed-switch 0x1
        :pswitch_0
    .end packed-switch
.end method

.method private getStatSysBatteryResId()I
    .locals 6

    .prologue
    .line 36
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    const-string v3, "stat_sys_battery"

    const-string v4, "drawable"

    iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

    move-result v0

    .line 39
    .local v0, resId:I
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

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

    move-result-object v2

    const-string v3, "status_bar_change_battery_icons"

    const/4 v4, 0x0

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

    move-result v1

    .line 40
    .local v1, value:I
    packed-switch v1, :pswitch_data_0

    .line 51
    :goto_0
    return v0

    .line 45
    :pswitch_0
    iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v2

    const-string v3, "stat_sys_battery_1"

    const-string v4, "drawable"

    iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

    invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

    move-result v0

    goto :goto_0

    .line 40
    :pswitch_data_0
    .packed-switch 0x1
        :pswitch_0
    .end packed-switch
.end method

9. While on SystemUI.apk BatteryController.smali file look for this method:
Code:
.method public onReceive(Landroid/content/Context;Landroid/content/Intent;)V

9. Found, now let's implement "calls" to our new "get" methods (in red)
Pay attention on v6 (in green), method must return as v6 (or the v? from your decompiled code)
Code:
.
.
.
    .line 117
    .end local v8           #plugType:I
    :cond_1
    :goto_1
    if-eqz v9, :cond_3

    const v6, 0x7f020130

    invoke-direct {p0}, Lcom/android/systemui/statusbar/policy/BatteryController;->getStatSysBatteryChargeResId()I

    move-result v6

    .line 120
    .local v6, icon:I
    :goto_2
    move-object/from16 v0, p0

    iget-object v13, v0, Lcom/android/systemui/statusbar/policy/BatteryController;->mIconViews:Ljava/util/ArrayList;

    invoke-virtual {v13}, Ljava/util/ArrayList;->size()I

    move-result v1
.
.
.


.
.
.
    .line 117
    .end local v8           #plugType:I
    :cond_3
    const v6, 0x7f020127
	
    invoke-direct {p0}, Lcom/android/systemui/statusbar/policy/BatteryController;->getStatSysBatteryResId()I

    move-result v6

    goto :goto_2

    .line 128
    .restart local v1       #N:I
    .restart local v4       #i:I
    .restart local v6       #icon:I
.
.
.
0x7f020130 is the hex value from original stat_sys_battery_charge resource (under SystemUI.apk public.xml)
0x7f020127 is the hex value from original stat_sys_battery resource (under SystemUI.apk public.xml)
Your values may differs!!!


10. Double check your changes, save everything, compile your modified SystemUI.apk and... done!!



Others soon...
.
.

No Words Just Simply Awesome Gonna try this
The Following User Says Thank You to ShadeSK For This Useful Post: [ View ]
Post Reply Subscribe to Thread

Tags
guide, java, serajr, smali, systemui
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes