title: NetworkStatsManager - what is the earliest possible start time?
body: <p>I'm using the NetworkStatsManager class to retrieve the data usage of the apps.  </p>
  
  <p>If I provide 01.01.2018 as start time, it shows that my phone has sent out 5,4 GB.<br>
  If I provide 01.01.2017, it still shows 5,4 GB.</p>
  
  <p>This lets me assume that there is a limit somehow regarding the start time. The documentation unfortunately does not mention anything regarding this.  </p>
  
  <p>So, how much in time can we go back?  </p>
  
  <p>Code:<br>
  This is the code which retrieves the data using querySummary:  </p>
  
  <pre><code>private long[] getBytesSummary(Context context, int networkType, Calendar calendar) {
      NetworkStatsManager networkStatsManager = (NetworkStatsManager) context.getSystemService(Context.NETWORK_STATS_SERVICE);
      NetworkStats networkStats = null;
      try {
          networkStats = networkStatsManager.querySummary(
                  networkType,
                  Util.getSubscriberId(context, networkType),
                  calendar.getTimeInMillis(),
                  System.currentTimeMillis());
      } catch (RemoteException e) {
          if (debug) Log.e(TAG, "getBytesSummary: " + e.toString());
      }
      long[] result = new long[2];
      long totalRxBytes = 0;
      long totalTxBytes = 0;
  
      NetworkStats.Bucket bucket = new NetworkStats.Bucket();
      if (networkStats != null) {
          while (networkStats.hasNextBucket()) {
              networkStats.getNextBucket(bucket);
              int uid = bucket.getUid();
              long uidRxBytes = bucket.getRxBytes();
              long uidTxBytes = bucket.getTxBytes();
              if (uidsWithNetworkUsageMap.indexOfKey(uid) &lt; 0) {
                  long[] uidBytes = new long[2];
                  uidBytes[0] = uidRxBytes;
                  uidBytes[1] = uidTxBytes;
                  uidsWithNetworkUsageMap.put(uid, uidBytes);
              } else {
                  long[] value = uidsWithNetworkUsageMap.get(uid);
                  value[0] = value[0] + uidRxBytes;
                  value[1] = value[1] + uidTxBytes;
                  uidsWithNetworkUsageMap.put(uid, value);
              }
              totalRxBytes += bucket.getRxBytes();
              totalTxBytes += bucket.getTxBytes();
          }
          networkStats.close();
      }
      result[0] = totalRxBytes;
      result[1] = totalTxBytes;
      return result;
  }
  </code></pre>
  
  <p>As you can see above, I give a calendar object to the method.<br>
  This is how I get the calendar for the current year:  </p>
  
  <pre><code>public static Calendar getCalendarCurrentYear() {
          Calendar calendar = Calendar.getInstance();
          calendar.set(Calendar.DAY_OF_YEAR, 1);
          // for 0-12 clocks
          calendar.set(Calendar.HOUR, 0);
          calendar.set(Calendar.AM_PM, Calendar.AM);
          // for 0-24 clocks
          calendar.set(Calendar.HOUR_OF_DAY, 0);
          calendar.set(Calendar.MINUTE, 0);
          calendar.set(Calendar.SECOND, 0);
          calendar.set(Calendar.MILLISECOND, 0);
  //        calendar.set(Calendar.YEAR, 2017);
          Log.i("DataUsage", "getCalendarCurrentYear: " + calendar.getTime());
          return calendar;
      }
  </code></pre>
  
  <p>This returns Mon Jan 01 00:00:00 GMT+01:00 2018.<br>
  If I set it now to 2017, the result is the same as for 2018.  </p>
  
  <p>Am I doing something wrong?  </p>
  
  <p><strong>EDIT:</strong><br>
  I just did some testing, the limit seems to be 3 months somehow.<br>
  Anything greater than 3 months as start time results in the same value.<br>
  Can anyone confirm that managed to get it working for <strong>more than 3 months from current time</strong>?<br>
  Or is there any official documentation addressing this?</p>