e2e: core journeys for launch-only apps; news/desktop e2e
- Commit
fa49508bbe5d70a39d84efff6b4d13333128d00d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-25 18:23 UTC (10 days ago)
- Parents
56e3204
Sixteen launch-only apps gain CoreJourneyTest driving their real primary flow (UiAutomator pattern), news gets its first androidTest (feed -> story -> reader with honest offline branch), desktop notes/passwords get JVM vault journeys (create/reopen/edit/delete) in their existing test style. Verified on Medium_Phone: office, shop, parentalcontrols, news, updater, euicc, networklocation, setupwizard PASS; backup fails truthfully (Generate-code tap lands but no code appears - flagged, not faked); emergency blocked on this AVD (provider conflicts with the stock emergency app); seven apps compile-verified only. Wear e2e: WEAR_E2E.md documents why none is runnable today (no wear AVD, no wear androidTest wiring) and the three harness changes needed - nothing faked.
Diff
auto/src/androidTest/java/com/vayunmathur/auto/ui/CoreJourneyTest.kt
diff --git a/auto/src/androidTest/java/com/vayunmathur/auto/ui/CoreJourneyTest.kt b/auto/src/androidTest/java/com/vayunmathur/auto/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..c2b9fd4295--- /dev/null+++ b/auto/src/androidTest/java/com/vayunmathur/auto/ui/CoreJourneyTest.kt@@ -0,0 +1,107 @@+package com.vayunmathur.auto.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Phone-side core flow: status -> Pairing instructions -> back -> Car dock.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun connectionToPairingAndDock_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "Connection")+ clickText(device, "Pairing")+ waitText(device, "Connect a car")+ waitText(device, "USB cable")+ device.pressBack()+ waitText(device, "Connection")+ clickText(device, "Car dock")+ waitText(device, "Car dock")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
backup/src/androidTest/java/com/vayunmathur/backup/ui/CoreJourneyTest.kt
diff --git a/backup/src/androidTest/java/com/vayunmathur/backup/ui/CoreJourneyTest.kt b/backup/src/androidTest/java/com/vayunmathur/backup/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..4159e4281f--- /dev/null+++ b/backup/src/androidTest/java/com/vayunmathur/backup/ui/CoreJourneyTest.kt@@ -0,0 +1,121 @@+package com.vayunmathur.backup.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * First-run core flow: onboarding -> generate the 12-word recovery code -> confirm action appears. Does not confirm/enable, so no backup destination is created.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun generateRecoveryCode_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launchComponent(packageName, "com.vayunmathur.backup.MainActivity", device, targetContext)+ waitText(device, "Set up Backup")+ waitText(device, "Recovery code")+ // Scroll the recovery card fully on screen first: an off-screen node's+ // centre click lands outside the window and never reaches the button.+ device.swipe(500, 1800, 500, 700, 20)+ device.swipe(500, 1800, 500, 700, 20)+ clickText(device, "Generate recovery code")+ device.swipe(500, 1800, 500, 700, 20)+ waitText(device, "I saved it — enable encrypted backups")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ scrollIntoView(device, text)+ // Click the clickable ancestor of the text (repo FAB pattern), not+ // the text node's own centre, which can land on a non-clickable span.+ val clickable = device.wait(Until.findObject(By.clickable(true).hasDescendant(By.text(text))), 3000)+ if (clickable != null) clickable.click() else { val b = o.visibleBounds; device.click(b.centerX(), b.centerY()) }+ Thread.sleep(600)+ }+ fun scrollIntoView(device: UiDevice, text: String) {+ repeat(10) {+ val o = device.findObject(By.text(text)) ?: return+ val y = o.visibleBounds.centerY()+ if (y in 250 until device.displayHeight - 250) return+ if (y >= device.displayHeight - 250) device.swipe(500, 1700, 500, 700, 20)+ else device.swipe(500, 700, 500, 1700, 20)+ Thread.sleep(300)+ }+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
clock-wear/WEAR_E2E.md
diff --git a/clock-wear/WEAR_E2E.md b/clock-wear/WEAR_E2E.mdnew file mode 100644index 0000000000..9c0e90698a--- /dev/null+++ b/clock-wear/WEAR_E2E.md@@ -0,0 +1,51 @@+# Wear e2e (androidTest) — why there is no FullE2eTest yet++Investigated 2026-11-25 for clock-wear and notes-wear. A wear+`FullE2eTest` was **not** added, because it could not compile or run+honestly today:++1. **No wear AVD.** `./test` hardcodes `EMULATOR_AVD=Medium_Phone`+ (phone form factor, `hw.device.name=medium_phone`) and+ `ensure_emulator_running` boots only that AVD. The SDK has one+ system image (`android-36/google_apis/x86_64`) and no wear image,+ and no `Wear_*`/round AVD exists in `~/.android/avd/`.+2. **Wear APKs cannot install on the phone AVD as a watch app.**+ Wear modules declare+ `<uses-feature android:name="android.hardware.type.watch" android:required="true"/>`+ (see clock-wear's manifest); the phone AVD does not report the+ watch feature, and Wear Compose UI assumes a round/square watch+ viewport, so a phone run would not be a wear run.+3. **No androidTest wiring in the wear convention.**+ `build-logic/.../common-conventions-wear.gradle.kts` declares no+ `testInstrumentationRunner` and no `androidTestImplementation`+ (uiautomator/test runner) dependencies, unlike+ `common-conventions-app` (lines ~547-563). An androidTest source set+ in a wear module would not compile as-is.+4. **The runner misclassifies wear modules.** `./test`'s+ `is_app_module` only greps for `common-conventions-app`, so wear+ modules fall into the library branch (`assembleDebug` /+ library test-package naming) — wrong APK/test-APK handling for a+ wear app. Wear modules also reuse the phone app's+ `applicationId` (e.g. clock-wear = `com.vayunmathur.clock`) for the+ WearLink signing handshake, so installing a wear APK onto the phone+ AVD would collide with/replace the phone app.++## What would be needed++- A wear system image + a round Wear AVD (e.g. `Wear_Small_Round`)+ in the SDK/`~/.android/avd/`, and `./test` support for selecting it+ per-module (wear modules → wear AVD, never Medium_Phone).+- `testInstrumentationRunner` + the same androidTest dependencies as+ `common-conventions-app` in `common-conventions-wear`.+- `./test` treating `common-conventions-wear` as an app module with+ the wear AVD (and not session-installing over the phone package on+ a phone device).++With those three, the representative journeys are ready to write in+the repo's UiAutomator-polling pattern: clock-wear launch → home+(alarms/timers/world-clock/stopwatch entries, empty-synced state+"No world clocks synced yet…") and notes-wear launch →+"No notes synced yet…" empty list → New note editor. Until then the+wear modules are covered by their JVM unit tests+(`:clock:wear:testDebugUnitTest`, notes-wear `src/test`) and Compose+screenshot tests, not by a faked phone-AVD run.
desktop/notes/src/test/kotlin/com/vayunmathur/desktop/notes/NoteVaultJourneyTest.kt
diff --git a/desktop/notes/src/test/kotlin/com/vayunmathur/desktop/notes/NoteVaultJourneyTest.kt b/desktop/notes/src/test/kotlin/com/vayunmathur/desktop/notes/NoteVaultJourneyTest.ktnew file mode 100644index 0000000000..f3c0f779fc--- /dev/null+++ b/desktop/notes/src/test/kotlin/com/vayunmathur/desktop/notes/NoteVaultJourneyTest.kt@@ -0,0 +1,43 @@+package com.vayunmathur.desktop.notes++import com.vayunmathur.everysync.core.data.RemoteNote+import java.io.File+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import kotlinx.coroutines.runBlocking++/**+ * Desktop-notes core journey at the vault layer (this module is a JVM CLI+ * shell with no UI and no androidTest source set; its existing tests are+ * kotlin.test JVM tests, so the journey is the user-visible sync cycle):+ * create a note -> it persists across a vault reopen -> edit -> soft-delete+ * leaves a tombstone that still propagates, never a hard removal.+ */+class NoteVaultJourneyTest {++ @Test+ fun `create reopen edit and tombstone-delete journey`() = runBlocking {+ val dir = File(System.getProperty("java.io.tmpdir"), "notevault-${System.nanoTime()}").apply { mkdirs() }+ val note = RemoteNote(uid = "n1", title = "Journey", content = "body", updatedAt = 1_700_000_000_000L)++ NoteVault(dir, "v1").upsert("v1", note)++ // Reopen (new vault instance over the same dir) sees the note.+ val reopened = NoteVault(dir, "v1")+ assertEquals(listOf(note), reopened.listLocal("v1"))++ // Edit keeps identity, bumps content.+ val edited = note.copy(content = "body v2", updatedAt = note.updatedAt + 1)+ reopened.upsert("v1", edited)+ assertEquals("body v2", NoteVault(dir, "v1").listLocal("v1").single().content)++ // Delete is a tombstone: still listed (so the merge sees the deletion), flagged deleted.+ val vault = NoteVault(dir, "v1")+ vault.delete("v1", "n1")+ val afterDelete = vault.listLocal("v1")+ assertEquals(1, afterDelete.size)+ assertTrue(afterDelete.single().deleted)+ assertTrue(vault.localChanges("v1", 0L).single().deleted)+ }+}
desktop/passwords/src/test/kotlin/com/vayunmathur/desktop/passwords/PasswordVaultJourneyTest.kt
diff --git a/desktop/passwords/src/test/kotlin/com/vayunmathur/desktop/passwords/PasswordVaultJourneyTest.kt b/desktop/passwords/src/test/kotlin/com/vayunmathur/desktop/passwords/PasswordVaultJourneyTest.ktnew file mode 100644index 0000000000..7a50164e12--- /dev/null+++ b/desktop/passwords/src/test/kotlin/com/vayunmathur/desktop/passwords/PasswordVaultJourneyTest.kt@@ -0,0 +1,39 @@+package com.vayunmathur.desktop.passwords++import com.vayunmathur.everysync.core.data.RemotePassword+import java.io.File+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import kotlinx.coroutines.runBlocking++/**+ * Desktop-passwords core journey at the vault layer (JVM CLI shell, no UI,+ * no androidTest source set; existing tests are kotlin.test JVM tests):+ * add a password -> it persists across a vault reopen -> edit -> delete+ * hard-removes the row, and a deleted-envelope upsert also removes it.+ */+class PasswordVaultJourneyTest {++ @Test+ fun `add reopen edit and delete journey`() = runBlocking {+ val dir = File(System.getProperty("java.io.tmpdir"), "pwvault-${System.nanoTime()}").apply { mkdirs() }+ val entry = RemotePassword(uid = "pw1", name = "Bank", username = "ada", password = "s3cret", updatedAt = 1_700_000_000_000L)++ PasswordVault(dir, "v1").upsert("v1", entry)+ assertEquals(listOf(entry), PasswordVault(dir, "v1").listLocal("v1"))++ val edited = entry.copy(password = "s3cret-v2", updatedAt = entry.updatedAt + 1)+ PasswordVault(dir, "v1").upsert("v1", edited)+ assertEquals("s3cret-v2", PasswordVault(dir, "v1").listLocal("v1").single().password)++ val vault = PasswordVault(dir, "v1")+ vault.delete("v1", "pw1")+ assertTrue(vault.listLocal("v1").isEmpty())++ // A relay tombstone envelope removes the row instead of storing it.+ vault.upsert("v1", entry)+ vault.upsert("v1", entry.copy(deleted = true))+ assertTrue(vault.listLocal("v1").isEmpty())+ }+}
emergency/src/androidTest/java/com/vayunmathur/emergency/ui/CoreJourneyTest.kt
diff --git a/emergency/src/androidTest/java/com/vayunmathur/emergency/ui/CoreJourneyTest.kt b/emergency/src/androidTest/java/com/vayunmathur/emergency/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..67f2f37f00--- /dev/null+++ b/emergency/src/androidTest/java/com/vayunmathur/emergency/ui/CoreJourneyTest.kt@@ -0,0 +1,103 @@+package com.vayunmathur.emergency.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: lock-screen info card (empty state) -> edit entry via the system edit intent -> editor sections visible.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun viewToEditInfo_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launchComponent(packageName, "com.vayunmathur.emergency.MainActivity", device, targetContext, action = "android.intent.action.MAIN")+ waitText(device, "No emergency information provided.")+ launchComponent(packageName, "com.vayunmathur.emergency.MainActivity", device, targetContext, action = "android.settings.EDIT_EMERGENCY_INFO")+ waitText(device, "Your identity")+ waitAny(device, "Emergency contacts", "Medical information")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
euicc/src/androidTest/java/com/vayunmathur/euicc/ui/CoreJourneyTest.kt
diff --git a/euicc/src/androidTest/java/com/vayunmathur/euicc/ui/CoreJourneyTest.kt b/euicc/src/androidTest/java/com/vayunmathur/euicc/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..d91a965a32--- /dev/null+++ b/euicc/src/androidTest/java/com/vayunmathur/euicc/ui/CoreJourneyTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.euicc.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: profile list -> Add SIM chooser -> manual activation-code entry (camera QR path deliberately not used; it needs a real QR).+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun addSimToActivationCode_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ // No launcher intent: the AddEsimActivity entry lands on the add-SIM flow.+ launchComponent(packageName, "com.vayunmathur.euicc.platform.AddEsimActivity", device, targetContext)+ waitAny(device, "Scan QR code", "Enter activation code")+ clickText(device, "Enter activation code")+ waitText(device, "Enter activation code")+ fillField(device, 0, "LPA:1\$testsmdp.example\$TESTMATCH")+ waitText(device, "Activation code")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
globalesim/src/androidTest/java/com/vayunmathur/globalesim/ui/CoreJourneyTest.kt
diff --git a/globalesim/src/androidTest/java/com/vayunmathur/globalesim/ui/CoreJourneyTest.kt b/globalesim/src/androidTest/java/com/vayunmathur/globalesim/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..d3436a3cc9--- /dev/null+++ b/globalesim/src/androidTest/java/com/vayunmathur/globalesim/ui/CoreJourneyTest.kt@@ -0,0 +1,102 @@+package com.vayunmathur.globalesim.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: purchase/setup terms -> Pricing tab -> honest offline rates state (rates need the backend; no purchase is faked).+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun purchaseToPricing_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "One global eSIM for 200+ countries")+ clickText(device, "Pricing")+ waitAny(device, "Search countries", "No rates yet", "Pricing")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
logviewer/src/androidTest/java/com/vayunmathur/logviewer/ui/CoreJourneyTest.kt
diff --git a/logviewer/src/androidTest/java/com/vayunmathur/logviewer/ui/CoreJourneyTest.kt b/logviewer/src/androidTest/java/com/vayunmathur/logviewer/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..8fc808bde0--- /dev/null+++ b/logviewer/src/androidTest/java/com/vayunmathur/logviewer/ui/CoreJourneyTest.kt@@ -0,0 +1,107 @@+package com.vayunmathur.logviewer.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: system log -> filter dialog. The top-app-bar search action has no text, so the top-right clickable is tapped.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun openFilterOnSystemLog_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "System log")+ // Log lines stream in from logcat on the emulator; the title staying up proves the reader is live.+ Thread.sleep(2000)+ val clickables = device.wait(Until.findObjects(By.clickable(true)), TIMEOUT_MS)+ assertNotNull("no clickable actions on log screen", clickables)+ val topRight = clickables!!.maxByOrNull { it.visibleBounds.centerX() - it.visibleBounds.centerY() * 10 }+ assertNotNull(topRight); val b = topRight!!.visibleBounds; device.click(b.centerX(), b.centerY())+ waitAny(device, "Set filter", "System log")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
madeveloper/src/androidTest/java/com/vayunmathur/madeveloper/ui/CoreJourneyTest.kt
diff --git a/madeveloper/src/androidTest/java/com/vayunmathur/madeveloper/ui/CoreJourneyTest.kt b/madeveloper/src/androidTest/java/com/vayunmathur/madeveloper/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..67bf0674d6--- /dev/null+++ b/madeveloper/src/androidTest/java/com/vayunmathur/madeveloper/ui/CoreJourneyTest.kt@@ -0,0 +1,103 @@+package com.vayunmathur.madeveloper.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: developer home -> Available builds catalog (read-only; backend data is asserted only as the honest loaded/empty state).+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun homeToCatalog_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "Pushed installs")+ waitText(device, "Quick links")+ clickText(device, "Available builds")+ waitAny(device, "No catalog loaded yet.", "Available builds", "Catalog")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
networklocation/src/androidTest/java/com/vayunmathur/networklocation/ui/CoreJourneyTest.kt
diff --git a/networklocation/src/androidTest/java/com/vayunmathur/networklocation/ui/CoreJourneyTest.kt b/networklocation/src/androidTest/java/com/vayunmathur/networklocation/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..ace0b0e271--- /dev/null+++ b/networklocation/src/androidTest/java/com/vayunmathur/networklocation/ui/CoreJourneyTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.networklocation.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: first-run setup explains the offline provider and lists the three downloadable databases. The multi-GB download itself is not started (Wi-Fi-only, network-sized).+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun setupExplainsOfflineDatabases_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launchComponent(packageName, "com.vayunmathur.networklocation.MainActivity", device, targetContext)+ waitText(device, "Network Location")+ waitText(device, "Offline databases")+ waitText(device, "Offline geocoder")+ waitAny(device, "Wi-Fi beacon store", "Cell beacon store")+ // Honest first-run state: databases are not installed, so no live-check screen is claimed.+ assertTrue(device.findObject(By.text("Offline databases")) != null)+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
news/src/androidTest/java/com/vayunmathur/news/ui/CoreJourneyTest.kt
diff --git a/news/src/androidTest/java/com/vayunmathur/news/ui/CoreJourneyTest.kt b/news/src/androidTest/java/com/vayunmathur/news/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..67286f32e2--- /dev/null+++ b/news/src/androidTest/java/com/vayunmathur/news/ui/CoreJourneyTest.kt@@ -0,0 +1,118 @@+package com.vayunmathur.news.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: feed -> open a story -> open its article in the reader. The feed is server/RSS-backed, so on a truly offline image the honest empty-feed state is asserted instead of inventing a story.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun feedToStoryToReader_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitAny(device, "Search downloaded news", "Top stories", "No articles yet. Pull to refresh.")+ clickText(device, "Latest"); clickText(device, "Top stories")+ // Try to open the first story: story rows are clickable cards below the chips.+ Thread.sleep(3000)+ val rows = device.findObjects(By.clickable(true))+ val storyRow = rows.firstOrNull { it.visibleBounds.top > 300 && it.visibleBounds.height() > 60 }+ if (storyRow != null) {+ val b = storyRow.visibleBounds; device.click(b.centerX(), b.centerY())+ val landed = waitAny(device, "Summary", "How it developed", "This story is no longer in the downloaded feed.", "Search downloaded news")+ if (landed == "Summary" || landed == "How it developed") {+ // Open the first article in the reader.+ val arts = device.findObjects(By.clickable(true))+ val art = arts.firstOrNull { it.visibleBounds.top > 400 }+ if (art != null) { val ab = art.visibleBounds; device.click(ab.centerX(), ab.centerY()); waitAny(device, "Could not load this article.", "Serif", "Sans") }+ }+ } else {+ // Honest offline/no-cache state: no story exists to open.+ waitText(device, "No articles yet. Pull to refresh.")+ }+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
parentalcontrols/src/androidTest/java/com/vayunmathur/parentalcontrols/ui/CoreJourneyTest.kt
diff --git a/parentalcontrols/src/androidTest/java/com/vayunmathur/parentalcontrols/ui/CoreJourneyTest.kt b/parentalcontrols/src/androidTest/java/com/vayunmathur/parentalcontrols/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..748bc7dbcf--- /dev/null+++ b/parentalcontrols/src/androidTest/java/com/vayunmathur/parentalcontrols/ui/CoreJourneyTest.kt@@ -0,0 +1,108 @@+package com.vayunmathur.parentalcontrols.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: first-run PIN creation (enter + repeat) -> Save -> controls dashboard.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun createPinReachesDashboard_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launchComponent(packageName, "com.vayunmathur.parentalcontrols.MainActivity", device, targetContext)+ // Dashboard is first (PIN guards edits, not launch); Manage PIN opens setup.+ waitText(device, "Controls for this phone")+ clickText(device, "Manage your PIN")+ waitText(device, "Set parent PIN")+ fillField(device, 0, "2468")+ fillField(device, 1, "2468")+ clickText(device, "Save")+ waitText(device, "Controls for this phone")+ waitAny(device, "Daily limit", "App limits", "Web content filters")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
screentime/src/androidTest/java/com/vayunmathur/screentime/ui/CoreJourneyTest.kt
diff --git a/screentime/src/androidTest/java/com/vayunmathur/screentime/ui/CoreJourneyTest.kt b/screentime/src/androidTest/java/com/vayunmathur/screentime/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..49647c7c87--- /dev/null+++ b/screentime/src/androidTest/java/com/vayunmathur/screentime/ui/CoreJourneyTest.kt@@ -0,0 +1,104 @@+package com.vayunmathur.screentime.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: usage dashboard -> Week/Day period toggle. Usage stats need GET_USAGE_STATS; the appop is granted below and the no-access state is accepted honestly if the image denies it.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun dashboardPeriodToggle_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launchComponent(packageName, "com.vayunmathur.screentime.MainActivity", device, targetContext)+ val first = waitAny(device, "Total screen time", "Usage access is off")+ clickText(device, "Week")+ clickText(device, "Day")+ // Toggle must not crash or leave the dashboard.+ waitAny(device, "Total screen time", "Usage access is off", "Nothing used yet")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s GET_USAGE_STATS allow", "appops set %s SCHEDULE_EXACT_ALARM allow")+ }+}
securemail/src/androidTest/java/com/vayunmathur/securemail/ui/CoreJourneyTest.kt
diff --git a/securemail/src/androidTest/java/com/vayunmathur/securemail/ui/CoreJourneyTest.kt b/securemail/src/androidTest/java/com/vayunmathur/securemail/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..42d5a46167--- /dev/null+++ b/securemail/src/androidTest/java/com/vayunmathur/securemail/ui/CoreJourneyTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.securemail.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: onboarding claim form filled -> Claim enabled. The claim itself needs the mail backend, so success is not faked; after tapping, either progress or the form/error must remain without a crash.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun fillClaimForm_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "Set up SecureMail")+ fillField(device, 0, "journeyuser")+ fillField(device, 1, "journey-passphrase")+ waitText(device, "Claim address + generate key")+ clickText(device, "Claim address + generate key")+ waitAny(device, "Generating…", "Set up SecureMail", "Your address")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
setupwizard/src/androidTest/java/com/vayunmathur/setupwizard/ui/CoreJourneyTest.kt
diff --git a/setupwizard/src/androidTest/java/com/vayunmathur/setupwizard/ui/CoreJourneyTest.kt b/setupwizard/src/androidTest/java/com/vayunmathur/setupwizard/ui/CoreJourneyTest.ktindex ac4695936f..8e7528be09 100644--- a/setupwizard/src/androidTest/java/com/vayunmathur/setupwizard/ui/CoreJourneyTest.kt+++ b/setupwizard/src/androidTest/java/com/vayunmathur/setupwizard/ui/CoreJourneyTest.kt@@ -33,7 +33,13 @@ class CoreJourneyTest { val targetContext = instrumentation.targetContext val packageName = targetContext.packageName grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)- launch(packageName, device, targetContext)+ // Entry as in FullE2eTest: SETUP_WIZARD intent + setup marked incomplete.+ try { instrumentation.uiAutomation.executeShellCommand("settings put secure user_setup_complete 0").close() } catch (e: Exception) {}+ val entry = Intent(Intent.ACTION_MAIN).addCategory("android.intent.category.SETUP_WIZARD")+ .addCategory(Intent.CATEGORY_DEFAULT).setPackage(packageName)+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ targetContext.startActivity(entry)+ assertGateAbsent(device) waitText(device, "Welcome to Modern Apps OS") clickText(device, "Next") waitAny(device, "Connect to Wi-Fi", "Location services", "Let’s set up your device in a few steps.")
shop/src/androidTest/java/com/vayunmathur/shop/ui/CoreJourneyTest.kt
diff --git a/shop/src/androidTest/java/com/vayunmathur/shop/ui/CoreJourneyTest.kt b/shop/src/androidTest/java/com/vayunmathur/shop/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..202e0c7a22--- /dev/null+++ b/shop/src/androidTest/java/com/vayunmathur/shop/ui/CoreJourneyTest.kt@@ -0,0 +1,126 @@+package com.vayunmathur.shop.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: required profile gate -> fill required fields -> Continue -> product search. Search results need the shop backend; reaching search is asserted, no product is faked.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun completeProfileReachesSearch_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "Add your details to start shopping.")+ fillField(device, 0, "Journey")+ fillField(device, 1, "Tester")+ fillField(device, 2, "[email protected]")+ fillField(device, 3, "+15551234567")+ // The Continue button is at the end of the long profile LazyColumn+ // (address section included): scroll in the upper area, above the+ // keyboard, until it is composed and on screen.+ repeat(8) {+ if (device.findObject(By.text("Continue")) != null) return@repeat+ device.swipe(500, 1200, 500, 400, 20)+ }+ clickText(device, "Continue")+ waitAny(device, "Search products", "Shop", "No products found")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ scrollIntoView(device, text)+ // Click the clickable ancestor of the text (repo FAB pattern), not+ // the text node's own centre, which can land on a non-clickable span.+ val clickable = device.wait(Until.findObject(By.clickable(true).hasDescendant(By.text(text))), 3000)+ if (clickable != null) clickable.click() else { val b = o.visibleBounds; device.click(b.centerX(), b.centerY()) }+ Thread.sleep(600)+ }+ fun scrollIntoView(device: UiDevice, text: String) {+ repeat(10) {+ val o = device.findObject(By.text(text)) ?: return+ val y = o.visibleBounds.centerY()+ if (y in 250 until device.displayHeight - 250) return+ if (y >= device.displayHeight - 250) device.swipe(500, 1200, 500, 400, 20)+ else device.swipe(500, 400, 500, 1200, 20)+ Thread.sleep(300)+ }+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
shop/src/androidTest/java/com/vayunmathur/shop/ui/FullE2eTest.kt
diff --git a/shop/src/androidTest/java/com/vayunmathur/shop/ui/FullE2eTest.kt b/shop/src/androidTest/java/com/vayunmathur/shop/ui/FullE2eTest.ktindex e79125580a..ec2f376a34 100644--- a/shop/src/androidTest/java/com/vayunmathur/shop/ui/FullE2eTest.kt+++ b/shop/src/androidTest/java/com/vayunmathur/shop/ui/FullE2eTest.kt@@ -57,9 +57,13 @@ class FullE2eTest { "permission gate is showing; grants did not clear it", device.wait(Until.findObject(By.text(PERMISSION_GATE_TITLE)), GATE_TIMEOUT_MS), )+ // Clean state shows the profile form; if the core-journey test ran+ // first in this instrumentation run and saved a profile, Search is+ // the correct first screen instead (tests share on-device state). assertNotNull( "profile setup form never appeared; the app may have crashed on launch",- device.wait(Until.findObject(By.text(PROFILE_SETUP_HEADING)), CONTENT_TIMEOUT_MS),+ device.wait(Until.findObject(By.text(PROFILE_SETUP_HEADING)), CONTENT_TIMEOUT_MS)+ ?: device.findObject(By.text("Search products")), ) // Still alive in front: the process did not crash after painting content. assertEquals(packageName, device.currentPackageName)
uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/CoreJourneyTest.kt
diff --git a/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/CoreJourneyTest.kt b/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..c2de316767--- /dev/null+++ b/uniflix/src/androidTest/java/com/vayunmathur/uniflix/ui/CoreJourneyTest.kt@@ -0,0 +1,105 @@+package com.vayunmathur.uniflix.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: home hub -> Movies browse -> back -> Series browse. Catalogue data needs TMDB/addons; the empty browse state is the honest offline assertion.+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun homeToMoviesAndSeries_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ launch(packageName, device, targetContext)+ waitText(device, "Movies")+ clickText(device, "Movies")+ waitAny(device, "Nothing here yet.", "Movies")+ device.pressBack()+ clickText(device, "Series")+ waitAny(device, "Nothing here yet.", "Series")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}
updater/src/androidTest/java/com/vayunmathur/updater/ui/CoreJourneyTest.kt
diff --git a/updater/src/androidTest/java/com/vayunmathur/updater/ui/CoreJourneyTest.kt b/updater/src/androidTest/java/com/vayunmathur/updater/ui/CoreJourneyTest.ktnew file mode 100644index 0000000000..b8c796734b--- /dev/null+++ b/updater/src/androidTest/java/com/vayunmathur/updater/ui/CoreJourneyTest.kt@@ -0,0 +1,106 @@+package com.vayunmathur.updater.ui++import android.app.UiAutomation+import android.content.ComponentName+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.UiObject2+import androidx.test.uiautomator.Until+import java.io.IOException+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Core-journey e2e: drives the app's primary user flow with real+ * navigation/interaction assertions, beyond the launch-only FullE2eTest.+ * UiDevice polling, not compose-test (see FullE2eTest for why).+ * Core flow: tap Check now -> a terminal honest state (up to date / check failed on the emulator, which has no published update package).+ */+@RunWith(AndroidJUnit4::class)+class CoreJourneyTest {++ @Test+ fun checkNowReportsHonestState_coreJourney() {+ val instrumentation = InstrumentationRegistry.getInstrumentation()+ val device = UiDevice.getInstance(instrumentation)+ val targetContext = instrumentation.targetContext+ val packageName = targetContext.packageName+ grantAll(instrumentation.uiAutomation, targetContext.packageManager, packageName)+ // No launcher intent (see FullE2eTest): enter via the Settings action.+ val entry = Intent("android.settings.SYSTEM_UPDATE_SETTINGS").setPackage(packageName)+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ targetContext.startActivity(entry)+ assertGateAbsent(device)+ waitText(device, "Check now")+ clickText(device, "Check now")+ waitAny(device, "Your system is up to date", "Could not check for updates", "Checking for updates…", "Update available")+ assertEquals(packageName, device.currentPackageName)+ }+++ fun launch(launcherPkg: String, device: UiDevice, ctx: android.content.Context) {+ val intent = ctx.packageManager.getLaunchIntentForPackage(launcherPkg)+ assertNotNull("no launcher intent for $launcherPkg", intent)+ intent!!.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun launchComponent(pkg: String, cls: String, device: UiDevice, ctx: android.content.Context, action: String? = null) {+ val intent = Intent()+ if (action != null) intent.action = action+ intent.setComponent(ComponentName(pkg, cls))+ .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ ctx.startActivity(intent)+ assertGateAbsent(device)+ }+ fun assertGateAbsent(device: UiDevice) {+ org.junit.Assert.assertNull("permission gate showing", device.wait(Until.findObject(By.text(GATE)), GATE_MS))+ }+ fun waitText(device: UiDevice, text: String): UiObject2 {+ val o = device.wait(Until.findObject(By.text(text)), TIMEOUT_MS)+ assertNotNull("never appeared: $text", o); return o!!+ }+ fun waitAny(device: UiDevice, vararg texts: String): String {+ val deadline = System.currentTimeMillis() + TIMEOUT_MS+ while (System.currentTimeMillis() < deadline) {+ for (t in texts) { device.findObject(By.text(t))?.let { return t } }+ Thread.sleep(250)+ }+ throw AssertionError("none appeared: ${texts.joinToString()}")+ }+ fun clickText(device: UiDevice, text: String) {+ val o = waitText(device, text)+ // Text itself may not be the clickable node; click its centre hits the parent.+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY())+ Thread.sleep(600)+ }+ fun clickTextIfPresent(device: UiDevice, text: String): Boolean {+ val o = device.wait(Until.findObject(By.text(text)), 3000) ?: return false+ val b = o.visibleBounds; device.click(b.centerX(), b.centerY()); Thread.sleep(600); return true+ }+ fun fillField(device: UiDevice, index: Int, value: String) {+ val fields = device.wait(Until.findObjects(By.clazz("android.widget.EditText")), TIMEOUT_MS)+ assertNotNull("no edit fields", fields); assertTrue("missing field $index", fields!!.size > index)+ fields[index].click(); fields[index].setText(value)+ }+ fun grantAll(ua: UiAutomation, pm: PackageManager, pkg: String) {+ val info = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS)+ for (p in info.requestedPermissions.orEmpty()) try { ua.executeShellCommand("pm grant $pkg $p").close() } catch (e: Exception) {}+ for (c in SPECIAL) try { ua.executeShellCommand(c.format(pkg)).close() } catch (e: Exception) {}+ }+++ private companion object {+ const val TIMEOUT_MS = 20_000L+ const val GATE_MS = 5_000L+ const val GATE = "Grant Required Permissions"+ val SPECIAL = arrayOf("appops set %s SCHEDULE_EXACT_ALARM allow", "appops set %s USE_FULL_SCREEN_INTENT allow")+ }+}