diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d7b75b7bf..f7944fdfa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Blocking app starts if "appLaunchedInForeground" is false. (Android only) ([#2291](https://github.com/getsentry/sentry-dart/pull/2291) + ### Enhancements - Improve app start integration ([#2266](https://github.com/getsentry/sentry-dart/pull/2266)) diff --git a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt index d38872f6ee..4e11cf5cf5 100644 --- a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt +++ b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt @@ -65,7 +65,7 @@ class SentryFlutter( } data.getIfNotNull("diagnosticLevel") { if (options.isDebug) { - val sentryLevel = SentryLevel.valueOf(it.toUpperCase(Locale.ROOT)) + val sentryLevel = SentryLevel.valueOf(it.uppercase(Locale.ROOT)) options.setDiagnosticLevel(sentryLevel) } } diff --git a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt index a10966fd50..a6d4516152 100644 --- a/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt +++ b/flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt @@ -34,6 +34,8 @@ import io.sentry.protocol.User import io.sentry.transport.CurrentDateProvider import java.io.File import java.lang.ref.WeakReference +import kotlin.time.DurationUnit +import kotlin.time.toDuration class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { private lateinit var channel: MethodChannel @@ -171,6 +173,16 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { val appStartMetrics = AppStartMetrics.getInstance() + if (!appStartMetrics.isAppLaunchedInForeground || + appStartMetrics.appStartTimeSpan.durationMs > 1.toDuration(DurationUnit.MINUTES).inWholeMilliseconds + ) { + Log.w( + "Sentry", + "Invalid app start data: app not launched in foreground or app start took too long (>60s)", + ) + result.success(null) + } + val appStartTimeSpan = appStartMetrics.appStartTimeSpan val appStartTime = appStartTimeSpan.startTimestamp val isColdStart = appStartMetrics.appStartType == AppStartMetrics.AppStartType.COLD