On Friday, August 3, 2012 3:27:12 AM UTC-7, Mark Murphy (a Commons Guy) 
wrote:
>
> On Fri, Aug 3, 2012 at 5:08 AM, thejaswi s <.......> wrote: 
> > Data usage per application. Based on uid I can take third party 
> application 
> > data usage from my app using 'TrafficStats' API. But this will get reset 
> in 
> > sertain condition. So is there any other way to take data usage per 
> > application. 
>
> No. 
>
>
You could read from:

        case TX:
            sprintf(tcp_filename, "/proc/uid_stat/%d/tcp_snd_pkt", uid);
            sprintf(udp_filename, "/proc/uid_stat/%d/udp_snd_pkt", uid);
            break;
        case RX:
            sprintf(tcp_filename, "/proc/uid_stat/%d/tcp_rcv_pkt", uid);
            sprintf(udp_filename, "/proc/uid_stat/%d/udp_rcv_pkt", uid);


in the same way that 
http://source-android.frandroid.com/frameworks/base/core/jni/android_net_TrafficStats.cpp
but odds are you don't want to, as it only works as a snapshot of live PIDs 
(which you have to match to UIDs to
packages) and you don't have a good trigger about when the pids will start 
or stop (unlike the public API which
the ActivityManager can tell to update before it shuts down a process) 
which will be probably more difficult to
solve than looking for the cases where the public API resets, and given 
that the issue you are probably dealing
with is related to this bug:

http://code.google.com/p/android/issues/detail?id=19938

the root cause of which isn't happening  in the .cpp -> .java framework 
stuff but the data that fills the /proc filesystem
values (so even this alternate method will have the same issue) all that 
extra work will be without value.

Once that bug is fixed, the only reset should be on reboot, so make a 
broadcast receiver and give it a filter like:

        IntentFilter intentf = new IntentFilter();
        intentf.addAction(Intent.ACTION_REBOOT);
        intentf.addAction(Intent.ACTION_SHUTDOWN);
        intentf.addAction("android.intent.action.QUICKBOOT_POWEROFF");

so you can grab the TrafficStats with it's last values before it gets reset 
on the next boot.
 

      Dan S.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to