Search in sources :

Example 1 with NativeSessionFileProvider

use of com.google.firebase.crashlytics.internal.NativeSessionFileProvider in project firebase-android-sdk by firebase.

the class CrashlyticsController method finalizePreviousNativeSession.

private void finalizePreviousNativeSession(String previousSessionId) {
    Logger.getLogger().v("Finalizing native report for session " + previousSessionId);
    NativeSessionFileProvider nativeSessionFileProvider = nativeComponent.getSessionFileProvider(previousSessionId);
    File minidumpFile = nativeSessionFileProvider.getMinidumpFile();
    if (minidumpFile == null || !minidumpFile.exists()) {
        Logger.getLogger().w("No minidump data found for session " + previousSessionId);
        return;
    }
    // Because we don't want to read the minidump to get its timestamp, just use file creation time.
    final long eventTime = minidumpFile.lastModified();
    final LogFileManager previousSessionLogManager = new LogFileManager(fileStore, previousSessionId);
    final File nativeSessionDirectory = fileStore.getNativeSessionDir(previousSessionId);
    if (!nativeSessionDirectory.isDirectory()) {
        Logger.getLogger().w("Couldn't create directory to store native session files, aborting.");
        return;
    }
    doWriteAppExceptionMarker(eventTime);
    List<NativeSessionFile> nativeSessionFiles = getNativeSessionFiles(nativeSessionFileProvider, previousSessionId, fileStore, previousSessionLogManager.getBytesForLog());
    NativeSessionFileGzipper.processNativeSessions(nativeSessionDirectory, nativeSessionFiles);
    Logger.getLogger().d("CrashlyticsController#finalizePreviousNativeSession");
    reportingCoordinator.finalizeSessionWithNativeEvent(previousSessionId, nativeSessionFiles);
    previousSessionLogManager.clearLog();
}
Also used : NativeSessionFileProvider(com.google.firebase.crashlytics.internal.NativeSessionFileProvider) File(java.io.File) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager)

Example 2 with NativeSessionFileProvider

use of com.google.firebase.crashlytics.internal.NativeSessionFileProvider in project firebase-android-sdk by firebase.

the class CrashlyticsControllerTest method testNativeCrashDataCausesNativeReport.

public void testNativeCrashDataCausesNativeReport() throws Exception {
    final String sessionId = "sessionId_1_new";
    final String previousSessionId = "sessionId_0_previous";
    final File testDir = testFileStore.getNativeSessionDir(previousSessionId);
    final File minidump = new File(testDir, "crash.dmp");
    final File metadata = new File(testDir, "crash.device_info");
    final File session = new File(testDir, "session.json");
    final File app = new File(testDir, "app.json");
    final File device = new File(testDir, "device.json");
    final File os = new File(testDir, "os.json");
    TestUtils.writeStringToFile("minidump", minidump);
    TestUtils.writeStringToFile("metadata", metadata);
    TestUtils.writeStringToFile("session", session);
    TestUtils.writeStringToFile("app", app);
    TestUtils.writeStringToFile("device", device);
    TestUtils.writeStringToFile("os", os);
    final CrashlyticsNativeComponent mockNativeComponent = mock(CrashlyticsNativeComponent.class);
    when(mockNativeComponent.hasCrashDataForSession(anyString())).thenReturn(true);
    when(mockNativeComponent.getSessionFileProvider(anyString())).thenReturn(new NativeSessionFileProvider() {

        @Override
        public File getMinidumpFile() {
            return minidump;
        }

        @Override
        public File getBinaryImagesFile() {
            return null;
        }

        @Override
        public File getMetadataFile() {
            return metadata;
        }

        @Override
        public File getSessionFile() {
            return session;
        }

        @Override
        public File getAppFile() {
            return app;
        }

        @Override
        public File getDeviceFile() {
            return device;
        }

        @Override
        public File getOsFile() {
            return os;
        }
    });
    when(mockSessionReportingCoordinator.listSortedOpenSessionIds()).thenReturn(new TreeSet<>(Arrays.asList(sessionId, previousSessionId)).descendingSet());
    final LogFileManager logFileManager = new LogFileManager(testFileStore, sessionId);
    final CrashlyticsController controller = builder().setNativeComponent(mockNativeComponent).setLogFileManager(logFileManager).build();
    controller.finalizeSessions(testSettingsProvider);
    verify(mockSessionReportingCoordinator).finalizeSessionWithNativeEvent(eq(previousSessionId), any());
    verify(mockSessionReportingCoordinator, never()).finalizeSessionWithNativeEvent(eq(sessionId), any());
}
Also used : NativeSessionFileProvider(com.google.firebase.crashlytics.internal.NativeSessionFileProvider) TreeSet(java.util.TreeSet) Mockito.anyString(org.mockito.Mockito.anyString) File(java.io.File) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager) CrashlyticsNativeComponent(com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent)

Example 3 with NativeSessionFileProvider

use of com.google.firebase.crashlytics.internal.NativeSessionFileProvider in project GreenHouse by utsanjan.

the class CrashlyticsController method finalizePreviousNativeSession.

private void finalizePreviousNativeSession(String previousSessionId) {
    Logger logger = Logger.getLogger();
    logger.d("Finalizing native report for session " + previousSessionId);
    NativeSessionFileProvider nativeSessionFileProvider = this.nativeComponent.getSessionFileProvider(previousSessionId);
    File minidumpFile = nativeSessionFileProvider.getMinidumpFile();
    if (minidumpFile == null || !minidumpFile.exists()) {
        Logger logger2 = Logger.getLogger();
        logger2.w("No minidump data found for session " + previousSessionId);
        return;
    }
    LogFileManager previousSessionLogManager = new LogFileManager(this.context, this.logFileDirectoryProvider, previousSessionId);
    File nativeSessionDirectory = new File(getNativeSessionFilesDir(), previousSessionId);
    if (!nativeSessionDirectory.mkdirs()) {
        Logger.getLogger().d("Couldn't create native sessions directory");
        return;
    }
    List<NativeSessionFile> nativeSessionFiles = getNativeSessionFiles(nativeSessionFileProvider, previousSessionId, getContext(), getFilesDir(), previousSessionLogManager.getBytesForLog());
    NativeSessionFileGzipper.processNativeSessions(nativeSessionDirectory, nativeSessionFiles);
    this.reportingCoordinator.finalizeSessionWithNativeEvent(makeFirebaseSessionIdentifier(previousSessionId), nativeSessionFiles);
    previousSessionLogManager.clearLog();
}
Also used : NativeSessionFileProvider(com.google.firebase.crashlytics.internal.NativeSessionFileProvider) Logger(com.google.firebase.crashlytics.internal.Logger) File(java.io.File) LogFileManager(com.google.firebase.crashlytics.internal.log.LogFileManager)

Aggregations

NativeSessionFileProvider (com.google.firebase.crashlytics.internal.NativeSessionFileProvider)3 File (java.io.File)3 LogFileManager (com.google.firebase.crashlytics.internal.metadata.LogFileManager)2 CrashlyticsNativeComponent (com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent)1 Logger (com.google.firebase.crashlytics.internal.Logger)1 LogFileManager (com.google.firebase.crashlytics.internal.log.LogFileManager)1 TreeSet (java.util.TreeSet)1 Mockito.anyString (org.mockito.Mockito.anyString)1