Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[NEW] Stock Data Usage Monitor in Android 2.x

OP tweakradje

18th September 2012, 11:38 AM   |  #1  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Decided to start a new thread on this subject since I could not find any correct info about it.
I decompiled phone.apk to check wether there was a data usage monitor in there. If you use Anycut you can select it (from of Phone.apk). Only it looks like it is disabled. Carriers wish? The data usage monitor in Android 2.x (like in ICS) might be useful

Anyway, after decompiling Phone.apk and searching for "datausage" there it was.

Files that are interesting are in com/android/phone:
- DataUsageListener.smali
- DataUsage.smali
- Settings.smali

com/android/phone/DataUsageListener
android/net/ThrottleManager

This answers a question I already had for a while: /data/system/throttle with temp file like:
1:6:0:0:0:0:0:0:0:0:0:0:0:0:2:1347228000000:134982 0000000

In Settings.smali there is:

Code:
    :cond_a
    const-string v6, "throttle"

    invoke-virtual {p0, v6}, Lcom/android/phone/Settings;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Landroid/net/ThrottleManager;

    .line 473
    .local v5, tm:Landroid/net/ThrottleManager;
    new-instance v6, Lcom/android/phone/DataUsageListener;

    iget-object v7, p0, Lcom/android/phone/Settings;->mButtonDataUsage:Landroid/preference/Preference;

    invoke-direct {v6, p0, v7, v3}, Lcom/android/phone/DataUsageListener;-><init>(Landroid/content/Context;Landroid/preference/Preference;Landroid/preference/PreferenceScreen;)V

    iput-object v6, p0, Lcom/android/phone/Settings;->mDataUsageListener:Lcom/android/phone/DataUsageListener;

    .line 475
    const-string v6, "XEC"

    sget-object v7, Lcom/android/phone/Settings;->salesCode:Ljava/lang/String;

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

    move-result v6
and a ref to android.settings.secure:

Code:
/**
3936          * The bandwidth throttle polling freqency in seconds
3937          * @hide
3938          */
3939         public static final String THROTTLE_POLLING_SEC = "throttle_polling_sec";
3940 
3941         /**
3942          * The bandwidth throttle threshold (long)
3943          * @hide
3944          */
3945         public static final String THROTTLE_THRESHOLD_BYTES = "throttle_threshold_bytes";
3946 
3947         /**
3948          * The bandwidth throttle value (kbps)
3949          * @hide
3950          */
3951         public static final String THROTTLE_VALUE_KBITSPS = "throttle_value_kbitsps";
3952 
3953         /**
3954          * The bandwidth throttle reset calendar day (1-28)
3955          * @hide
3956          */
3957         public static final String THROTTLE_RESET_DAY = "throttle_reset_day";
3958 
3959         /**
3960          * The throttling notifications we should send
3961          * @hide
3962          */
3963         public static final String THROTTLE_NOTIFICATION_TYPE = "throttle_notification_type";
3964 
3965         /**
3966          * Help URI for data throttling policy
3967          * @hide
3968          */
3969         public static final String THROTTLE_HELP_URI = "throttle_help_uri";
3970 
3971         /**
3972          * The length of time in Sec that we allow our notion of NTP time
3973          * to be cached before we refresh it
3974          * @hide
3975          */
3976         public static final String THROTTLE_MAX_NTP_CACHE_AGE_SEC =
3977                 "throttle_max_ntp_cache_age_sec";
3978 
3979         /**
3980          * The maximum size, in bytes, of a download that the download manager will transfer over
3981          * a non-wifi connection.
3982          * @hide
3983          */
3984         public static final String DOWNLOAD_MAX_BYTES_OVER_MOBILE =
3985                 "download_manager_max_bytes_over_mobile";
3986 
3987         /**
3988          * The recommended maximum size, in bytes, of a download that the download manager should
3989          * transfer over a non-wifi connection. Over this size, the use will be warned, but will
3990          * have the option to start the download over the mobile connection anyway.
3991          * @hide
3992          */
3993         public static final String DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE =
3994                 "download_manager_recommended_max_bytes_over_mobile";
3995


