Skip to content

Commit

Permalink
block app start if appLaunchedInForeground is not set. (#2291)
Browse files Browse the repository at this point in the history
* block app start if appLaunchedInForeground is not set.

* add changelog entry

* call public method

* fix deprecated toUpperCase to uppercase

* Update flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt

Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>

* add 60 second timeout for app starts for android native

* fix missing time imports

* rearrange line

* add comma

---------

Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>
  • Loading branch information
martinhaintz and buenaflor authored Sep 23, 2024
1 parent c26ba1d commit 48c3cf1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SentryFlutter(
}
data.getIfNotNull<String>("diagnosticLevel") {
if (options.isDebug) {
val sentryLevel = SentryLevel.valueOf(it.toUpperCase(Locale.ROOT))
val sentryLevel = SentryLevel.valueOf(it.uppercase(Locale.ROOT))
options.setDiagnosticLevel(sentryLevel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 48c3cf1

Please sign in to comment.