@@ -76,7 +76,7 @@ private void fetchStats(NetworkTemplate template) {
7676 Long .MAX_VALUE , false );
7777 reportStats (stats );
7878 } catch (RemoteException e ) {
79- Log .w (LOG_TAG , "Failed to fetch network stats for wifi ." );
79+ Log .w (LOG_TAG , "Failed to fetch network stats." );
8080 }
8181 }
8282
@@ -85,16 +85,22 @@ private void fetchStats(NetworkTemplate template) {
8585 * @param stats {@link NetworkorStats} to print
8686 */
8787 void reportStats (NetworkStats stats ) {
88+ Bundle result = new Bundle ();
89+ long rxBytes = 0 ;
90+ long txBytes = 0 ;
8891 for (int i = 0 ; i < stats .size (); ++i ) {
92+ // Label will be iface_uid_tag_set
8993 Entry statsEntry = stats .getValues (i , null );
90- Bundle result = new Bundle ();
91- result .putInt ("uid" , statsEntry .uid );
92- result .putInt ("tag" , statsEntry .tag );
93- result .putInt ("set" , statsEntry .set );
94- result .putString ("iface" , statsEntry .iface );
95- result .putLong ("rxBytes" , statsEntry .rxBytes );
96- result .putLong ("txBytes" , statsEntry .txBytes );
97- getInstrumentation ().sendStatus (INSTRUMENTATION_IN_PROGRESS , result );
94+ String labelTemplate = String .format ("%s_%d_%d_%d" , statsEntry .iface , statsEntry .uid ,
95+ statsEntry .tag , statsEntry .set ) + "_%s" ;
96+ result .putLong (String .format (labelTemplate , "rxBytes" ), statsEntry .rxBytes );
97+ result .putLong (String .format (labelTemplate , "txBytes" ), statsEntry .txBytes );
98+ rxBytes += statsEntry .rxBytes ;
99+ txBytes += statsEntry .txBytes ;
98100 }
101+ result .putLong ("Total rxBytes" , rxBytes );
102+ result .putLong ("Total txBytes" , txBytes );
103+ getInstrumentation ().sendStatus (INSTRUMENTATION_IN_PROGRESS , result );
104+
99105 }
100106}
0 commit comments