16
16
17
17
import android .annotation .SuppressLint ;
18
18
import android .database .SQLException ;
19
+ import android .os .SystemClock ;
19
20
import com .google .android .datatransport .Event ;
20
21
import com .google .android .datatransport .Priority ;
21
22
import com .google .android .datatransport .Transport ;
@@ -39,10 +40,12 @@ final class ReportQueue {
39
40
private static final int MS_PER_SECOND = 1_000 ;
40
41
private static final int MS_PER_MINUTE = 60_000 ;
41
42
private static final int MAX_DELAY_MS = 3_600_000 ; // 1 hour.
43
+ private static final int STARTUP_DURATION_MS = 2_000 ; // 2 seconds.
42
44
43
45
private final double ratePerMinute ;
44
46
private final double base ;
45
47
private final long stepDurationMs ;
48
+ private final long startTimeMs ;
46
49
47
50
private final int queueCapacity ;
48
51
private final BlockingQueue <Runnable > queue ;
@@ -77,6 +80,8 @@ final class ReportQueue {
77
80
this .transport = transport ;
78
81
this .onDemandCounter = onDemandCounter ;
79
82
83
+ startTimeMs = SystemClock .elapsedRealtime ();
84
+
80
85
// The queue capacity is the per-minute rate number. // TODO(mrober): Round up to next int?
81
86
queueCapacity = (int ) ratePerMinute ;
82
87
queue = new ArrayBlockingQueue <>(queueCapacity );
@@ -146,14 +151,17 @@ private void sendReport(
146
151
TaskCompletionSource <CrashlyticsReportWithSessionId > tcs ) {
147
152
Logger .getLogger ()
148
153
.d ("Sending report through Google DataTransport: " + reportWithSessionId .getSessionId ());
154
+ boolean isStartup = (SystemClock .elapsedRealtime () - startTimeMs ) < STARTUP_DURATION_MS ;
149
155
transport .schedule (
150
156
Event .ofUrgent (reportWithSessionId .getReport ()),
151
157
error -> {
152
158
if (error != null ) {
153
159
tcs .trySetException (error );
154
160
return ;
155
161
}
156
- flushScheduledReportsIfAble ();
162
+ if (isStartup ) {
163
+ flushScheduledReportsIfAble ();
164
+ }
157
165
tcs .trySetResult (reportWithSessionId );
158
166
});
159
167
}
0 commit comments