Skip to content

Commit d48029b

Browse files
romtsnclaude
andcommitted
fix(test): Check notification permission before launching request to fix flaky API 34 tests
On API 34, Maestro's `permissions: all: allow` pre-grants POST_NOTIFICATIONS via `pm grant`. The ActivityResult callback from `requestPermissionLauncher` is not always reliably invoked when the permission is already granted, causing the notification to never be posted. This adds a checkSelfPermission guard so the notification is posted directly when already permitted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 01221e2 commit d48029b

File tree

1 file changed

+9
-1
lines changed
  • sentry-android-integration-tests/sentry-uitest-android-critical/src/main/java/io/sentry/uitest/android/critical

1 file changed

+9
-1
lines changed

sentry-android-integration-tests/sentry-uitest-android-critical/src/main/java/io/sentry/uitest/android/critical/MainActivity.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.uitest.android.critical
22

33
import android.content.Intent
4+
import android.content.pm.PackageManager
45
import android.os.Build
56
import android.os.Bundle
67
import android.widget.Toast
@@ -22,6 +23,7 @@ import androidx.compose.runtime.remember
2223
import androidx.compose.runtime.setValue
2324
import androidx.compose.ui.Modifier
2425
import androidx.compose.ui.unit.dp
26+
import androidx.core.content.ContextCompat
2527
import io.sentry.Sentry
2628
import io.sentry.android.core.performance.AppStartMetrics
2729
import io.sentry.uitest.android.critical.NotificationHelper.showNotification
@@ -82,7 +84,13 @@ class MainActivity : ComponentActivity() {
8284
Button(onClick = { finish() }) { Text("Finish Activity") }
8385
Button(
8486
onClick = {
85-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
87+
if (
88+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
89+
ContextCompat.checkSelfPermission(
90+
this@MainActivity,
91+
android.Manifest.permission.POST_NOTIFICATIONS,
92+
) != PackageManager.PERMISSION_GRANTED
93+
) {
8694
requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS)
8795
} else {
8896
postNotification()

0 commit comments

Comments
 (0)