title: NetworkStatsManager.queryDetailsForUid not obtaining the "same" values as TrafficStats
body: <p>I'm comparing the new <code>NetworkStats</code> class with <code>TrafficStats</code> for measuring traffic for the network interfaces and a given application (pex Chrome)</p>
  
  <p>Since <code>TrafficStats</code> has values since device boot the test that I'm performing is this:</p>
  
  <ol>
  <li>Reboot phone. </li>
  <li>Open Chrome. </li>
  <li>Download 10 mb data (over WiFi).</li>
  </ol>
  
  <p>The data obtained with <code>TrafficStats</code> is this:</p>
  
  <pre><code>TrafficStats.getTotalRxBytes() aprox 17.21 MB
  TrafficStats.getUidRxBytes(chromeUid) aprox 13.22 MB
  </code></pre>
  
  <p>I grant the permission to <code>NetworkStats</code> and the values that I obtain are this:</p>
  
  <pre><code>wifiBucket.getRxBytes() + mobileBucket.getRxBytes() aprox 17.23 MB
  dataFromWiFiBucket[1] + dataFromMobileBucket[1] gives 0 bytes
  </code></pre>
  
  <p>The code to obtain the data from <code>NetworkStats</code> is the following:</p>
  
  <pre><code>long timeStamp = System.currentTimeMillis();
  long bootTime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
  
  NetworkStats.Bucket wifiBucket = networkStatsManager.querySummaryForDevice(ConnectivityManager.TYPE_WIFI, null, bootTime, timeStamp);
  NetworkStats.Bucket mobileBucket = networkStatsManager.querySummaryForDevice(ConnectivityManager.TYPE_MOBILE, subscriberID, bootTime, timeStamp);
  
  NetworkStats wifiBucketForApp = networkStatsManager.queryDetailsForUid(ConnectivityManager.TYPE_WIFI, null, bootTime, timeStamp, chromeUid);
  NetworkStats mobileBucketForApp = networkStatsManager.queryDetailsForUid(ConnectivityManager.TYPE_MOBILE, subscriberID, bootTime, timeStamp, chromeUid);
  
  long[] dataFromWiFiBucket = getDataFromBucket(wifiBucketForApp);
  long[] dataFromMobileBucket = getDataFromBucket(mobileBucketForApp);
  </code></pre>
  
  <p>Where <code>getDataFromBucket</code> is:</p>
  
  <pre><code>@RequiresApi(api = Build.VERSION_CODES.M) public static long[] getDataFromBucket(NetworkStats bucketForApp) {
  
      long dataTx = 0;
      long dataRx = 0;
  
      NetworkStats.Bucket bucket;
  
      while (bucketForApp.hasNextBucket()) {
          bucket = new NetworkStats.Bucket();
          bucketForApp.getNextBucket(bucket);
          dataTx += bucket.getTxBytes();
          dataRx += bucket.getRxBytes();
  
      }
  
      return new long[]{dataTx, dataRx};
  }
  </code></pre>
  
  <p>I've read somewhere that buckets are from two hours so I've added this code:</p>
  
  <pre><code>if (bootTime &gt; (timeStamp - TimeUnit.HOURS.toMillis(TWO_HOURS))) {
      bootTime = timeStamp - TimeUnit.HOURS.toMillis(TWO_HOURS);
  }
  </code></pre>
  
  <p>But data for chrome is still 0 because <code>wifiBucketForApp</code> and <code>mobileBucketForApp</code> do not have any buckets.</p>
  
  <p>If I set <code>bootTime</code> to the beginning of the day (its 18:30 in my country) I obtain:</p>
  
  <pre><code>wifiBucket.getRxBytes() + mobileBucket.getRxBytes() aprox 44.74 MB (expected because is since the beginning of the day)
  dataFromWiFiBucket[1] + dataFromMobileBucket[1] gives 26.32 MB
  </code></pre>
  
  <p>Does anybody know why I'm not obtaining the same values as <code>TrafficStats</code> since device boot from <code>NetworkStatsManager</code> for the Chrome app?</p>