Skip to content

Commit 56fc810

Browse files
authored
Wait for DataTransport callback task at crash time (#1479)
Improves reliability of sending crash reports at crash time in the case that the process would exit before Crashlytics has received the asynchronous callback from DataTransport.
1 parent 1a13ce2 commit 56fc810

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,10 @@ public Task<Void> then(@Nullable AppSettingsData appSettingsData)
435435
// Data collection is enabled, so it's safe to send the report.
436436
boolean dataCollectionToken = true;
437437
sendSessionReports(appSettingsData, dataCollectionToken);
438-
reportingCoordinator.sendReports(
439-
executor, DataTransportState.getState(appSettingsData));
440-
return recordFatalFirebaseEventTask;
438+
return Tasks.whenAll(
439+
reportingCoordinator.sendReports(
440+
executor, DataTransportState.getState(appSettingsData)),
441+
recordFatalFirebaseEventTask);
441442
}
442443
});
443444
}

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import androidx.annotation.NonNull;
1919
import androidx.annotation.Nullable;
2020
import com.google.android.gms.tasks.Task;
21+
import com.google.android.gms.tasks.Tasks;
2122
import com.google.firebase.crashlytics.internal.Logger;
2223
import com.google.firebase.crashlytics.internal.log.LogFileManager;
2324
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport;
@@ -170,16 +171,17 @@ public void removeAllReports() {
170171
* sent.
171172
* @param dataTransportState used to determine whether to send the report before cleaning it up.
172173
*/
173-
public void sendReports(
174+
Task<Void> sendReports(
174175
@NonNull Executor reportSendCompleteExecutor,
175176
@NonNull DataTransportState dataTransportState) {
176177
if (dataTransportState == DataTransportState.NONE) {
177178
Logger.getLogger().d("Send via DataTransport disabled. Removing DataTransport reports.");
178179
reportPersistence.deleteAllReports();
179-
return;
180+
return Tasks.forResult(null);
180181
}
181182
final List<CrashlyticsReportWithSessionId> reportsToSend =
182183
reportPersistence.loadFinalizedReports();
184+
final List<Task<Boolean>> sendTasks = new ArrayList<>();
183185
for (CrashlyticsReportWithSessionId reportToSend : reportsToSend) {
184186
if (reportToSend.getReport().getType() == CrashlyticsReport.Type.NATIVE
185187
&& dataTransportState != DataTransportState.ALL) {
@@ -189,10 +191,12 @@ public void sendReports(
189191
continue;
190192
}
191193

192-
reportsSender
193-
.sendReport(reportToSend)
194-
.continueWith(reportSendCompleteExecutor, this::onReportSendComplete);
194+
sendTasks.add(
195+
reportsSender
196+
.sendReport(reportToSend)
197+
.continueWith(reportSendCompleteExecutor, this::onReportSendComplete));
195198
}
199+
return Tasks.whenAll(sendTasks);
196200
}
197201

198202
private void persistEvent(

0 commit comments

Comments
 (0)