diff --git a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinatorTest.java b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinatorTest.java index ab95fa94900..97f2bb3b22f 100644 --- a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinatorTest.java +++ b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinatorTest.java @@ -35,12 +35,10 @@ import com.google.firebase.crashlytics.internal.metadata.UserMetadata; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.CustomAttribute; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.crashlytics.internal.persistence.CrashlyticsReportPersistence; import com.google.firebase.crashlytics.internal.send.DataTransportCrashlyticsReportSender; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -233,8 +231,9 @@ public void testNonFatalEvent_addsSortedKeysToEvent() { final CustomAttribute customAttribute2 = CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build(); - final ImmutableList expectedCustomAttributes = - ImmutableList.from(customAttribute1, customAttribute2); + final List expectedCustomAttributes = new ArrayList<>(); + expectedCustomAttributes.add(customAttribute1); + expectedCustomAttributes.add(customAttribute2); when(reportMetadata.getCustomKeys()).thenReturn(attributes); when(reportMetadata.getInternalKeys()).thenReturn(attributes); @@ -294,8 +293,9 @@ public void testFatalEvent_addsSortedCustomKeysToEvent() { final CustomAttribute customAttribute2 = CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build(); - final ImmutableList expectedCustomAttributes = - ImmutableList.from(customAttribute1, customAttribute2); + final List expectedCustomAttributes = new ArrayList<>(); + expectedCustomAttributes.add(customAttribute1); + expectedCustomAttributes.add(customAttribute2); when(reportMetadata.getCustomKeys()).thenReturn(attributes); @@ -331,8 +331,9 @@ public void testFatalEvent_addsSortedInternalKeysToEvent() { final CustomAttribute customAttribute2 = CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build(); - final ImmutableList expectedCustomAttributes = - ImmutableList.from(customAttribute1, customAttribute2); + final List expectedCustomAttributes = new ArrayList<>(); + expectedCustomAttributes.add(customAttribute1); + expectedCustomAttributes.add(customAttribute2); when(reportMetadata.getInternalKeys()).thenReturn(attributes); @@ -403,7 +404,8 @@ public void testFinalizeSessionWithNativeEvent_createsCrashlyticsReportWithNativ String byteBackedSessionName = "byte"; BytesBackedNativeSessionFile byteSession = new BytesBackedNativeSessionFile(byteBackedSessionName, "not_applicable", testBytes); - reportingCoordinator.finalizeSessionWithNativeEvent("id", Arrays.asList(byteSession), null); + reportingCoordinator.finalizeSessionWithNativeEvent( + "id", Collections.singletonList(byteSession), null); ArgumentCaptor filesPayload = ArgumentCaptor.forClass(CrashlyticsReport.FilesPayload.class); diff --git a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransformTest.java b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransformTest.java index 58b7deea60e..9e6c36dcd9e 100644 --- a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransformTest.java +++ b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransformTest.java @@ -24,9 +24,9 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Signal; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Thread.Frame; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.User; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -144,14 +144,6 @@ private static Application makeTestApplication(boolean useDevelopmentPlatform) { return builder.build(); } - private static ImmutableList makeTestEvents(int numEvents) { - List events = new ArrayList<>(); - for (int i = 0; i < numEvents; i++) { - events.add(makeTestEvent()); - } - return ImmutableList.from(events); - } - private static Event makeTestEvent() { return Event.builder() .setType("type") @@ -162,7 +154,7 @@ private static Event makeTestEvent() { .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -178,7 +170,7 @@ private static Event makeTestEvent() { .build()) .setSignal(Signal.builder().setCode("0").setName("0").setAddress(0).build()) .setThreads( - ImmutableList.from( + Collections.singletonList( Session.Event.Application.Execution.Thread.builder() .setName("name") .setImportance(4) @@ -209,7 +201,7 @@ private static Event makeAnrEvent(boolean withBuildIds) { .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -233,29 +225,33 @@ private static Event makeAnrEvent(boolean withBuildIds) { .build(); } - private static ImmutableList makeTestFrames() { - return ImmutableList.from( + private static List makeTestFrames() { + ArrayList frames = new ArrayList<>(); + frames.add( Frame.builder() .setPc(0) .setSymbol("func1") .setFile("Test.java") .setOffset(36) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func2") .setFile("Test.java") .setOffset(5637) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func3") .setFile("Test.java") .setOffset(22429) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func4") @@ -263,14 +259,15 @@ private static ImmutableList makeTestFrames() { .setOffset(751) .setImportance(4) .build()); + return Collections.unmodifiableList(frames); } private static CrashlyticsReport.ApplicationExitInfo makeAppExitInfo(boolean withBuildIds) { - ImmutableList + List buildIdMappingForArchImmutableList = null; if (withBuildIds) { buildIdMappingForArchImmutableList = - ImmutableList.from( + Collections.singletonList( CrashlyticsReport.ApplicationExitInfo.BuildIdMappingForArch.builder() .setLibraryName("lib.so") .setArch("x86") diff --git a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistenceTest.java b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistenceTest.java index 89a77bddda1..71ef2995558 100644 --- a/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistenceTest.java +++ b/firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistenceTest.java @@ -32,7 +32,6 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Signal; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Thread.Frame; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.ProcessDetails; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.crashlytics.internal.settings.Settings; import com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData; import com.google.firebase.crashlytics.internal.settings.SettingsProvider; @@ -40,6 +39,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -164,7 +164,7 @@ public void testLoadFinalizedReports_reportThenEvent_returnsReportWithEvent() { testReport .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent)), + .withEvents(Collections.singletonList(testEvent)), finalizedReport); } @@ -186,11 +186,14 @@ public void testLoadFinalizedReports_reportThenMultipleEvents_returnsReportWithM reportPersistence.loadFinalizedReports(); assertEquals(1, finalizedReports.size()); final CrashlyticsReport finalizedReport = finalizedReports.get(0).getReport(); + ArrayList events = new ArrayList<>(); + events.add(testEvent); + events.add(testEvent2); assertEquals( testReport .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent, testEvent2)), + .withEvents(events), finalizedReport); } @@ -220,14 +223,14 @@ public void testLoadFinalizedReports_reportThenMultipleEvents_returnsReportWithM testReport1 .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent1)), + .withEvents(Collections.singletonList(testEvent1)), finalizedReport1); final CrashlyticsReport finalizedReport2 = finalizedReports.get(0).getReport(); assertEquals( testReport2 .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent2)), + .withEvents(Collections.singletonList(testEvent2)), finalizedReport2); } @@ -450,9 +453,11 @@ public void testLoadFinalizedReports_reportWithProcessDetails_returnsReportWithP CrashlyticsReport testReport = makeTestReport(sessionId); ProcessDetails process1 = makeProcessDetails("process1"); ProcessDetails process2 = makeProcessDetails("process2"); + ArrayList processDetails = new ArrayList<>(); + processDetails.add(process1); + processDetails.add(process2); CrashlyticsReport.Session.Event testEvent = - makeTestEvent( - "java.lang.Exception", "reason", process1, ImmutableList.from(process1, process2)); + makeTestEvent("java.lang.Exception", "reason", process1, processDetails); reportPersistence.persistReport(testReport); reportPersistence.persistEvent(testEvent, sessionId); @@ -601,11 +606,16 @@ public void testPersistEvent_keepsAppropriateNumberOfMostRecentEvents() throws I assertEquals(1, finalizedReports.size()); final CrashlyticsReport finalizedReport = finalizedReports.get(0).getReport(); assertEquals(4, finalizedReport.getSession().getEvents().size()); + ArrayList events = new ArrayList<>(); + events.add(testEvent2); + events.add(testEvent3); + events.add(testEvent4); + events.add(testEvent5); assertEquals( testReport .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent2, testEvent3, testEvent4, testEvent5)), + .withEvents(events), finalizedReport); } @@ -649,11 +659,16 @@ public void testPersistEvent_whenSettingsChanges_keepsAppropriateNumberOfMostRec assertEquals(1, finalizedReports.size()); final CrashlyticsReport finalizedReport = finalizedReports.get(0).getReport(); assertEquals(4, finalizedReport.getSession().getEvents().size()); + ArrayList events = new ArrayList<>(); + events.add(testEvent2); + events.add(testEvent3); + events.add(testEvent4); + events.add(testEvent5); assertEquals( testReport .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents(ImmutableList.from(testEvent2, testEvent3, testEvent4, testEvent5)), + .withEvents(events), finalizedReport); when(settingsProvider.getSettingsSync()).thenReturn(settings2); @@ -687,20 +702,21 @@ public void testPersistEvent_whenSettingsChanges_keepsAppropriateNumberOfMostRec assertEquals(2, finalizedReports2.size()); final CrashlyticsReport finalizedReport2 = finalizedReports2.get(0).getReport(); assertEquals(8, finalizedReport2.getSession().getEvents().size()); + ArrayList allEvents = new ArrayList<>(); + allEvents.add(testEvent3); + allEvents.add(testEvent4); + allEvents.add(testEvent5); + allEvents.add(testEvent6); + allEvents.add(testEvent7); + allEvents.add(testEvent8); + allEvents.add(testEvent9); + allEvents.add(testEvent10); + assertEquals( testReport2 .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(APP_QUALITY_SESSION_ID) - .withEvents( - ImmutableList.from( - testEvent3, - testEvent4, - testEvent5, - testEvent6, - testEvent7, - testEvent8, - testEvent9, - testEvent10)), + .withEvents(allEvents), finalizedReport2); } @@ -754,7 +770,7 @@ public void testFinalizeReports_missingAppQualitySessionId() { assertEquals( testReport .withSessionEndFields(endedAt, false, null) - .withEvents(ImmutableList.from(testEvent)), + .withEvents(Collections.singletonList(testEvent)), finalizedReport); // getAppQualitySessionId should return null since sessions subscriber never got an id. @@ -795,11 +811,15 @@ public void testPersistEvent_updatesLatestAppQualitySession() { assertEquals(1, finalizedReports.size()); CrashlyticsReport finalizedReport = finalizedReports.get(0).getReport(); assertNotNull(finalizedReport.getSession()); + ArrayList events = new ArrayList<>(); + events.add(testEvent1); + events.add(testEvent2); + events.add(testEvent3); assertEquals( testReport .withSessionEndFields(endedAt, false, null) .withAppQualitySessionId(latestAppQualitySessionId) - .withEvents(ImmutableList.from(testEvent1, testEvent2, testEvent3)), + .withEvents(events), finalizedReport); } @@ -834,7 +854,7 @@ private static CrashlyticsReport.FilesPayload makeFilePayload() { return CrashlyticsReport.FilesPayload.builder() .setOrgId("orgId") .setFiles( - ImmutableList.from( + Collections.singletonList( CrashlyticsReport.FilesPayload.File.builder() .setContents(testContents) .setFilename("bytes") @@ -848,7 +868,7 @@ private static CrashlyticsReport makeTestNativeReport() { CrashlyticsReport.FilesPayload.builder() .setOrgId("orgId") .setFiles( - ImmutableList.from( + Collections.singletonList( CrashlyticsReport.FilesPayload.File.builder() .setContents(testContents) .setFilename("bytes") @@ -889,7 +909,7 @@ private static Event makeTestEvent( String type, String reason, @Nullable ProcessDetails currentProcessDetails, - @Nullable ImmutableList appProcessDetails) { + @Nullable List appProcessDetails) { return Event.builder() .setType(type) .setTimestamp(1000) @@ -901,7 +921,7 @@ private static Event makeTestEvent( .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -917,7 +937,7 @@ private static Event makeTestEvent( .build()) .setSignal(Signal.builder().setCode("0").setName("0").setAddress(0).build()) .setThreads( - ImmutableList.from( + Collections.singletonList( Session.Event.Application.Execution.Thread.builder() .setName("name") .setImportance(4) @@ -948,7 +968,7 @@ private static Event makeTestAnrEvent() { .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -972,29 +992,33 @@ private static Event makeTestAnrEvent() { .build(); } - private static ImmutableList makeTestFrames() { - return ImmutableList.from( + private static List makeTestFrames() { + ArrayList l = new ArrayList<>(); + l.add( Frame.builder() .setPc(0) .setSymbol("func1") .setFile("Test.java") .setOffset(36) .setImportance(4) - .build(), + .build()); + l.add( Frame.builder() .setPc(1) .setSymbol("func2") .setFile("Test.java") .setOffset(5637) .setImportance(4) - .build(), + .build()); + l.add( Frame.builder() .setPc(2) .setSymbol("func3") .setFile("Test.java") .setOffset(22429) .setImportance(4) - .build(), + .build()); + l.add( Frame.builder() .setPc(3) .setSymbol("func4") @@ -1002,6 +1026,8 @@ private static ImmutableList makeTestFrames() { .setOffset(751) .setImportance(4) .build()); + + return l; } private static CrashlyticsReport.ApplicationExitInfo makeAppExitInfo() { diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/ProcessDetailsProvider.kt b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/ProcessDetailsProvider.kt index 0b191f11ce8..bfa84d77af0 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/ProcessDetailsProvider.kt +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/ProcessDetailsProvider.kt @@ -21,7 +21,6 @@ import android.content.Context import android.os.Build import android.os.Process import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.ProcessDetails -import com.google.firebase.crashlytics.internal.model.ImmutableList /** * Provider of ProcessDetails. @@ -30,21 +29,19 @@ import com.google.firebase.crashlytics.internal.model.ImmutableList */ internal object ProcessDetailsProvider { /** Gets the details of all running app processes. */ - fun getAppProcessDetails(context: Context): ImmutableList { + fun getAppProcessDetails(context: Context): List { val defaultProcessName = context.applicationInfo.processName val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager val runningAppProcesses = activityManager?.runningAppProcesses ?: listOf() - return ImmutableList.from( - runningAppProcesses.filterNotNull().map { runningAppProcessInfo -> - ProcessDetails.builder() - .setProcessName(runningAppProcessInfo.processName) - .setPid(runningAppProcessInfo.pid) - .setImportance(runningAppProcessInfo.importance) - .setDefaultProcess(runningAppProcessInfo.processName == defaultProcessName) - .build() - } - ) + return runningAppProcesses.filterNotNull().map { runningAppProcessInfo -> + ProcessDetails.builder() + .setProcessName(runningAppProcessInfo.processName) + .setPid(runningAppProcessInfo.pid) + .setImportance(runningAppProcessInfo.importance) + .setDefaultProcess(runningAppProcessInfo.processName == defaultProcessName) + .build() + } } /** diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsReportDataCapture.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsReportDataCapture.java index 8a53a5974c2..b8ad6c967de 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsReportDataCapture.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsReportDataCapture.java @@ -32,11 +32,11 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.BinaryImage; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.ProcessDetails; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.crashlytics.internal.settings.SettingsProvider; import com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy; import com.google.firebase.crashlytics.internal.stacktrace.TrimmedThrowableData; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -135,7 +135,7 @@ public Event captureAnrEventData(CrashlyticsReport.ApplicationExitInfo applicati private CrashlyticsReport.ApplicationExitInfo addBuildIdInfo( CrashlyticsReport.ApplicationExitInfo applicationExitInfo) { - ImmutableList + List buildIdMappingForArchImmutableList = null; if (settingsProvider.getSettingsSync().featureFlagData.collectBuildIds && appData.buildIdInfoList.size() > 0) { @@ -149,7 +149,7 @@ private CrashlyticsReport.ApplicationExitInfo addBuildIdInfo( .setBuildId(buildIdInfo.getBuildId()) .build()); } - buildIdMappingForArchImmutableList = ImmutableList.from(buildIdMappingForArchList); + buildIdMappingForArchImmutableList = Collections.unmodifiableList(buildIdMappingForArchList); } return CrashlyticsReport.ApplicationExitInfo.builder() @@ -327,7 +327,7 @@ private Execution populateExecutionData( .build(); } - private ImmutableList populateThreadsList( + private List populateThreadsList( TrimmedThrowableData trimmedEvent, Thread eventThread, int eventThreadImportance, @@ -350,7 +350,7 @@ private ImmutableList populateThreadsList( } } - return ImmutableList.from(threadsList); + return Collections.unmodifiableList(threadsList); } private Execution.Thread populateThreadData(Thread thread, StackTraceElement[] stacktrace) { @@ -362,18 +362,18 @@ private Execution.Thread populateThreadData( return Execution.Thread.builder() .setName(thread.getName()) .setImportance(importance) - .setFrames(ImmutableList.from(populateFramesList(stacktrace, importance))) + .setFrames(populateFramesList(stacktrace, importance)) .build(); } - private ImmutableList populateFramesList( + private List populateFramesList( StackTraceElement[] stacktrace, int importance) { final List framesList = new ArrayList<>(); for (StackTraceElement element : stacktrace) { framesList.add( populateFrameData(element, Execution.Thread.Frame.builder().setImportance(importance))); } - return ImmutableList.from(framesList); + return Collections.unmodifiableList(framesList); } private Execution.Exception populateExceptionData( @@ -405,7 +405,7 @@ private Execution.Exception populateExceptionData( Execution.Exception.builder() .setType(type) .setReason(reason) - .setFrames(ImmutableList.from(populateFramesList(stacktrace, eventThreadImportance))) + .setFrames(populateFramesList(stacktrace, eventThreadImportance)) .setOverflowCount(overflowCount); if (cause != null && overflowCount == 0) { @@ -439,8 +439,8 @@ private Execution.Thread.Frame populateFrameData( return frameBuilder.setPc(pc).setSymbol(symbol).setFile(file).setOffset(offset).build(); } - private ImmutableList populateBinaryImagesList() { - return ImmutableList.from(populateBinaryImageData()); + private List populateBinaryImagesList() { + return Collections.singletonList(populateBinaryImageData()); } private Execution.BinaryImage populateBinaryImageData() { diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java index 0a15f5d3eb0..0fd7970fd3d 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java @@ -29,7 +29,6 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.CustomAttribute; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.FilesPayload; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.crashlytics.internal.persistence.CrashlyticsReportPersistence; import com.google.firebase.crashlytics.internal.persistence.FileStore; import com.google.firebase.crashlytics.internal.send.DataTransportCrashlyticsReportSender; @@ -181,7 +180,7 @@ public void finalizeSessionWithNativeEvent( reportPersistence.finalizeSessionWithNativeEvent( sessionId, - FilesPayload.builder().setFiles(ImmutableList.from(nativeFiles)).build(), + FilesPayload.builder().setFiles(Collections.unmodifiableList(nativeFiles)).build(), applicationExitInfo); } @@ -281,8 +280,8 @@ private CrashlyticsReport.Session.Event addLogsAndCustomKeysToEvent( if (!sortedCustomAttributes.isEmpty() || !sortedInternalKeys.isEmpty()) { eventBuilder.setApp( capturedEvent.getApp().toBuilder() - .setCustomAttributes(ImmutableList.from(sortedCustomAttributes)) - .setInternalKeys(ImmutableList.from(sortedInternalKeys)) + .setCustomAttributes(sortedCustomAttributes) + .setInternalKeys(sortedInternalKeys) .build()); } @@ -346,7 +345,7 @@ private static List getSortedCustomAttributes( attributesList, (CustomAttribute attr1, CustomAttribute attr2) -> attr1.getKey().compareTo(attr2.getKey())); - return attributesList; + return Collections.unmodifiableList(attributesList); } @RequiresApi(api = Build.VERSION_CODES.R) diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReport.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReport.java index d5b6e56fee4..6d969d05c6f 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReport.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReport.java @@ -26,6 +26,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.charset.Charset; +import java.util.List; /** * This class represents the data captured by and reported to Crashlytics. @@ -121,7 +122,7 @@ public Type getType() { * @return a new {@link CrashlyticsReport} with its events list set to the given list of events. */ @NonNull - public CrashlyticsReport withEvents(@NonNull ImmutableList events) { + public CrashlyticsReport withEvents(@NonNull List events) { if (getSession() == null) { throw new IllegalStateException("Reports without sessions cannot have events added to them."); } @@ -213,7 +214,7 @@ public static Builder builder() { } @NonNull - public abstract ImmutableList getFiles(); + public abstract List getFiles(); @Nullable public abstract String getOrgId(); @@ -250,7 +251,7 @@ public abstract static class Builder { @AutoValue.Builder public abstract static class Builder { - public abstract Builder setFiles(ImmutableList value); + public abstract Builder setFiles(List value); public abstract Builder setOrgId(String value); @@ -332,7 +333,7 @@ public byte[] getIdentifierUtf8Bytes() { public abstract Device getDevice(); @Nullable - public abstract ImmutableList getEvents(); + public abstract List getEvents(); public abstract int getGeneratorType(); @@ -340,7 +341,7 @@ public byte[] getIdentifierUtf8Bytes() { public abstract Builder toBuilder(); @NonNull - Session withEvents(@NonNull ImmutableList events) { + Session withEvents(@NonNull List events) { return toBuilder().setEvents(events).build(); } @@ -406,7 +407,7 @@ public Builder setIdentifierFromUtf8Bytes(@NonNull byte[] utf8Bytes) { public abstract Builder setDevice(@NonNull Device value); @NonNull - public abstract Builder setEvents(@NonNull ImmutableList value); + public abstract Builder setEvents(@NonNull List value); @NonNull public abstract Builder setGeneratorType(int generatorType); @@ -678,10 +679,10 @@ public static Builder builder() { public abstract Execution getExecution(); @Nullable - public abstract ImmutableList getCustomAttributes(); + public abstract List getCustomAttributes(); @Nullable - public abstract ImmutableList getInternalKeys(); + public abstract List getInternalKeys(); @Nullable public abstract Boolean getBackground(); @@ -690,7 +691,7 @@ public static Builder builder() { public abstract ProcessDetails getCurrentProcessDetails(); @Nullable - public abstract ImmutableList getAppProcessDetails(); + public abstract List getAppProcessDetails(); public abstract int getUiOrientation(); @@ -706,7 +707,7 @@ public static Builder builder() { } @Nullable - public abstract ImmutableList getThreads(); + public abstract List getThreads(); @Nullable public abstract Exception getException(); @@ -718,7 +719,7 @@ public static Builder builder() { public abstract Signal getSignal(); @NonNull - public abstract ImmutableList getBinaries(); + public abstract List getBinaries(); @AutoValue public abstract static class Thread { @@ -735,7 +736,7 @@ public static Builder builder() { public abstract int getImportance(); @NonNull - public abstract ImmutableList getFrames(); + public abstract List getFrames(); @AutoValue public abstract static class Frame { @@ -793,7 +794,7 @@ public abstract static class Builder { public abstract Builder setImportance(int value); @NonNull - public abstract Builder setFrames(@NonNull ImmutableList value); + public abstract Builder setFrames(@NonNull List value); @NonNull public abstract Thread build(); @@ -816,7 +817,7 @@ public static Builder builder() { public abstract String getReason(); @NonNull - public abstract ImmutableList getFrames(); + public abstract List getFrames(); @Nullable public abstract Exception getCausedBy(); @@ -834,7 +835,7 @@ public abstract static class Builder { public abstract Builder setReason(@NonNull String value); @NonNull - public abstract Builder setFrames(@NonNull ImmutableList value); + public abstract Builder setFrames(@NonNull List value); @NonNull public abstract Builder setCausedBy(@NonNull Exception value); @@ -942,7 +943,7 @@ public Builder setUuidFromUtf8Bytes(@NonNull byte[] utf8Bytes) { public abstract static class Builder { @NonNull - public abstract Builder setThreads(@NonNull ImmutableList value); + public abstract Builder setThreads(@NonNull List value); @NonNull public abstract Builder setException(@NonNull Exception value); @@ -954,7 +955,7 @@ public abstract static class Builder { public abstract Builder setSignal(@NonNull Signal value); @NonNull - public abstract Builder setBinaries(@NonNull ImmutableList value); + public abstract Builder setBinaries(@NonNull List value); @NonNull public abstract Execution build(); @@ -1006,11 +1007,10 @@ public abstract static class Builder { public abstract Builder setExecution(@NonNull Execution value); @NonNull - public abstract Builder setCustomAttributes( - @NonNull ImmutableList value); + public abstract Builder setCustomAttributes(@NonNull List value); @NonNull - public abstract Builder setInternalKeys(@NonNull ImmutableList value); + public abstract Builder setInternalKeys(@NonNull List value); @NonNull public abstract Builder setBackground(@Nullable Boolean value); @@ -1020,7 +1020,7 @@ public abstract Builder setCustomAttributes( @NonNull public abstract Builder setAppProcessDetails( - @Nullable ImmutableList appProcessDetails); + @Nullable List appProcessDetails); @NonNull public abstract Builder setUiOrientation(int value); @@ -1161,7 +1161,7 @@ public static ApplicationExitInfo.Builder builder() { @Nullable // Not all ApplicationExitInfos have build id info - public abstract ImmutableList getBuildIdMappingForArch(); + public abstract List getBuildIdMappingForArch(); /** Builder for {@link ApplicationExitInfo}. */ @AutoValue.Builder @@ -1192,7 +1192,7 @@ public abstract static class Builder { @NonNull public abstract ApplicationExitInfo.Builder setBuildIdMappingForArch( - @Nullable ImmutableList value); + @Nullable List value); @NonNull public abstract ApplicationExitInfo build(); diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/ImmutableList.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/ImmutableList.java deleted file mode 100644 index 93b8c550dd4..00000000000 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/ImmutableList.java +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.firebase.crashlytics.internal.model; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.RandomAccess; - -/** Immutable list implementation for use with AutoValue */ -public final class ImmutableList implements List, RandomAccess { - - @NonNull - public static ImmutableList from(E... elements) { - return new ImmutableList<>(Arrays.asList(elements)); - } - - @NonNull - public static ImmutableList from(@NonNull List mutableList) { - return new ImmutableList<>(mutableList); - } - - private final List immutableList; - - private ImmutableList(List mutableList) { - this.immutableList = Collections.unmodifiableList(mutableList); - } - - @Override - public int size() { - return immutableList.size(); - } - - @Override - public boolean isEmpty() { - return immutableList.isEmpty(); - } - - @Override - public boolean contains(@Nullable Object o) { - return immutableList.contains(o); - } - - @NonNull - @Override - public Iterator iterator() { - return immutableList.iterator(); - } - - @Nullable - @Override - public Object[] toArray() { - return immutableList.toArray(); - } - - @Override - public T[] toArray(@Nullable T[] a) { - return immutableList.toArray(a); - } - - @Override - public boolean add(@NonNull E e) { - return immutableList.add(e); - } - - @Override - public boolean remove(@Nullable Object o) { - return immutableList.remove(o); - } - - @Override - public boolean containsAll(@NonNull Collection c) { - return immutableList.containsAll(c); - } - - @Override - public boolean addAll(@NonNull Collection c) { - return immutableList.addAll(c); - } - - @Override - public boolean addAll(int index, @NonNull Collection c) { - return immutableList.addAll(index, c); - } - - @Override - public boolean removeAll(@NonNull Collection c) { - return immutableList.removeAll(c); - } - - @Override - public boolean retainAll(@NonNull Collection c) { - return immutableList.retainAll(c); - } - - @Override - public void clear() { - immutableList.clear(); - } - - @Override - public boolean equals(@Nullable Object o) { - return immutableList.equals(o); - } - - @Override - public int hashCode() { - return immutableList.hashCode(); - } - - @NonNull - @Override - public E get(int index) { - return immutableList.get(index); - } - - @NonNull - @Override - public E set(int index, @NonNull E element) { - return immutableList.set(index, element); - } - - @Override - public void add(int index, @NonNull E element) { - immutableList.add(index, element); - } - - @Override - public E remove(int index) { - return immutableList.remove(index); - } - - @Override - public int indexOf(@Nullable Object o) { - return immutableList.indexOf(o); - } - - @Override - public int lastIndexOf(@Nullable Object o) { - return immutableList.lastIndexOf(o); - } - - @NonNull - @Override - public ListIterator listIterator() { - return immutableList.listIterator(); - } - - @NonNull - @Override - public ListIterator listIterator(int index) { - return immutableList.listIterator(index); - } - - @NonNull - @Override - public List subList(int fromIndex, int toIndex) { - return immutableList.subList(fromIndex, toIndex); - } -} diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransform.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransform.java index 1f5d7abf3f3..5365d747f07 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransform.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/model/serialization/CrashlyticsReportJsonTransform.java @@ -22,12 +22,12 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.ApplicationExitInfo.BuildIdMappingForArch; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.CustomAttribute; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.encoders.DataEncoder; import com.google.firebase.encoders.json.JsonDataEncoderBuilder; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class CrashlyticsReportJsonTransform { @@ -294,13 +294,10 @@ private static CrashlyticsReport.Session.User parseUser(@NonNull JsonReader json jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); - switch (name) { - case "identifier": - builder.setIdentifier(jsonReader.nextString()); - break; - default: - jsonReader.skipValue(); - break; + if (name.equals("identifier")) { + builder.setIdentifier(jsonReader.nextString()); + } else { + jsonReader.skipValue(); } } jsonReader.endObject(); @@ -764,13 +761,10 @@ private static Event.Log parseEventLog(@NonNull JsonReader jsonReader) throws IO jsonReader.beginObject(); while (jsonReader.hasNext()) { String name = jsonReader.nextName(); - switch (name) { - case "content": - builder.setContent(jsonReader.nextString()); - break; - default: - jsonReader.skipValue(); - break; + if (name.equals("content")) { + builder.setContent(jsonReader.nextString()); + } else { + jsonReader.skipValue(); } } jsonReader.endObject(); @@ -829,7 +823,7 @@ private static BuildIdMappingForArch parseBuildIdMappingForArch(@NonNull JsonRea } @NonNull - private static ImmutableList parseArray( + private static List parseArray( @NonNull JsonReader jsonReader, @NonNull ObjectParser objectParser) throws IOException { final List objects = new ArrayList<>(); @@ -839,7 +833,7 @@ private static ImmutableList parseArray( } jsonReader.endArray(); - return ImmutableList.from(objects); + return Collections.unmodifiableList(objects); } private interface ObjectParser { diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistence.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistence.java index 4fa895f96de..d684fda7b31 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistence.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/persistence/CrashlyticsReportPersistence.java @@ -23,7 +23,6 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session; import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event; -import com.google.firebase.crashlytics.internal.model.ImmutableList; import com.google.firebase.crashlytics.internal.model.serialization.CrashlyticsReportJsonTransform; import com.google.firebase.crashlytics.internal.settings.SettingsProvider; import java.io.ByteArrayOutputStream; @@ -357,7 +356,7 @@ private void synthesizeReportFile( .reportFromJson(readTextFile(reportFile)) .withSessionEndFields(sessionEndTime, isHighPriorityReport, userId) .withAppQualitySessionId(appQualitySessionId) - .withEvents(ImmutableList.from(events)); + .withEvents(events); final Session session = report.getSession(); if (session == null) { diff --git a/firebase-crashlytics/src/test/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReportTest.java b/firebase-crashlytics/src/test/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReportTest.java index 81e2240c31c..7b8a99118d2 100644 --- a/firebase-crashlytics/src/test/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReportTest.java +++ b/firebase-crashlytics/src/test/java/com/google/firebase/crashlytics/internal/model/CrashlyticsReportTest.java @@ -25,6 +25,7 @@ import com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event.Application.Execution.Thread.Frame; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.Test; @@ -49,7 +50,7 @@ public void testWithEvents_returnsNewReportWithAnr() { assertNull(testReport.getSession().getEvents()); final CrashlyticsReport withAnrEventsReport = - testReport.withEvents(ImmutableList.from(makeAnrEvent())); + testReport.withEvents(Collections.singletonList(makeAnrEvent())); assertNotEquals(testReport, withAnrEventsReport); assertNotNull(withAnrEventsReport.getSession().getEvents()); @@ -221,12 +222,12 @@ private static Application makeTestApplication() { .build(); } - private static ImmutableList makeTestEvents(int numEvents) { + private static List makeTestEvents(int numEvents) { List events = new ArrayList<>(); for (int i = 0; i < numEvents; i++) { events.add(makeTestEvent()); } - return ImmutableList.from(events); + return events; } private static Event makeAnrEvent() { @@ -239,7 +240,7 @@ private static Event makeAnrEvent() { .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -273,7 +274,7 @@ private static Event makeTestEvent() { .setExecution( Execution.builder() .setBinaries( - ImmutableList.from( + Collections.singletonList( Execution.BinaryImage.builder() .setBaseAddress(0) .setName("name") @@ -289,7 +290,7 @@ private static Event makeTestEvent() { .build()) .setSignal(Signal.builder().setCode("0").setName("0").setAddress(0).build()) .setThreads( - ImmutableList.from( + Collections.singletonList( Session.Event.Application.Execution.Thread.builder() .setName("name") .setImportance(4) @@ -323,29 +324,33 @@ private static CrashlyticsReport.ApplicationExitInfo makeAppExitInfo() { .build(); } - private static ImmutableList makeTestFrames() { - return ImmutableList.from( + private static List makeTestFrames() { + ArrayList frames = new ArrayList<>(); + frames.add( Frame.builder() .setPc(0) .setSymbol("func1") .setFile("Test.java") .setOffset(36) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func2") .setFile("Test.java") .setOffset(5637) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func3") .setFile("Test.java") .setOffset(22429) .setImportance(4) - .build(), + .build()); + frames.add( Frame.builder() .setPc(0) .setSymbol("func4") @@ -353,5 +358,6 @@ private static ImmutableList makeTestFrames() { .setOffset(751) .setImportance(4) .build()); + return frames; } }