Modern Apps git

← Modern-Apps.git

all apps: add no crash test

Commit
8f1d05631fdca91614baa853743445e1642aa780
Author
vayun-mathur <[email protected]>
When
2026-10-21 07:16 UTC (1 month ago)
Parents
c7d5e26

Diff

appstore/src/androidTest/java/com/vayunmathur/appstore/ui/LaunchNoCrashTest.kt
diff --git a/appstore/src/androidTest/java/com/vayunmathur/appstore/ui/LaunchNoCrashTest.kt b/appstore/src/androidTest/java/com/vayunmathur/appstore/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..f4490086c6--- /dev/null+++ b/appstore/src/androidTest/java/com/vayunmathur/appstore/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.appstore.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the home tabs.+ *+ * Appstore hosts a five-tab pager rooted on Home; the Home tab label is always+ * composed, so the content wait keys on it.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsHomeTabs() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // home tab label is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "home tabs never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(HOME_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val HOME_TAB_LABEL = "Home"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt
diff --git a/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt b/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..5065346454--- /dev/null+++ b/astronomy/src/androidTest/java/com/vayunmathur/astronomy/ui/LaunchNoCrashTest.kt@@ -0,0 +1,93 @@+package com.vayunmathur.astronomy.ui++import android.content.pm.PackageManager+import android.os.Build+import androidx.compose.ui.test.assertCountEquals+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.v2.createEmptyComposeRule+import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.lifecycle.Lifecycle+import androidx.test.core.app.ActivityScenario+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import com.vayunmathur.astronomy.MainActivity+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Rule+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the sky map.+ *+ * Astronomy gates on FINE + COARSE location through the shared AppPermissionsGate.+ * The grant pass discovers permissions from the manifest at runtime and issues+ * headless `pm grant`s, so the gate clears without touching system UI. The sky+ * map itself is a canvas with icon-button chrome, so the test keys on the+ * Search action's content description.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @get:Rule+    val composeRule = createEmptyComposeRule()++    @Test+    fun launch_grantsPermissions_showsSkyMap() {+        grantAllRequestedPermissions()++        ActivityScenario.launch(MainActivity::class.java).use { scenario ->+            composeRule.waitUntil(timeoutMillis = CONTENT_TIMEOUT_MS) {+                try {+                    composeRule.onNodeWithContentDescription(SEARCH_ACTION).assertExists()+                    true+                } catch (ignored: AssertionError) {+                    false+                }+            }+            // Past the permission screen: the gate wall is gone and the sky+            // map chrome is showing.+            composeRule.onAllNodesWithText(PERMISSION_GATE_TITLE).assertCountEquals(0)+            composeRule.onNodeWithContentDescription(SEARCH_ACTION).assertIsDisplayed()+            // A crash during launch would fail the launch/wait above; the RESUMED+            // check makes the no-crash bar explicit.+            assertEquals(Lifecycle.State.RESUMED, scenario.state)+        }+    }++    private fun grantAllRequestedPermissions() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName+        val info = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+            targetContext.packageManager.getPackageInfo(+                packageName,+                PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong()),+            )+        } else {+            @Suppress("DEPRECATION")+            targetContext.packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        }+        val requested = info.requestedPermissions ?: return+        val uiAutomation = instrumentation.uiAutomation+        for (permission in requested) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val SEARCH_ACTION = "Search"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"+    }+}
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex d512f50a14..75ffba8ede 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -219,6 +219,9 @@ configure<com.android.build.api.dsl.ApplicationExtension> {         versionCode = appVersionCode         versionName = appVersionName         targetSdk = 37+        // Launch-no-crash tests run on-device (connectedDevAndroidTest). Mirrors+        // :library:map, the only other module with an androidTest source set.+        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"         // arm64-v8a only by default — all phones/tablets + Apple Silicon emulator are         // arm64. AGP otherwise configures buildCMakeDebug for armeabi-v7a/x86/x86_64         // which wastes time and broke when offline router's sqlite3.c was removed.@@ -307,6 +310,13 @@ configure<com.android.build.api.dsl.ApplicationExtension> {             }             // initWith(release) copied DEV_BUILD=false; dev is a developer build, so flip it on.             buildConfigField("boolean", "DEV_BUILD", "true")+            // Coverage for the launch-no-crash rollout and everything after it:+            // unit-test coverage via createDevUnitTestCoverageReport, on-device+            // coverage via the connectedDevAndroidTest + coverage report tasks.+            // Enable coverage for unit tests+            enableUnitTestCoverage = true+            // Enable coverage for instrumentation tests+            enableAndroidTestCoverage = true         }     } @@ -378,6 +388,18 @@ dependencies {      testImplementation(libs.kotlin.test)     testImplementation(libs.kotlin.test.junit)++    // Launch-no-crash tests (src/androidTest, run on-device via assemble ++    // `am instrument`). Wired once here so no app build file needs its own+    // block; modules without an androidTest source set compile nothing extra.+    // Deliberately no compose ui-test: its Espresso idle-sync reflects on+    // hidden InputManager APIs that no longer exist on current releases, so+    // every compose-rule test dies before its first line. UiDevice polling+    // covers Compose and non-Compose screens alike with no Espresso involved.+    androidTestImplementation(libs.androidx.test.runner)+    androidTestImplementation(libs.androidx.test.core)+    androidTestImplementation(libs.androidx.test.ext.junit)+    androidTestImplementation(libs.androidx.test.uiautomator) }  fun DependencyHandlerScope.justSoItShowsAsUsedSomewhere() {
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex 2d34eb55fd..e699673da3 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -33,6 +33,19 @@ configure<com.android.build.api.dsl.LibraryExtension> {         minSdk = 31     } +    buildTypes {+        named("release") {+            // Coverage for unit tests, mirroring common-conventions-app so+            // library modules report into the same per-module tasks.+            // Enable coverage for unit tests+            enableUnitTestCoverage = true+        }+        named("debug") {+            // Enable coverage for unit tests+            enableUnitTestCoverage = true+        }+    }+     lint {         // Toast is banned repo-wide. Apps also catch this transitively via         // checkDependencies, but failing here gives faster feedback when
calculator/src/androidTest/java/com/vayunmathur/calculator/ui/LaunchNoCrashTest.kt
diff --git a/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/LaunchNoCrashTest.kt b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..26cec92182--- /dev/null+++ b/calculator/src/androidTest/java/com/vayunmathur/calculator/ui/LaunchNoCrashTest.kt@@ -0,0 +1,116 @@+package com.vayunmathur.calculator.ui++import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on real content rather than sitting on a permission screen.+ *+ * Calculator declares only install-time permissions (INTERNET, VIBRATE), so the+ * grant pass is a no-op here. Gated apps copy this template verbatim: the grant+ * discovery reads the manifest at runtime, so no per-app permission list is ever+ * checked in.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsMainContent() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears (calculator has+        // none; gated apps assert the same absence to prove they cleared it).+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the keypad equals key plus a tab label.+        assertNotNull(+            "calculator keypad never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(EQUALS_KEY)), CONTENT_TIMEOUT_MS),+        )+        assertNotNull(+            "calculator tabs never appeared",+            device.wait(Until.findObject(By.text(BOTTOM_TAB_LABEL)), SHORT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: android.app.UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val SHORT_TIMEOUT_MS = 5_000L+        private const val BOTTOM_TAB_LABEL = "Calculator"+        private const val EQUALS_KEY = "="+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
calendar/src/androidTest/java/com/vayunmathur/calendar/ui/LaunchNoCrashTest.kt
diff --git a/calendar/src/androidTest/java/com/vayunmathur/calendar/ui/LaunchNoCrashTest.kt b/calendar/src/androidTest/java/com/vayunmathur/calendar/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..cf819bf5c9--- /dev/null+++ b/calendar/src/androidTest/java/com/vayunmathur/calendar/ui/LaunchNoCrashTest.kt@@ -0,0 +1,111 @@+package com.vayunmathur.calendar.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test that launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the agenda view.+ *+ * Calendar gates on READ/WRITE_CALENDAR plus exact alarms and notifications through+ * the shared AppPermissionsGate. The grant pass discovers permissions from the+ * manifest at runtime and flips the exact-alarm/full-screen-intent appops, so the+ * gate clears without touching system UI. The first screen is the calendar home,+ * which always shows the Agenda layout tab.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsAgenda() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the Agenda layout tab.+        assertNotNull(+            "agenda view never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(AGENDA_TAB)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val AGENDA_TAB = "Agenda"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
camera/src/androidTest/java/com/vayunmathur/camera/ui/LaunchNoCrashTest.kt
diff --git a/camera/src/androidTest/java/com/vayunmathur/camera/ui/LaunchNoCrashTest.kt b/camera/src/androidTest/java/com/vayunmathur/camera/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..de45cc0e43--- /dev/null+++ b/camera/src/androidTest/java/com/vayunmathur/camera/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.camera.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the viewfinder.+ *+ * Camera gates on CAMERA + RECORD_AUDIO through the shared AppPermissionsGate.+ * The grant pass discovers permissions from the manifest at runtime and issues+ * headless `pm grant`s, so the gate clears without touching system UI.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsViewfinder() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // viewfinder mode selector is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "camera viewfinder never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(MODE_PHOTO_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val MODE_PHOTO_LABEL = "Photo"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
cast/src/androidTest/java/com/vayunmathur/cast/ui/LaunchNoCrashTest.kt
diff --git a/cast/src/androidTest/java/com/vayunmathur/cast/ui/LaunchNoCrashTest.kt b/cast/src/androidTest/java/com/vayunmathur/cast/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..0056a6e55d--- /dev/null+++ b/cast/src/androidTest/java/com/vayunmathur/cast/ui/LaunchNoCrashTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.cast.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the device list.+ *+ * Cast is a single-screen app rooted on the TV picker; the launcher entry is an+ * activity-alias (LauncherAlias -> MainActivity) which getLaunchIntentForPackage+ * resolves, so the standard launch path applies. The device-list heading is always+ * composed, so the content wait keys on it.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsDeviceList() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // television picker heading is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "device list never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(DEVICES_HEADING)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val DEVICES_HEADING = "Televisions"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
clock/src/androidTest/java/com/vayunmathur/clock/ui/LaunchNoCrashTest.kt
diff --git a/clock/src/androidTest/java/com/vayunmathur/clock/ui/LaunchNoCrashTest.kt b/clock/src/androidTest/java/com/vayunmathur/clock/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..1079b38af4--- /dev/null+++ b/clock/src/androidTest/java/com/vayunmathur/clock/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.clock.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the alarms list.+ *+ * Clock gates on POST_NOTIFICATIONS (a `pm grant`-able runtime permission) plus+ * ExactAlarms and FullScreenIntent (special access, granted headlessly through+ * `appops set`). The grant pass below covers all three without touching system UI.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsAlarms() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // alarms tab is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "alarms screen never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(ALARM_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val ALARM_TAB_LABEL = "Alarm"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind clock's gate: exact alarms + full-screen intent have+         * no pm-grantable permission, but the shell can flip their appops. Ignored+         * where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
code/src/androidTest/java/com/vayunmathur/code/ui/LaunchNoCrashTest.kt
diff --git a/code/src/androidTest/java/com/vayunmathur/code/ui/LaunchNoCrashTest.kt b/code/src/androidTest/java/com/vayunmathur/code/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..4ca5db998c--- /dev/null+++ b/code/src/androidTest/java/com/vayunmathur/code/ui/LaunchNoCrashTest.kt@@ -0,0 +1,113 @@+package com.vayunmathur.code.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the editor.+ *+ * Code gates first launch on all-files special access (MANAGE_EXTERNAL_STORAGE)+ * through the shared AppPermissionsGate. The grant pass discovers permissions+ * from the manifest at runtime and issues headless `pm grant`s plus appops for+ * special access, so the gate clears without touching system UI.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsEditor() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // empty editor state is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "editor never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(EMPTY_EDITOR_TEXT)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val EMPTY_EDITOR_TEXT = "No file open"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Code has no launcher permission dialog for all-files access (settings+         * page only), so MANAGE_EXTERNAL_STORAGE is flipped the same way.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+            "appops set --uid %s MANAGE_EXTERNAL_STORAGE allow",+        )+    }+}
communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt
diff --git a/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt b/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..157fa538f5--- /dev/null+++ b/communicate/src/androidTest/java/com/vayunmathur/communicate/ui/LaunchNoCrashTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.communicate.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the messages tab.+ *+ * Communicate gates SMS, call-log and contacts access through the shared+ * AppPermissionsGate. The grant pass discovers permissions from the manifest+ * at runtime and issues headless `pm grant`s, so the gate clears without+ * touching system UI.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsMessages() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Messages bottom-nav tab is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "messages tab never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(MESSAGES_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val MESSAGES_TAB_LABEL = "Messages"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
contacts/src/androidTest/java/com/vayunmathur/contacts/ui/LaunchNoCrashTest.kt
diff --git a/contacts/src/androidTest/java/com/vayunmathur/contacts/ui/LaunchNoCrashTest.kt b/contacts/src/androidTest/java/com/vayunmathur/contacts/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..f9cee8dcb8--- /dev/null+++ b/contacts/src/androidTest/java/com/vayunmathur/contacts/ui/LaunchNoCrashTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.contacts.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the contacts list.+ *+ * Contacts gates on READ/WRITE_CONTACTS + CALL_PHONE + READ_PHONE_STATE through+ * the shared AppPermissionsGate. The grant pass discovers permissions from the+ * manifest at runtime and issues headless `pm grant`s, so the gate clears+ * without touching system UI.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsContactsList() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // contacts list search field is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "contacts list never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(SEARCH_PLACEHOLDER)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val SEARCH_PLACEHOLDER = "Search contacts"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt
diff --git a/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt b/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..c0ec6c162f--- /dev/null+++ b/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.education.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the Learn catalog.+ *+ * Education loads its bundled content packs before the catalog paints, so the+ * marker wait covers that load. A fresh install has a blank learner name, so+ * the home title reads Learn.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsLearnCatalog() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Learn catalog title is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "learn catalog never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(LEARN_TITLE)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val LEARN_TITLE = "Learn"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
email/src/androidTest/java/com/vayunmathur/email/ui/LaunchNoCrashTest.kt
diff --git a/email/src/androidTest/java/com/vayunmathur/email/ui/LaunchNoCrashTest.kt b/email/src/androidTest/java/com/vayunmathur/email/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..52fb1f6439--- /dev/null+++ b/email/src/androidTest/java/com/vayunmathur/email/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.email.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto account setup.+ *+ * A fresh install has no accounts, so MainContent shows the Add Account screen+ * before the inbox. The marker asserts that stable setup title rather than any+ * message content.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsAccountSetup() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Add Account setup title is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "account setup never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(ADD_ACCOUNT_TITLE)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val ADD_ACCOUNT_TITLE = "Add Account"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
everysync/src/androidTest/java/com/vayunmathur/everysync/ui/LaunchNoCrashTest.kt
diff --git a/everysync/src/androidTest/java/com/vayunmathur/everysync/ui/LaunchNoCrashTest.kt b/everysync/src/androidTest/java/com/vayunmathur/everysync/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..8a3256e192--- /dev/null+++ b/everysync/src/androidTest/java/com/vayunmathur/everysync/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.everysync.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the accounts list.+ *+ * A fresh install has no accounts, so the marker asserts the accounts-list+ * empty state rather than any account row.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsAccountsList() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // accounts-list empty state is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "accounts list never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(NO_ACCOUNTS_TEXT)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val NO_ACCOUNTS_TEXT = "No accounts yet. Tap + to add one."+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
files/src/androidTest/java/com/vayunmathur/files/ui/LaunchNoCrashTest.kt
diff --git a/files/src/androidTest/java/com/vayunmathur/files/ui/LaunchNoCrashTest.kt b/files/src/androidTest/java/com/vayunmathur/files/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..fc9593b746--- /dev/null+++ b/files/src/androidTest/java/com/vayunmathur/files/ui/LaunchNoCrashTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.files.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on real content rather than sitting on a permission screen.+ *+ * Files has no runtime-permission gate in MainActivity, so the grant pass only+ * covers what the manifest declares. The first screen is the directory listing,+ * titled "Internal storage" for the default location.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsDirectory() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears (files has+        // none; gated apps assert the same absence to prove they cleared it).+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the default directory title.+        assertNotNull(+            "directory listing never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(DIRECTORY_TITLE)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val DIRECTORY_TITLE = "Internal storage"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
findfamily/src/androidTest/java/com/vayunmathur/findfamily/ui/LaunchNoCrashTest.kt
diff --git a/findfamily/src/androidTest/java/com/vayunmathur/findfamily/ui/LaunchNoCrashTest.kt b/findfamily/src/androidTest/java/com/vayunmathur/findfamily/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..d1c7ff430e--- /dev/null+++ b/findfamily/src/androidTest/java/com/vayunmathur/findfamily/ui/LaunchNoCrashTest.kt@@ -0,0 +1,111 @@+package com.vayunmathur.findfamily.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the family map.+ *+ * FindFamily gates on foreground + background location + BLUETOOTH_SCAN through+ * the shared AppPermissionsGate (three runtime batches). The grant pass+ * discovers permissions from the manifest at runtime and issues headless+ * `pm grant`s, so the gate clears without touching system UI. The marker is the+ * family-list sheet's "Saved Places" section header.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsFamilyMap() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // family-list sheet section is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "family map never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(SHEET_SECTION)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val SHEET_SECTION = "Saved Places"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
flashcards/src/androidTest/java/com/vayunmathur/flashcards/ui/LaunchNoCrashTest.kt
diff --git a/flashcards/src/androidTest/java/com/vayunmathur/flashcards/ui/LaunchNoCrashTest.kt b/flashcards/src/androidTest/java/com/vayunmathur/flashcards/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..ef0e10383e--- /dev/null+++ b/flashcards/src/androidTest/java/com/vayunmathur/flashcards/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.flashcards.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the decks tab.+ *+ * A fresh install has no decks, so the marker asserts the decks-tab empty+ * state rather than any deck row.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsDecksTab() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // decks-tab empty state is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "decks tab never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(NO_DECKS_TEXT)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val NO_DECKS_TEXT = "No decks yet"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
fooddelivery/src/androidTest/java/com/vayunmathur/fooddelivery/ui/LaunchNoCrashTest.kt
diff --git a/fooddelivery/src/androidTest/java/com/vayunmathur/fooddelivery/ui/LaunchNoCrashTest.kt b/fooddelivery/src/androidTest/java/com/vayunmathur/fooddelivery/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..f7f93535cb--- /dev/null+++ b/fooddelivery/src/androidTest/java/com/vayunmathur/fooddelivery/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.fooddelivery.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the home tab.+ *+ * The five bottom-nav tabs paint without sign-in, so the marker asserts the+ * Home tab label rather than any signed-in content.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsHomeTab() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Home bottom-nav tab is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "home tab never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(HOME_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val HOME_TAB_LABEL = "Home"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/arrows/src/androidTest/java/com/vayunmathur/games/arrows/ui/LaunchNoCrashTest.kt
diff --git a/games/arrows/src/androidTest/java/com/vayunmathur/games/arrows/ui/LaunchNoCrashTest.kt b/games/arrows/src/androidTest/java/com/vayunmathur/games/arrows/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..42ad1283b1--- /dev/null+++ b/games/arrows/src/androidTest/java/com/vayunmathur/games/arrows/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.games.arrows.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the game board.+ *+ * Arrows boots straight into the board with the mode selector on top, so the+ * marker asserts the Levels mode label rather than any board state.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsBoard() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Levels mode label is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "arrows board never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(MODE_LEVELS_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val MODE_LEVELS_LABEL = "Levels"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/chess/src/androidTest/java/com/vayunmathur/games/chess/ui/LaunchNoCrashTest.kt
diff --git a/games/chess/src/androidTest/java/com/vayunmathur/games/chess/ui/LaunchNoCrashTest.kt b/games/chess/src/androidTest/java/com/vayunmathur/games/chess/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..b9fa8080ea--- /dev/null+++ b/games/chess/src/androidTest/java/com/vayunmathur/games/chess/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.games.chess.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the offline board.+ *+ * Chess boots into the offline game with the four bottom-bar tabs below it,+ * so the marker asserts the Offline Play tab label rather than any board+ * or online state.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsOfflineTab() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Offline Play bottom-bar tab is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "offline tab never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(OFFLINE_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val OFFLINE_TAB_LABEL = "Offline Play"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/hub/src/androidTest/java/com/vayunmathur/games/hub/ui/LaunchNoCrashTest.kt
diff --git a/games/hub/src/androidTest/java/com/vayunmathur/games/hub/ui/LaunchNoCrashTest.kt b/games/hub/src/androidTest/java/com/vayunmathur/games/hub/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..8f836353b0--- /dev/null+++ b/games/hub/src/androidTest/java/com/vayunmathur/games/hub/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.games.hub.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the games list.+ *+ * GameHub boots into the Home/Games pager; an empty hub shows the stable+ * no-games empty state rather than any game row.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsGamesTab() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Games bottom-nav tab is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "games tab never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(GAMES_TAB_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val GAMES_TAB_LABEL = "Games"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/kart/src/androidTest/java/com/vayunmathur/games/kart/ui/LaunchNoCrashTest.kt
diff --git a/games/kart/src/androidTest/java/com/vayunmathur/games/kart/ui/LaunchNoCrashTest.kt b/games/kart/src/androidTest/java/com/vayunmathur/games/kart/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..77c422b5f2--- /dev/null+++ b/games/kart/src/androidTest/java/com/vayunmathur/games/kart/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.games.kart.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the garage.+ *+ * Kart boots into the garage lobby with the Start Race button on top, so the+ * marker asserts that stable button label rather than any race state.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsGarage() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // Start Race button is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "kart garage never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(START_RACE_LABEL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val START_RACE_LABEL = "Start Race"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/logicgate/src/androidTest/java/com/vayunmathur/games/logicgate/ui/LaunchNoCrashTest.kt
diff --git a/games/logicgate/src/androidTest/java/com/vayunmathur/games/logicgate/ui/LaunchNoCrashTest.kt b/games/logicgate/src/androidTest/java/com/vayunmathur/games/logicgate/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..5e5cf00a8c--- /dev/null+++ b/games/logicgate/src/androidTest/java/com/vayunmathur/games/logicgate/ui/LaunchNoCrashTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.games.logicgate.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it gets past the permission screen onto the level map.+ *+ * LogicGate boots into the progression map, so the marker asserts the stable+ * NAND-to-computer subtitle rather than any level-node state.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsLevelMap() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears and the+        // progression subtitle is showing.+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        assertNotNull(+            "level map never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(PROGRESSION_SUBTITLE)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val PROGRESSION_SUBTITLE = "Start with NAND. End with a computer."+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/minesweeper/src/androidTest/java/com/vayunmathur/games/minesweeper/ui/LaunchNoCrashTest.kt
diff --git a/games/minesweeper/src/androidTest/java/com/vayunmathur/games/minesweeper/ui/LaunchNoCrashTest.kt b/games/minesweeper/src/androidTest/java/com/vayunmathur/games/minesweeper/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..b81ea7c416--- /dev/null+++ b/games/minesweeper/src/androidTest/java/com/vayunmathur/games/minesweeper/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.games.minesweeper.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on the home menu rather than sitting on a permission screen.+ *+ * Minesweeper starts at Route.Home with a New Game button; stats cards render+ * from the local repository, so no gate or loading state stands in the way.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsHome() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears (minesweeper+        // has none; gated apps assert the same absence to prove they cleared it).+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the home menu's New Game button.+        assertNotNull(+            "minesweeper home never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(NEW_GAME_BUTTON)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val NEW_GAME_BUTTON = "New Game"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/nonogram/src/androidTest/java/com/vayunmathur/games/nonogram/ui/LaunchNoCrashTest.kt
diff --git a/games/nonogram/src/androidTest/java/com/vayunmathur/games/nonogram/ui/LaunchNoCrashTest.kt b/games/nonogram/src/androidTest/java/com/vayunmathur/games/nonogram/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..fd64e864ca--- /dev/null+++ b/games/nonogram/src/androidTest/java/com/vayunmathur/games/nonogram/ui/LaunchNoCrashTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.games.nonogram.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on the puzzle board rather than sitting on a permission screen.+ *+ * Nonogram starts directly at Route.Game: the top-bar title folds in the level+ * number (dynamic text), so the marker is the Fill mode-toggle segment, a stable+ * literal that is always on screen once the board paints.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsGame() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears (nonogram+        // has none; gated apps assert the same absence to prove they cleared it).+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the board's Fill mode toggle.+        assertNotNull(+            "nonogram board never appeared; the app may have crashed on launch",+            device.wait(Until.findObject(By.text(MARK_MODE_FILL)), CONTENT_TIMEOUT_MS),+        )+        // Still alive in front: the process did not crash after painting content.+        assertEquals(packageName, device.currentPackageName)+    }++    private fun grantAllRequestedPermissions(+        uiAutomation: UiAutomation,+        packageManager: PackageManager,+        packageName: String,+    ) {+        val info = try {+            packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)+        } catch (e: PackageManager.NameNotFoundException) {+            throw AssertionError("package $packageName not installed", e)+        }+        for (permission in info.requestedPermissions.orEmpty()) {+            try {+                uiAutomation.executeShellCommand("pm grant $packageName $permission").close()+            } catch (ignored: SecurityException) {+                // Not a headlessly grantable permission: nothing to do.+            } catch (ignored: IOException) {+                // Shell pipe failed: the permission stays ungranted and the+                // content assertions below report it.+            }+        }+        for (command in SPECIAL_ACCESS_COMMANDS) {+            try {+                uiAutomation.executeShellCommand(command.format(packageName)).close()+            } catch (ignored: SecurityException) {+                // Appop missing on this release: the gate assertion reports it.+            } catch (ignored: IOException) {+                // Shell pipe failed: the gate assertion below reports it.+            }+        }+    }++    private companion object {+        private const val CONTENT_TIMEOUT_MS = 15_000L+        private const val GATE_TIMEOUT_MS = 5_000L+        private const val MARK_MODE_FILL = "Fill"+        private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"++        /**+         * Special access behind some apps' gates: exact alarms + full-screen intent+         * have no pm-grantable permission, but the shell can flip their appops.+         * Ignored where the appop does not exist; the gate assertion reports it.+         */+        private val SPECIAL_ACCESS_COMMANDS = arrayOf(+            "appops set %s SCHEDULE_EXACT_ALARM allow",+            "appops set %s USE_FULL_SCREEN_INTENT allow",+        )+    }+}
games/pipes/src/androidTest/java/com/vayunmathur/games/pipes/ui/LaunchNoCrashTest.kt
diff --git a/games/pipes/src/androidTest/java/com/vayunmathur/games/pipes/ui/LaunchNoCrashTest.kt b/games/pipes/src/androidTest/java/com/vayunmathur/games/pipes/ui/LaunchNoCrashTest.ktnew file mode 100644index 0000000000..789f065880--- /dev/null+++ b/games/pipes/src/androidTest/java/com/vayunmathur/games/pipes/ui/LaunchNoCrashTest.kt@@ -0,0 +1,109 @@+package com.vayunmathur.games.pipes.ui++import android.app.UiAutomation+import android.content.Intent+import android.content.pm.PackageManager+import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import androidx.test.uiautomator.By+import androidx.test.uiautomator.UiDevice+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Launch-no-crash test: launches the app, grants every requested permission, and+ * asserts it lands on the pack list rather than sitting on a permission screen.+ *+ * Pipes starts at Route.PackSelector, whose title is the stable Pack Select+ * literal; pack rows themselves carry dynamic progress counts.+ *+ * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on+ * hidden InputManager APIs that no longer exist on current releases, so every+ * compose-rule test dies before its first line. Text polling works for Compose+ * and non-Compose screens alike.+ */+@RunWith(AndroidJUnit4::class)+class LaunchNoCrashTest {++    @Test+    fun launch_grantsPermissions_showsPackList() {+        val instrumentation = InstrumentationRegistry.getInstrumentation()+        val device = UiDevice.getInstance(instrumentation)+        val targetContext = instrumentation.targetContext+        val packageName = targetContext.packageName++        grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)++        val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)+        assertNotNull("no launcher intent for $packageName", intent)+        intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+        targetContext.startActivity(intent)++        // Past the permission screen: the gate wall never appears (pipes has+        // none; gated apps assert the same absence to prove they cleared it).+        assertNull(+            "permission gate is showing; grants did not clear it",+            device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS),+        )+        // Main content is actually visible: the pack selector title.+       

Diff truncated.