This is W.I.P....... will come back soon

Cheers
Last edited by tweakradje; 19th September 2012 at 09:48 PM.
The Following 18 Users Say Thank You to tweakradje For This Useful Post: [ View ]
18th September 2012, 08:29 PM   |  #2  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Ok, when listing all services on my 2.3.6 stock rom I see that throttle service is running:

# service list
...
24 throttle: [android.net.IThrottleManager]
...

In logcat I see the throttle service starting:
I/SystemServer( 179): Throttle Service
I/SystemServer( 179): throttleF systemReady

So now I will try to add some records to the secure db with sqlite3 for throttle.


EDIT: seems like throttle has nothing todo with data usage reporting. Only with
narrowing your bandwith when a certain amount of data is reached.
http://forum.xda-developers.com/show...ification+type
Perhaps DataUsageListener hooks into that service?
Last edited by tweakradje; 18th September 2012 at 09:50 PM.
The Following User Says Thank You to tweakradje For This Useful Post: [ View ]
18th September 2012, 11:11 PM   |  #3  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Ok now I have entered some values for throttling into the secure table of android.settings

(ref: https://www.codeaurora.org/git/proje...leService.java)

### check current throttle settings
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "SELECT * FROM secure WHERE name like 'throttle_%';"
Quote:

27|throttle_reset_day|10
540|throttle_polling_sec|60
541|throttle_threshold_bytes|0
542|throttle_notification_type|2
543|throttle_value_kbitsps|100000000

These are the sqlite3 (must be rooted and sqlite3 installed) commands to get them into th db. These are test values. 60 sec sampling is too fast. Use 3600 for every hour.

### interval in secs for measuring kbytes used
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) VALUES ('throttle_polling_sec', '60');"

### what is the limit in bytes after throttle_reset_day before start throttling 0=no throttle, don't show in phone settings
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) VALUES ('throttle_threshold_bytes', '0');"

### do you want a notification (not the provider)
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) VALUES ('throttle_notification_type', '2');"

### the new kbit/s is threshold is reached in the period (throttle_reset_day) 0=not measuring data usage?
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "INSERT INTO secure (name, value) VALUES ('throttle_value_kbitsps', '100000000');"

If you want to update one of these values use:
## setting throttle kb to 1 Mb, it should start to throttle and give me a warning
sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='1024000' WHERE name='throttle_threshold_bytes';"

Quote:

27|throttle_reset_day|10
540|throttle_polling_sec|60
541|throttle_threshold_bytes|1024000
542|throttle_notification_type|2
543|throttle_value_kbitsps|100000000

Now I have rebooted my phone and throttling samples should provide data for datausage?

Cheers
Last edited by tweakradje; 20th September 2012 at 09:06 PM.
The Following User Says Thank You to tweakradje For This Useful Post: [ View ]
18th September 2012, 11:39 PM   |  #4  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Cool
I know I am talking to myself right now but hey.

How about this guys? Some progress. See screenshot.
Now only need to set the proper network adapter I guess.

Quote:

config_datause_iface
public static final int config_datause_ifaceThe default iface on which to monitor data use

Code:
# netcfg
netcfg
lo       UP    127.0.0.1       255.0.0.0       0x00000049
dummy0   DOWN  0.0.0.0         0.0.0.0         0x00000082
rmnet0   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet1   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet2   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet3   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet4   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet5   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet6   DOWN  0.0.0.0         0.0.0.0         0x00001002
rmnet7   DOWN  0.0.0.0         0.0.0.0         0x00001002
usb0     DOWN  0.0.0.0         0.0.0.0         0x00001002
tunl0    DOWN  0.0.0.0         0.0.0.0         0x00000080
gre0     DOWN  0.0.0.0         0.0.0.0         0x00000080
sit0     DOWN  0.0.0.0         0.0.0.0         0x00000080
wlan0    DOWN  0.0.0.0         0.0.0.0         0x00001002
pdp0     UP    188.90.76.237   255.255.255.0   0x000010d1
logcat says:
Quote:

