Skip to content

Commit c09e9cc

Browse files
authored
Add internal api for Crashlytics to notify Sessions of crash events (#7114)
1 parent 7c56ee1 commit c09e9cc

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.google.firebase.crashlytics.internal.persistence.FileStore;
4444
import com.google.firebase.crashlytics.internal.settings.Settings;
4545
import com.google.firebase.crashlytics.internal.settings.SettingsProvider;
46+
import com.google.firebase.sessions.api.CrashEventReceiver;
4647
import java.io.ByteArrayOutputStream;
4748
import java.io.File;
4849
import java.io.FilenameFilter;
@@ -189,6 +190,11 @@ synchronized void handleUncaughtException(
189190
Logger.getLogger()
190191
.d("Handling uncaught " + "exception \"" + ex + "\" from thread " + thread.getName());
191192

193+
// Notify the Firebase Sessions SDK that a fatal crash has occurred.
194+
if (!isOnDemand) {
195+
CrashEventReceiver.notifyCrashOccurred();
196+
}
197+
192198
// Capture the time that the crash occurs and close over it so that the time doesn't
193199
// reflect when we get around to executing the task later.
194200
final long timestampMillis = System.currentTimeMillis();

firebase-sessions/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Unreleased
2-
2+
* [changed] Added internal api for Crashlytics to notify Sessions of crash events
33

44
# 2.1.1
55
* [unchanged] Updated to keep SDK versions aligned.

firebase-sessions/api.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Signature format: 3.0
22
package com.google.firebase.sessions.api {
33

4+
public final class CrashEventReceiver {
5+
method public static void notifyCrashOccurred();
6+
field public static final com.google.firebase.sessions.api.CrashEventReceiver INSTANCE;
7+
}
8+
49
public final class FirebaseSessionsDependencies {
510
method public static void addDependency(com.google.firebase.sessions.api.SessionSubscriber.Name subscriberName);
611
method public static void register(com.google.firebase.sessions.api.SessionSubscriber subscriber);

firebase-sessions/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=2.1.3
15+
version=2.2.0
1616
latestReleasedVersion=2.1.2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.sessions.api
18+
19+
/**
20+
* Internal API used by Firebase Crashlytics to notify the Firebase Sessions SDK of fatal crashes.
21+
*
22+
* This object provides a static-like entry point that Crashlytics calls to inform Sessions a fatal
23+
* crash has occurred.
24+
*/
25+
object CrashEventReceiver {
26+
/**
27+
* Notifies the Firebase Sessions SDK that a fatal crash has occurred.
28+
*
29+
* This method should be called by Firebase Crashlytics as soon as it detects a fatal crash. It
30+
* safely processes the crash notification, treating the crash as a background event, to ensure
31+
* that the session state is updated correctly.
32+
*
33+
* @see SharedSessionRepository.appBackground
34+
*/
35+
@JvmStatic
36+
fun notifyCrashOccurred() {
37+
// TODO(mrober): Implement in #7039
38+
}
39+
}

0 commit comments

Comments
 (0)