1616
1717import android .annotation .SuppressLint ;
1818import android .database .SQLException ;
19+ import android .os .SystemClock ;
1920import com .google .android .datatransport .Event ;
2021import com .google .android .datatransport .Priority ;
2122import com .google .android .datatransport .Transport ;
@@ -39,10 +40,12 @@ final class ReportQueue {
3940 private static final int MS_PER_SECOND = 1_000 ;
4041 private static final int MS_PER_MINUTE = 60_000 ;
4142 private static final int MAX_DELAY_MS = 3_600_000 ; // 1 hour.
43+ private static final int STARTUP_DURATION_MS = 2_000 ; // 2 seconds.
4244
4345 private final double ratePerMinute ;
4446 private final double base ;
4547 private final long stepDurationMs ;
48+ private final long startTimeMs ;
4649
4750 private final int queueCapacity ;
4851 private final BlockingQueue <Runnable > queue ;
@@ -77,6 +80,8 @@ final class ReportQueue {
7780 this .transport = transport ;
7881 this .onDemandCounter = onDemandCounter ;
7982
83+ startTimeMs = SystemClock .elapsedRealtime ();
84+
8085 // The queue capacity is the per-minute rate number. // TODO(mrober): Round up to next int?
8186 queueCapacity = (int ) ratePerMinute ;
8287 queue = new ArrayBlockingQueue <>(queueCapacity );
@@ -146,14 +151,17 @@ private void sendReport(
146151 TaskCompletionSource <CrashlyticsReportWithSessionId > tcs ) {
147152 Logger .getLogger ()
148153 .d ("Sending report through Google DataTransport: " + reportWithSessionId .getSessionId ());
154+ boolean isStartup = (SystemClock .elapsedRealtime () - startTimeMs ) < STARTUP_DURATION_MS ;
149155 transport .schedule (
150156 Event .ofUrgent (reportWithSessionId .getReport ()),
151157 error -> {
152158 if (error != null ) {
153159 tcs .trySetException (error );
154160 return ;
155161 }
156- flushScheduledReportsIfAble ();
162+ if (isStartup ) {
163+ flushScheduledReportsIfAble ();
164+ }
157165 tcs .trySetResult (reportWithSessionId );
158166 });
159167 }
0 commit comments