Skip to content

Commit 48c3cf1

Browse files
block app start if appLaunchedInForeground is not set. (#2291)
* 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 <[email protected]> * add 60 second timeout for app starts for android native * fix missing time imports * rearrange line * add comma --------- Co-authored-by: Giancarlo Buenaflor <[email protected]>
1 parent c26ba1d commit 48c3cf1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Blocking app starts if "appLaunchedInForeground" is false. (Android only) ([#2291](https://github.com/getsentry/sentry-dart/pull/2291)
8+
59
### Enhancements
610

711
- Improve app start integration ([#2266](https://github.com/getsentry/sentry-dart/pull/2266))

flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SentryFlutter(
6565
}
6666
data.getIfNotNull<String>("diagnosticLevel") {
6767
if (options.isDebug) {
68-
val sentryLevel = SentryLevel.valueOf(it.toUpperCase(Locale.ROOT))
68+
val sentryLevel = SentryLevel.valueOf(it.uppercase(Locale.ROOT))
6969
options.setDiagnosticLevel(sentryLevel)
7070
}
7171
}

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

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import io.sentry.protocol.User
3434
import io.sentry.transport.CurrentDateProvider
3535
import java.io.File
3636
import java.lang.ref.WeakReference
37+
import kotlin.time.DurationUnit
38+
import kotlin.time.toDuration
3739

3840
class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
3941
private lateinit var channel: MethodChannel
@@ -171,6 +173,16 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
171173

172174
val appStartMetrics = AppStartMetrics.getInstance()
173175

176+
if (!appStartMetrics.isAppLaunchedInForeground ||
177+
appStartMetrics.appStartTimeSpan.durationMs > 1.toDuration(DurationUnit.MINUTES).inWholeMilliseconds
178+
) {
179+
Log.w(
180+
"Sentry",
181+
"Invalid app start data: app not launched in foreground or app start took too long (>60s)",
182+
)
183+
result.success(null)
184+
}
185+
174186
val appStartTimeSpan = appStartMetrics.appStartTimeSpan
175187
val appStartTime = appStartTimeSpan.startTimestamp
176188
val isColdStart = appStartMetrics.appStartType == AppStartMetrics.AppStartType.COLD

0 commit comments

Comments
 (0)