diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java index 5a1322fc9b6..8efd1c40187 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java @@ -43,6 +43,7 @@ import com.google.firebase.crashlytics.internal.persistence.FileStore; import com.google.firebase.crashlytics.internal.settings.Settings; import com.google.firebase.crashlytics.internal.settings.SettingsProvider; +import com.google.firebase.sessions.api.CrashEventReceiver; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FilenameFilter; @@ -189,6 +190,11 @@ synchronized void handleUncaughtException( Logger.getLogger() .d("Handling uncaught " + "exception \"" + ex + "\" from thread " + thread.getName()); + // Notify the Firebase Sessions SDK that a fatal crash has occurred. + if (!isOnDemand) { + CrashEventReceiver.notifyCrashOccurred(); + } + // Capture the time that the crash occurs and close over it so that the time doesn't // reflect when we get around to executing the task later. final long timestampMillis = System.currentTimeMillis(); diff --git a/firebase-sessions/CHANGELOG.md b/firebase-sessions/CHANGELOG.md index 70ad76eb6fe..d604327ca3d 100644 --- a/firebase-sessions/CHANGELOG.md +++ b/firebase-sessions/CHANGELOG.md @@ -1,5 +1,5 @@ # Unreleased - +* [changed] Added internal api for Crashlytics to notify Sessions of crash events # 2.1.1 * [unchanged] Updated to keep SDK versions aligned. diff --git a/firebase-sessions/api.txt b/firebase-sessions/api.txt index 5824e4febdf..58174fd4849 100644 --- a/firebase-sessions/api.txt +++ b/firebase-sessions/api.txt @@ -1,6 +1,11 @@ // Signature format: 3.0 package com.google.firebase.sessions.api { + public final class CrashEventReceiver { + method public static void notifyCrashOccurred(); + field public static final com.google.firebase.sessions.api.CrashEventReceiver INSTANCE; + } + public final class FirebaseSessionsDependencies { method public static void addDependency(com.google.firebase.sessions.api.SessionSubscriber.Name subscriberName); method public static void register(com.google.firebase.sessions.api.SessionSubscriber subscriber); diff --git a/firebase-sessions/gradle.properties b/firebase-sessions/gradle.properties index f2704e85093..b6163415afe 100644 --- a/firebase-sessions/gradle.properties +++ b/firebase-sessions/gradle.properties @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -version=2.1.3 +version=2.2.0 latestReleasedVersion=2.1.2 diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/api/CrashEventReceiver.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/api/CrashEventReceiver.kt new file mode 100644 index 00000000000..2c40e96812e --- /dev/null +++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/api/CrashEventReceiver.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2025 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.sessions.api + +/** + * Internal API used by Firebase Crashlytics to notify the Firebase Sessions SDK of fatal crashes. + * + * This object provides a static-like entry point that Crashlytics calls to inform Sessions a fatal + * crash has occurred. + */ +object CrashEventReceiver { + /** + * Notifies the Firebase Sessions SDK that a fatal crash has occurred. + * + * This method should be called by Firebase Crashlytics as soon as it detects a fatal crash. It + * safely processes the crash notification, treating the crash as a background event, to ensure + * that the session state is updated correctly. + * + * @see SharedSessionRepository.appBackground + */ + @JvmStatic + fun notifyCrashOccurred() { + // TODO(mrober): Implement in #7039 + } +}