TrafficStats : concerning Tx and Rx data consumption (getUidRx/TxBytes)

527 views Asked by At

time for me to appear ^^

Well, I'm kinda new into programming, but I grow fast ^^

I hope, I won't give you a headache with my English '-'

So I'm here to talk about the "TrafficStats" function, and specially about Rx.

In fact, actually I'm developing an android application, and in this i show the data consumption about this apps.

I'm using so the "getUidRxBytes" and "getUidTxBytes" So if I understand well in the android documentation, Tx is Transmitted so it's Upload (UL), and Rx is Received so it's Download (DL), right ? Sooo the data consumption should be the addition of both right (UL + DL = data consumption) ???

So I'm faced with a problem, before launching my app here's my data consumption for this app (in data usage option) :

Data usage before using app

As you can see I have 588 MB used

I launch my apps, I start a video in this apps, from dailymotion (calling the sdk of it), multiple time to have enough data consummed.

My apps with counters

It's appear I have 59.25 MB used in Tx and 122.08 MB used in Rx. (so it should be 181.33MB)

When I look back into the data consumption of this apps (like this) :

(Not allow to post more than 2 link so trust me :x)

It shows, in fact a difference (go up to 650MB) so a difference of 62 MB

SO it's appear to match only (with a little % error) with the data Tx (so UL)

I'm using a third "party"(that I can't tell you) who is giving me the data used into the app and it match too with the Tx only !

--> My question : Where did the Rx (so DL) data goes ??? Don't you think there is a problem with the Rx method ? (method or function ? xD) or into Tx as well because it should be Tx + Rx and not only Tx.

Annex : here is my code where i use the TrafficStats

public class youtube_activity  extends AppCompatActivity {

private Handler mHandler1 = new Handler();
private Handler mHandler2 = new Handler();
private Handler mHandler3 = new Handler();

private long mStartRX1 = 0;
private long mStartTX1 = 0;
private long mStartRX2 = 0;
private long mStartTX2 = 0;
private long mStartRX3 = 0;
private long mStartTX3 = 0;
private long mStartRX4 = 0;
private long mStartTX4 = 0;

private PlayerWebView mVideoView;

int UID = android.os.Process.myUid();

public static final String API_KEY = "my API KEY";

public static final String VIDEO_ID = "e4gDgggbWAM";

int a,b,c,d,e,f;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rien);

    mStartRX1 = TrafficStats.getUidRxBytes(UID);
    mStartTX1 = TrafficStats.getUidTxBytes(UID);


    mHandler1.postDelayed(mRunnable1, 1);

    mVideoView = (PlayerWebView) findViewById(R.id.youtube_player);
    mVideoView.load("x4ct1a5");

    Button button6 = (Button) findViewById(R.id.button6);
    button6.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            String mySdkKey = "Confidential";

            String myUserId = "Confidential";

            int sdIconId = R.drawable.ic_launcher2;


            Boolean sdkUserMessaging = true;


            mStartRX3 = TrafficStats.getUidRxBytes(UID);
            mStartTX3 = TrafficStats.getUidTxBytes(UID);


            mHandler2.postDelayed(mRunnable2, 1);

            mHandler3.postDelayed(mRunnable3, 1);

        }
    });

}

private final Runnable mRunnable1 = new Runnable() {
    public void run() {
        TextView RX1 = (TextView)findViewById(R.id.RX1);
        TextView TX1 = (TextView)findViewById(R.id.TX1);

        long rxBytes1 = (TrafficStats.getUidRxBytes(UID) - mStartRX1) ;
        RX1.setText(Long.toString(rxBytes1));
        long txBytes1 = (TrafficStats.getUidTxBytes(UID) - mStartTX1) ;
        TX1.setText(Long.toString(txBytes1));
        mHandler1.postDelayed(mRunnable1, 1);

    }
};

public final Runnable mRunnable2 = new Runnable() {
    public void run() {
        TextView RX2 = (TextView)findViewById(R.id.RX2);
        TextView TX2 = (TextView)findViewById(R.id.TX2);

        long rxBytes2 = (TrafficStats.getUidRxBytes(UID) - mStartRX3) ;
        RX2.setText(Long.toString(rxBytes2));
        long txBytes2 = (TrafficStats.getUidTxBytes(UID) - mStartTX3) ;
        TX2.setText(Long.toString(txBytes2));
        mHandler2.postDelayed(mRunnable2, 1);
    }
};

public final Runnable mRunnable3 = new Runnable() {
    public void run() {
        TextView RX1 = (TextView)findViewById(R.id.RX1);
        TextView TX1 = (TextView)findViewById(R.id.TX1);

        TextView RX2 = (TextView)findViewById(R.id.RX2);
        TextView TX2 = (TextView)findViewById(R.id.TX2);

        TextView RX3 = (TextView)findViewById(R.id.RX3);
        TextView TX3 = (TextView)findViewById(R.id.TX3);

        a = Integer.parseInt(RX1.getText().toString());
        b = Integer.parseInt(RX2.getText().toString());

        c = Integer.parseInt(TX1.getText().toString());
        d = Integer.parseInt(TX2.getText().toString());

        e = a - b;

        f=c-d;

        RX3.setText(Integer.toString(e));
        TX3.setText(Integer.toString(f));
        mHandler3.postDelayed(mRunnable3, 1);
    }
};}
0

There are 0 answers