D/ThrottleService( 179): onPolicyChanged testing=false, period=60, threshold=1024000, value=100000000, resetDay=10, noteType=2, maxNtpCacheAge=86400

D/ThrottleService( 179): onResetAlarm - last period had 0 bytes read and 0 written

Not bad I would say

EDIT: config_datause_iface seems to be bolted down in the framework-res.apk (rmnet0). Will look at it later.


Cheers
Attached Images
File Type: jpg Data_Usage_on_stock_android_2.3.jpg - [Click for QR Code] (100.0 KB, 946 views)
Last edited by tweakradje; 19th September 2012 at 09:51 PM. Reason: readability
The Following 4 Users Say Thank You to tweakradje For This Useful Post: [ View ]
19th September 2012, 10:22 AM   |  #5  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
In framework-res\res\values\strings.xml there is this line:

<string name="config_datause_iface">rmnet0</string>

change it to

<string name="config_datause_iface">pdp0</string>

and recompile the framework-res.apk and overwrite it in /system/framework folder.

Other default values in framework-res\res\values\integers.xml
Quote:

<integer name="config_datause_polling_period_sec">600</integer>
<integer name="config_datause_threshold_bytes">0</integer>
<integer name="config_datause_throttle_kbitsps">300</integer>
<integer name="config_datause_notification_type">2</integer>

Cheers
The Following 3 Users Say Thank You to tweakradje For This Useful Post: [ View ]
19th September 2012, 12:13 PM   |  #6  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Red face IT WORKS !!!
After changing the framework-res.apk as described above the counter is running

From logd:

D/ThrottleService( 181): onPollAlarm - roaming =false, read =263, written =52, new total =21056

Only I cannot select it, phone crashes (logcat):
Quote:

W/dalvikvm( 1377): threadid=1: thread exiting with uncaught exception (group=0x40018578)
E/AndroidRuntime( 1377): FATAL EXCEPTION: main
E/AndroidRuntime( 1377): java.lang.RuntimeException: Unable to resume activity {com.android.phone/com.android.phone.Data
Usage}: java.util.MissingFormatArgumentException: Format specifier: 4$d
E/AndroidRuntime( 1377): at android.app.ActivityThread.performResumeActivity(A ctivityThread.java:2124)
E/AndroidRuntime( 1377): at android.app.ActivityThread.handleResumeActivity(Ac tivityThread.java:2139)
E/AndroidRuntime( 1377): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:1672)
E/AndroidRuntime( 1377): at android.app.ActivityThread.access$1500(ActivityThr ead.java:117)
E/AndroidRuntime( 1377): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:935)
E/AndroidRuntime( 1377): at android.os.Handler.dispatchMessage(Handler.java:99 )
E/AndroidRuntime( 1377): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1377): at android.app.ActivityThread.main(ActivityThread.jav a:3687)
E/AndroidRuntime( 1377): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1377): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1377): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:867)
E/AndroidRuntime( 1377): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:625)
E/AndroidRuntime( 1377): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1377): Caused by: java.util.MissingFormatArgumentException: Format specifier: 4$d
E/AndroidRuntime( 1377): at java.util.Formatter.getArgument(Formatter.java:113 1)
E/AndroidRuntime( 1377): at java.util.Formatter.doFormat(Formatter.java:1096)
E/AndroidRuntime( 1377): at java.util.Formatter.format(Formatter.java:1062)
E/AndroidRuntime( 1377): at java.util.Formatter.format(Formatter.java:1031)
E/AndroidRuntime( 1377): at java.lang.String.format(String.java:2177)
E/AndroidRuntime( 1377): at android.content.res.Resources.getString(Resources. java:283)
E/AndroidRuntime( 1377): at android.content.Context.getString(Context.java:196 )
E/AndroidRuntime( 1377): at com.android.phone.DataUsageListener.updateUI(DataU sageListener.java:180)
E/AndroidRuntime( 1377): at com.android.phone.DataUsageListener.updatePolicy(D ataUsageListener.java:139)
E/AndroidRuntime( 1377): at com.android.phone.DataUsageListener.resume(DataUsa geListener.java:110)
E/AndroidRuntime( 1377): at com.android.phone.DataUsage.onResume(DataUsage.jav a:74)
E/AndroidRuntime( 1377): at android.app.Instrumentation.callActivityOnResume(I nstrumentation.java:1150)
E/AndroidRuntime( 1377): at android.app.Activity.performResume(Activity.java:3 832)
E/AndroidRuntime( 1377): at android.app.ActivityThread.performResumeActivity(A ctivityThread.java:2114)
E/AndroidRuntime( 1377): ... 12 more
E/ ( 181): Dumpstate > /data/log/dumpstate_app_error

