diff --git a/README.md b/README.md index 6fd8546..f8f1626 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The current artifacts are development builds. Public distribution requires the c | `scripts` | Emulator-only test runner and ADB helpers | | `docs` | Architecture, design, development, platform, privacy and release guidance | -There is one production module and one test-fixture module. Production has one explicit library dependency: ZXing Core for local QR generation. Kotlin’s standard library is supplied by the Android Gradle plugin. +There is one production module and one test-fixture module. Production uses ZXing Core for local QR generation, AndroidX Wear Ongoing for receiving status, and AndroidX Core/SplashScreen for platform notifications and Wear launch sizing. Kotlin’s standard library is supplied by the Android Gradle plugin. Bundled privacy text and open-source acknowledgements are available from the application. ## Build @@ -55,4 +55,4 @@ python3 scripts/test-emulators.py --watch emulator-5554 --small --skip-build For browser tests and real Android-Emulator-to-Wear-Emulator uploads, see [development and testing](docs/DEVELOPMENT.md). Results and screenshots are generated under `app/build/reports/validation`, not checked into source control. -[Restriction audit](docs/RESTRICTIONS.md) · [Architecture](docs/ARCHITECTURE.md) · [Design](docs/DESIGN.md) · [Platform](docs/PLATFORM.md) · [Privacy](docs/PRIVACY.md) · [Release](docs/RELEASE.md) · [Validation](docs/VALIDATION.md) +[Product review](docs/PRODUCT_REVIEW.md) · [Store listing draft](docs/STORE_LISTING.md) · [Restriction audit](docs/RESTRICTIONS.md) · [Architecture](docs/ARCHITECTURE.md) · [Design](docs/DESIGN.md) · [Platform](docs/PLATFORM.md) · [Privacy](docs/PRIVACY.md) · [Release](docs/RELEASE.md) · [Validation](docs/VALIDATION.md) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ac4b7c8..8262d1c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -43,6 +43,9 @@ android { dependencies { implementation(libs.zxing) + implementation(libs.androidx.core) + implementation(libs.wear.ongoing) + implementation(libs.splashscreen) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.runner) diff --git a/app/src/androidTest/java/meghdad/pakkit/InstallSafetyTest.kt b/app/src/androidTest/java/meghdad/pakkit/InstallSafetyTest.kt index 05527cc..7eb3b77 100644 --- a/app/src/androidTest/java/meghdad/pakkit/InstallSafetyTest.kt +++ b/app/src/androidTest/java/meghdad/pakkit/InstallSafetyTest.kt @@ -14,6 +14,68 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class InstallSafetyTest : WatchTest() { + @Test + fun watchActionAndSystemConfirmationCompleteInstallation() { + assumeTrue(context.packageManager.canRequestPackageInstalls()) + val apk = fixture() + store.stage(apk) + openWatch() + instrumentation.runOnMainSync { + fun views(view: android.view.View): List = + listOf(view) + + if (view is android.view.ViewGroup) + (0 until view.childCount).flatMap { views(view.getChildAt(it)) } + else emptyList() + views(requireNotNull(activity).window.decorView) + .filterIsInstance() + .single { it.text == "Install" } + .performClick() + } + await(15_000) { store.pending()?.state == InstallState.CONFIRM } + // Exercise the real system button. No shell install or source-permission grant. + var consentClicked = false + try { + await(15_000) { + if (consentClicked) return@await true + val root = instrumentation.uiAutomation.rootInActiveWindow + val button = + root + ?.let { node -> + listOf("Install", "Update").flatMap { + node.findAccessibilityNodeInfosByText(it) + } + } + ?.firstOrNull { + it.text?.toString() in setOf("Install", "Update") && + it.isClickable && + it.isEnabled && + it.packageName?.toString() != context.packageName + } + consentClicked = + button?.performAction( + android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK + ) == true + consentClicked + } + } catch (failure: Exception) { + fun labels(node: android.view.accessibility.AccessibilityNodeInfo): List = + listOf( + "${node.packageName}: ${node.text} / ${node.contentDescription} clickable=${node.isClickable}" + ) + + (0 until node.childCount).flatMap { + node.getChild(it)?.let(::labels) ?: emptyList() + } + println(instrumentation.uiAutomation.rootInActiveWindow?.let(::labels)) + throw failure + } + await(30_000) { + store.pending()?.state in setOf(InstallState.INSTALLED, InstallState.FAILED) + } + assertEquals(store.pending()?.detail, InstallState.INSTALLED, store.pending()?.state) + assertFalse(store.file(apk.id).exists()) + assertNull(PendingApproval.intent) + } + @Test fun receiptAndForgedCallbacksCannotMarkPackageInstalled() { val apk = fixture() diff --git a/app/src/androidTest/java/meghdad/pakkit/PackageStoreTest.kt b/app/src/androidTest/java/meghdad/pakkit/PackageStoreTest.kt index 7c45701..c653a1e 100644 --- a/app/src/androidTest/java/meghdad/pakkit/PackageStoreTest.kt +++ b/app/src/androidTest/java/meghdad/pakkit/PackageStoreTest.kt @@ -36,6 +36,11 @@ class PackageStoreTest : WatchTest() { } return written } + + override fun remove(key: String): android.content.SharedPreferences.Editor { + editor.remove(key) + return this + } } } } @@ -45,11 +50,15 @@ class PackageStoreTest : WatchTest() { } assertTrue( runCatching { - PackageStore(wrapped).update(apk.id, InstallState.INSTALLING, "Preparing") - } + PackageStore(wrapped).update(apk.id, InstallState.INSTALLING, "Preparing") + } .isFailure ) assertEquals(apk, store.pending()) + failNext = true + assertTrue(runCatching { PackageStore(wrapped).dismiss(apk.id) }.isFailure) + assertEquals(apk, store.pending()) + assertTrue("Failed removal keeps the original APK", store.file(apk.id).exists()) } @Test diff --git a/app/src/androidTest/java/meghdad/pakkit/ReceiverLifecycleTest.kt b/app/src/androidTest/java/meghdad/pakkit/ReceiverLifecycleTest.kt index 5b263dd..4953485 100644 --- a/app/src/androidTest/java/meghdad/pakkit/ReceiverLifecycleTest.kt +++ b/app/src/androidTest/java/meghdad/pakkit/ReceiverLifecycleTest.kt @@ -11,6 +11,53 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ReceiverLifecycleTest : WatchTest() { + @Test + fun ongoingActivityReflectsReviewAndStopActionEndsReceiving() { + val permission = android.Manifest.permission.POST_NOTIFICATIONS + val granted = + context.checkSelfPermission(permission) == + android.content.pm.PackageManager.PERMISSION_GRANTED + if (android.os.Build.VERSION.SDK_INT >= 33 && !granted) + instrumentation.uiAutomation.grantRuntimePermission(context.packageName, permission) + // Keep this optional notification grant on the disposable emulator. Revoking a + // runtime permission kills the target process and its instrumentation runner. + run { + openWatch() + context.startForegroundService( + android.content.Intent(context, meghdad.pakkit.transfer.ReceiveService::class.java) + ) + await(30_000) { meghdad.pakkit.transfer.Receiving.state.url != null } + val manager = context.getSystemService(android.app.NotificationManager::class.java) + await { androidx.wear.ongoing.OngoingActivity.recoverOngoingActivity(context) != null } + val ongoing = + requireNotNull( + androidx.wear.ongoing.OngoingActivity.recoverOngoingActivity(context) + ) + assertTrue(ongoing.touchIntent.isImmutable) + store.stage(fixture()) + try { + await { + manager.activeNotifications.any { + it.id == ongoing.notificationId && + it.notification.extras.getString( + android.app.Notification.EXTRA_TITLE + ) == "Ready to install" + } + } + } catch (failure: Exception) { + throw AssertionError( + "Notifications: ${manager.activeNotifications.map { it.id to it.notification.extras.getString(android.app.Notification.EXTRA_TITLE) }}; review=${store.pending()?.state}; receiving=${meghdad.pakkit.transfer.Receiving.state}", + failure, + ) + } + val notification = + manager.activeNotifications.single { it.id == ongoing.notificationId }.notification + notification.actions.single { it.title == "Stop receiving" }.actionIntent.send() + await { !meghdad.pakkit.transfer.Receiving.state.active } + await { manager.activeNotifications.none { it.id == ongoing.notificationId } } + } + } + @Test fun ipv6ListenerAcceptsCanonicalBrowserAuthority() { LocalHttpServer(context, InetAddress.getByName("::1"), Any()).use { server -> diff --git a/app/src/androidTest/java/meghdad/pakkit/WatchExperienceTest.kt b/app/src/androidTest/java/meghdad/pakkit/WatchExperienceTest.kt index af11137..3db5c2b 100644 --- a/app/src/androidTest/java/meghdad/pakkit/WatchExperienceTest.kt +++ b/app/src/androidTest/java/meghdad/pakkit/WatchExperienceTest.kt @@ -27,6 +27,11 @@ class WatchExperienceTest : WatchTest() { private fun screen() = views(requireNotNull(activity).window.decorView) private fun capture(name: String) { + await { + var focused = false + instrumentation.runOnMainSync { focused = activity?.hasWindowFocus() == true } + focused + } instrumentation.waitForIdleSync() Thread.sleep(220) // Finite screen entrance; screenshots capture the settled UI. val bitmap = requireNotNull(instrumentation.uiAutomation.takeScreenshot()) @@ -56,6 +61,83 @@ class WatchExperienceTest : WatchTest() { } } + @Test + fun privacyIsAvailableWithoutStartingReceiving() { + openWatch() + val monitor = + instrumentation.addMonitor( + meghdad.pakkit.ui.AboutActivity::class.java.name, + null, + false, + ) + instrumentation.runOnMainSync { + screen().filterIsInstance -