Skip to content

Only attempt to flush reports for start up crashes #4786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.annotation.SuppressLint;
import android.database.SQLException;
import android.os.SystemClock;
import com.google.android.datatransport.Event;
import com.google.android.datatransport.Priority;
import com.google.android.datatransport.Transport;
Expand All @@ -39,10 +40,12 @@ final class ReportQueue {
private static final int MS_PER_SECOND = 1_000;
private static final int MS_PER_MINUTE = 60_000;
private static final int MAX_DELAY_MS = 3_600_000; // 1 hour.
private static final int STARTUP_DURATION_MS = 2_000; // 2 seconds.

private final double ratePerMinute;
private final double base;
private final long stepDurationMs;
private final long startTimeMs;

private final int queueCapacity;
private final BlockingQueue<Runnable> queue;
Expand Down Expand Up @@ -77,6 +80,8 @@ final class ReportQueue {
this.transport = transport;
this.onDemandCounter = onDemandCounter;

startTimeMs = SystemClock.elapsedRealtime();

// The queue capacity is the per-minute rate number. // TODO(mrober): Round up to next int?
queueCapacity = (int) ratePerMinute;
queue = new ArrayBlockingQueue<>(queueCapacity);
Expand Down Expand Up @@ -146,14 +151,17 @@ private void sendReport(
TaskCompletionSource<CrashlyticsReportWithSessionId> tcs) {
Logger.getLogger()
.d("Sending report through Google DataTransport: " + reportWithSessionId.getSessionId());
boolean isStartup = (SystemClock.elapsedRealtime() - startTimeMs) < STARTUP_DURATION_MS;
transport.schedule(
Event.ofUrgent(reportWithSessionId.getReport()),
error -> {
if (error != null) {
tcs.trySetException(error);
return;
}
flushScheduledReportsIfAble();
if (isStartup) {
flushScheduledReportsIfAble();
}
tcs.trySetResult(reportWithSessionId);
});
}
Expand Down