Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ public Task<Void> call() throws Exception {
ex, thread, currentSessionId, timestampSeconds);

doWriteAppExceptionMarker(timestampMillis);

doCloseSessions();
doOpenSession();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public Type getType() {
@Nullable
public abstract FilesPayload getNdkPayload();

@Nullable
public abstract ApplicationExitInfo getAppExitInfo();

@NonNull
protected abstract Builder toBuilder();

Expand Down Expand Up @@ -155,6 +158,16 @@ public CrashlyticsReport withNdkPayload(@NonNull FilesPayload filesPayload) {
return toBuilder().setSession(null).setNdkPayload(filesPayload).build();
}

/**
* Augment an existing {@link CrashlyticsReport} with an ApplicationExitInfo
*
* @return a new {@link CrashlyticsReport} with AppExitInfo inside of it.
*/
@NonNull
public CrashlyticsReport withAppExitInfo(@NonNull ApplicationExitInfo appExitInfo) {
return toBuilder().setAppExitInfo(appExitInfo).build();
}

/**
* Augment an existing {@link CrashlyticsReport} with fields set at session end.
*
Expand Down Expand Up @@ -1021,6 +1034,53 @@ public abstract static class Builder {
}
}

@AutoValue
public abstract static class ApplicationExitInfo {

@NonNull
public static ApplicationExitInfo.Builder builder() {
return new AutoValue_CrashlyticsReport_ApplicationExitInfo.Builder();
}

@NonNull
public abstract String getProcessName();

@NonNull
public abstract int getReasonCode();

@NonNull
public abstract int getImportance();

@NonNull
public abstract long getTimestamp();

@NonNull
public abstract String getTraceFile();

/** Builder for {@link ApplicationExitInfo}. */
@AutoValue.Builder
public abstract static class Builder {

@NonNull
public abstract ApplicationExitInfo.Builder setProcessName(@NonNull String value);

@NonNull
public abstract ApplicationExitInfo.Builder setReasonCode(@NonNull int value);

@NonNull
public abstract ApplicationExitInfo.Builder setImportance(@NonNull int value);

@NonNull
public abstract ApplicationExitInfo.Builder setTimestamp(@NonNull long value);

@Nullable
public abstract ApplicationExitInfo.Builder setTraceFile(@Nullable String value);

@NonNull
public abstract ApplicationExitInfo build();
}
}

@AutoValue.Builder
public abstract static class Builder {

Expand Down Expand Up @@ -1048,6 +1108,9 @@ public abstract static class Builder {
@NonNull
public abstract Builder setNdkPayload(FilesPayload value);

@NonNull
public abstract Builder setAppExitInfo(ApplicationExitInfo value);

@NonNull
public abstract CrashlyticsReport build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public void testWithEvents_returnsNewReportWithEvents() {
assertEquals(2, withEventsReport.getSession().getEvents().size());
}

@Test
public void testWithEvents_returnsNewReportWithAnr() {
final CrashlyticsReport testReport = makeTestReport();

assertNull(testReport.getSession().getEvents());
final CrashlyticsReport withAnrEventsReport =
testReport
.withEvents(ImmutableList.from(makeAnrEvent()))
.withAppExitInfo(makeAppExitInfo());

assertNotEquals(testReport, withAnrEventsReport);
assertNotNull(withAnrEventsReport.getSession().getEvents());
assertEquals(1, withAnrEventsReport.getSession().getEvents().size());
assertNotNull(withAnrEventsReport.getAppExitInfo());
}

@Test
public void testWithOrganizationId_returnsNewReportWithOrganizationId() {
final CrashlyticsReport testReport = makeTestReport();
Expand Down Expand Up @@ -209,9 +225,17 @@ private static ImmutableList<Event> makeTestEvents(int numEvents) {
return ImmutableList.from(events);
}

private static Event makeAnrEvent() {
return makeTestEvent("ANR");
}

private static Event makeTestEvent() {
return makeTestEvent("test");
}

private static Event makeTestEvent(String eventType) {
return Event.builder()
.setType("type")
.setType(eventType)
.setTimestamp(1000)
.setApp(
Session.Event.Application.builder()
Expand Down Expand Up @@ -256,6 +280,16 @@ private static Event makeTestEvent() {
.build();
}

private static CrashlyticsReport.ApplicationExitInfo makeAppExitInfo() {
return CrashlyticsReport.ApplicationExitInfo.builder()
.setTraceFile("trace")
.setTimestamp(1L)
.setImportance(1)
.setReasonCode(1)
.setProcessName("test")
.build();
}

private static ImmutableList<Frame> makeTestFrames() {
return ImmutableList.from(
Frame.builder()
Expand Down