The /data/system/throttle/-2065243490 file now looks like this:
1:6:2295795:4567981:0:0:0:0:301613:702561:0:0:0:0: 1:1346450400000:1349042400000
The /data/system/throttle/temp file remains the same:
1:6:0:0:0:0:0:0:0:0:0:0:0:0:2:1347228000000:134982 0000000

Cheers

ps: changed stock framework-res.apk for Galaxy Ace (S5830 - S5830XWKTM) attached.
Attached Images
File Type: jpg Data_Usage_01.jpg - [Click for QR Code] (97.7 KB, 686 views)
File Type: jpg data_Usage_02.jpg - [Click for QR Code] (88.0 KB, 609 views)
Attached Files
File Type: apk framework-res.apk - [Click for QR Code] (3.39 MB, 137 views)
Last edited by tweakradje; 21st September 2012 at 10:48 AM.
The Following 5 Users Say Thank You to tweakradje For This Useful Post: [ View ]
23rd September 2012, 11:20 AM   |  #7  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Question
Is there someone out there that can help with the last problem? If I click the DataUsage button ithe phone service crash/restarts?

Code:
E/AndroidRuntime( 1377): java.lang.RuntimeException: Unable to resume activity {com.android.phone/com.android.phone.Data
Usage}: java.util.MissingFormatArgumentException: Format specifier: 4$d
Cheers
The Following 2 Users Say Thank You to tweakradje For This Useful Post: [ View ]
28th September 2012, 08:58 AM   |  #8  
stranxk's Avatar
Senior Member
Flag Veracruz
Thanks Meter: 31
 
102 posts
Join Date:Joined: Jun 2011
More
You seem to be doing an awesone job for gingerbread devices, keep going mate, i would like something like this for galaxy s advance in a near future.
30th September 2012, 09:42 PM   |  #9  
LorD ClockaN's Avatar
Recognized Developer
Flag Veli Losinj
Thanks Meter: 27,658
 
13,337 posts
Join Date:Joined: Sep 2008
Donate to Me
More
Little info.. when we first built ICS for Desire HD, data counter wasn't working..
there was a lot to be done to the kernel regarding XT_quota and similar stuff..

and only after that the counter started working fine..
so don't kill your self with fwb code, maybe the kernel doesn't support it.. I know Desire HD's GB kernel didn't!
1st October 2012, 09:56 AM   |  #10  
OP Senior Member
Flag Android
Thanks Meter: 285
 
623 posts
Join Date:Joined: Mar 2005
Thx for your support guys.

The mobile data monitor part works ok. It even resets fine this morning to 0 Mb on day 1 of the month.
It is only the GUI part with the settings that FC the phone service. May indeed be missing a system variable.

The strange part is that if I disable the monitor as it was, the settings GUI does load but is greyed out (via custom shortcut in launcher).

See second image that show the screen that should load.

Any ideas?

Cheers
Attached Images
File Type: jpg Data_Usage_03.jpg - [Click for QR Code] (90.7 KB, 500 views)
File Type: jpg Data_Usage_04.jpg - [Click for QR Code] (52.4 KB, 443 views)

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes