diff --git a/.github/workflows/patcher-release.yml b/.github/workflows/patcher-release.yml index 56882058..cbceeb54 100644 --- a/.github/workflows/patcher-release.yml +++ b/.github/workflows/patcher-release.yml @@ -1,5 +1,9 @@ -# Builds the LibreWrist app and publishes its APK as a GitHub release whenever something under -# patcher-app/, or one of the directories it bundles, changes on main (or on demand). +# Builds the LibreWrist app and publishes its APKs as a GitHub release whenever something under +# patcher-app/, or one of the directories it bundles, changes on main (or on demand). Each release +# carries two APKs with the same versionName and build number: openshm-patcher--r.apk (the full +# app) and openshm-patcher-noguide--r.apk (built with -PnoGuide: package +# io.openshm.patcher.noguide, no accessibility service, for phones where Play Protect blocks apps that +# declare one), plus SHA256SUMS. # # Repository secrets (the LibreStatic release key; store and key share one password): # LIBRESTATIC_KEYSTORE_BASE64 base64 of the PKCS#12 keystore @@ -61,6 +65,7 @@ jobs: echo "::error::could not read versionName from patcher-app/app/build.gradle.kts" exit 1 fi + echo "PATCHER_VERSION_NAME=$version" >> "$GITHUB_ENV" taken="$(git tag --list "patcher-v$version-r*")" if [ -n "$taken" ]; then echo "::error::versionName $version was already released ($(echo $taken)); bump it in patcher-app/app/build.gradle.kts" @@ -128,24 +133,60 @@ jobs: # One Gradle run: the build is configured once and the release tasks overlap with the tests. A # failing test still fails the step before anything is published. - name: Test and build the release APK - run: patcher-app/gradlew --no-daemon :engine:test :app:testDebugUnitTest :app:assembleRelease + run: | + patcher-app/gradlew --no-daemon :engine:test :app:testDebugUnitTest :app:assembleRelease + mkdir -p "$RUNNER_TEMP/out" + cp patcher-app/app/build/outputs/apk/release/app-release.apk "$RUNNER_TEMP/out/openshm-patcher-$PATCHER_VERSION_NAME-r$PATCHER_VERSION_CODE.apk" + + # The same app as a separate package without Tic, the interactive guide, so it declares no + # accessibility service. Same output path as the full build, hence the copy right after each run. + - name: Build the APK without the guide + run: | + patcher-app/gradlew --no-daemon -PnoGuide :app:assembleRelease + cp patcher-app/app/build/outputs/apk/release/app-release.apk "$RUNNER_TEMP/out/openshm-patcher-noguide-$PATCHER_VERSION_NAME-r$PATCHER_VERSION_CODE.apk" - name: Check the signature env: EXPECTED_CERT: ${{ vars.PATCHER_CERT_SHA256 }} run: | - apk=patcher-app/app/build/outputs/apk/release/app-release.apk apksigner="$ANDROID_HOME/build-tools/37.0.0/apksigner" - certs="$("$apksigner" verify --print-certs "$apk")" - # "Signer #1 certificate ..." with a v1 signature, "V2 Signer: certificate ..." without one. - actual="$(printf '%s\n' "$certs" | sed -nE 's/^(Signer #1|V[0-9.]+ Signer:) certificate SHA-256 digest: //p' | head -n1)" - if [ -z "$actual" ]; then - echo "::error::could not read the signing certificate" + for apk in "$RUNNER_TEMP"/out/*.apk; do + echo "Checking $(basename "$apk")" + certs="$("$apksigner" verify --print-certs "$apk")" + # "Signer #1 certificate ..." with a v1 signature, "V2 Signer: certificate ..." without one. + actual="$(printf '%s\n' "$certs" | sed -nE 's/^(Signer #1|V[0-9.]+ Signer:) certificate SHA-256 digest: //p' | head -n1)" + if [ -z "$actual" ]; then + echo "::error::could not read the signing certificate" + exit 1 + fi + echo "Signing certificate SHA-256: $actual" + if [ -n "$EXPECTED_CERT" ] && [ "$actual" != "$(printf '%s' "$EXPECTED_CERT" | tr -d ': ' | tr 'A-F' 'a-f')" ]; then + echo "::error::signing certificate does not match PATCHER_CERT_SHA256" + exit 1 + fi + done + + # The point of the second APK: a different package that declares no accessibility service at all. + - name: Check the APK without the guide + run: | + aapt2="$ANDROID_HOME/build-tools/37.0.0/aapt2" + full="$RUNNER_TEMP/out/openshm-patcher-$PATCHER_VERSION_NAME-r$PATCHER_VERSION_CODE.apk" + noguide="$RUNNER_TEMP/out/openshm-patcher-noguide-$PATCHER_VERSION_NAME-r$PATCHER_VERSION_CODE.apk" + if [ "$("$aapt2" dump packagename "$full")" != "io.openshm.patcher" ]; then + echo "::error::the full APK is not package io.openshm.patcher" + exit 1 + fi + if [ "$("$aapt2" dump packagename "$noguide")" != "io.openshm.patcher.noguide" ]; then + echo "::error::the APK without the guide is not package io.openshm.patcher.noguide" exit 1 fi - echo "Signing certificate SHA-256: $actual" - if [ -n "$EXPECTED_CERT" ] && [ "$actual" != "$(printf '%s' "$EXPECTED_CERT" | tr -d ': ' | tr 'A-F' 'a-f')" ]; then - echo "::error::signing certificate does not match PATCHER_CERT_SHA256" + manifest="$("$aapt2" dump xmltree --file AndroidManifest.xml "$noguide")" + if [ -z "$manifest" ]; then + echo "::error::could not read the manifest of the APK without the guide" + exit 1 + fi + if printf '%s\n' "$manifest" | grep -qi accessibility; then + echo "::error::the APK without the guide still mentions accessibility in its manifest" exit 1 fi @@ -153,11 +194,9 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - version="$(sed -n 's/^ *versionName = "\(.*\)"$/\1/p' patcher-app/app/build.gradle.kts)" + version="$PATCHER_VERSION_NAME" tag="patcher-v$version-r$PATCHER_VERSION_CODE" out="$RUNNER_TEMP/out" - mkdir -p "$out" - cp patcher-app/app/build/outputs/apk/release/app-release.apk "$out/openshm-patcher-$version-r$PATCHER_VERSION_CODE.apk" ( cd "$out" && sha256sum *.apk > SHA256SUMS ) # The earlier patcher release with the highest build number; its commit bounds the change list. previous="$(git tag --list 'patcher-v*' | awk -F-r -v n="$PATCHER_VERSION_CODE" \ @@ -181,7 +220,7 @@ jobs: echo "- …and $((total - limit)) more" fi echo - echo "Install the APK on the phone; it upgrades any earlier build in place. Checksums: SHA256SUMS." + echo "Install openshm-patcher-$version-r$PATCHER_VERSION_CODE.apk on the phone; it upgrades any earlier build in place. openshm-patcher-noguide-$version-r$PATCHER_VERSION_CODE.apk is the same app without Tic, the interactive guide, so it declares no accessibility service; it installs as a separate app and does not upgrade the regular one. Checksums: SHA256SUMS." } > "$out/notes.md" gh release create "$tag" "$out"/*.apk "$out/SHA256SUMS" \ --target "$GITHUB_SHA" \ diff --git a/AGENTS.md b/AGENTS.md index 337508f3..4cb8adde 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,11 +54,14 @@ launcher `patcher-app/gradlew` is a jar-free shell script (the repo carries no j JDK 17 (`JAVA_HOME= patcher-app/gradlew :engine:test`). Every shipped library needs a row in `patcher-app/THIRD_PARTY.md` before it is added. The app's own code lives in `io.openshm.patcher`; code injected into vendor APKs still uses the `shminterop` placeholder. +`-PnoGuide` (or `PATCHER_NO_GUIDE=1`) builds the variant without Tic, the interactive guide: package +`io.openshm.patcher.noguide`, the accessibility service removed from the manifest, `BuildConfig.GUIDE_AVAILABLE` +false. The release workflow publishes both APKs under one `versionName` and tag. To render a screen without an emulator (Compose Driver, dev-only, needs a JDK 21+): `JAVA_HOME= patcher-app/tools/compose-driver/compose-driver.sh start WelcomeDriver`, then `tree` (semantics) and `shot `, then `stop`; see `patcher-app/tools/compose-driver/README.md`. ## Versioning (for `patcher-app/`) -- Every uploaded build has a `versionName` that no earlier upload used. This applies to every Play track (internal, closed, open, production) and to GitHub releases. Two builds with the same name are never allowed, not even a rebuild, a hotfix or a re-upload after a rejected or broken build. A new `versionCode` alone is not enough. Before uploading, check the release list for the name. If the name is already taken, bump the version again. +- Every uploaded build has a `versionName` that no earlier upload used. This applies to every Play track (internal, closed, open, production) and to GitHub releases. Two builds from different releases are never allowed the same name, not even a rebuild, a hotfix or a re-upload after a rejected or broken build. The default and `-PnoGuide` APKs of one release share that release's name. A new `versionCode` alone is not enough. Before uploading, check the release list for the name. If the name is already taken, bump the version again. - Every push to `main` that touches `patcher-app/`, `watch-mod/`, `shm-bridge/` or `catalogue/` publishes a GitHub release (`.github/workflows/patcher-release.yml`), so pushing such a commit is an upload. The workflow fails before building when the `versionName` was already released. - Bump `versionName` in `app/build.gradle.kts` in its own commit whenever you commit a change that affects the app (its code, resources or bundled data, including the directories above), right after that change, even when no upload is planned yet. Also bump it before an upload if the current name was already uploaded. Patch (`x.y.Z`) for fixes and small, self-contained changes (including a single small feature), minor (`x.Y.0`) for medium changes (several features, a reworked screen or flow), major (`X.0.0`) for a large overhaul; keep the pre-release suffix (e.g. `-beta`). The `versionCode` must also be higher than the last uploaded one. diff --git a/README.md b/README.md index 174d1b19..06545950 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,11 @@ The easiest way is **LibreWrist** (`patcher-app/`). This Android app does the wh phone itself; no PC is needed. Download the latest APK from the [Releases](https://github.com/LibreStatic/LibreWrist/releases) page and install it on the phone. +Each release also carries `openshm-patcher-noguide--r.apk`: the same app without the +interactive guide (Tic), so it declares no accessibility service. Use it on phones where Play Protect +blocks apps that declare one. It installs as a separate app (`io.openshm.patcher.noguide`), does not +upgrade the regular build, and updates itself from its own file. + The app guides you through these steps: 1. **Pairing**: the stock Galaxy Wearable pairing, then a Wireless debugging (ADB) pairing with the @@ -379,7 +384,8 @@ every 12 hours in the background. When there is one, the app shows an update dia notification if the background check found it first); tapping **Update** downloads the APK, checks its SHA-256 against the release's `SHA256SUMS`, checks that it is this app signed with the same key, and then asks Android to install it. The app closes while it updates; open it again afterwards. Only -official releases signed with the same key can update the app. +official releases signed with the same key can update the app. The build without the guide looks for +its own `openshm-patcher-noguide-…` file in the same release. GitHub is asked at most once an hour; in between, the app offers the last build it found each time it opens. **Later** shows it again on the next opening; ticking **Don't show this version again** @@ -519,6 +525,10 @@ the problem and tap **Export .txt**. Attach the file to the issue. - :construction: **Sleep apnea recording drains the battery on a Galaxy Watch8** ([#27](https://github.com/LibreStatic/LibreWrist/issues/27)) - **Status:** reported on a Galaxy Watch8 40 mm with 0.10.12. While recording it draws about 55 to 80 mA, against about 26 mA above idle measured on a Galaxy Watch5 Pro, so the watch runs flat before morning. Confirmed. A fix is in progress: a way to record without holding the watch awake is being tested. - **Workaround:** turn sleep apnea screening off on that watch until it is fixed. +- :mag: **Google Play Protect blocks the installation** ([#31](https://github.com/LibreStatic/LibreWrist/issues/31)) + - :hourglass_flowing_sand: **Blocked with "This app may request access to sensitive data".** In some countries Play Protect blocks apps installed outside the store that declare an accessibility service, and LibreWrist declares one for its optional interactive guide. Confirmed. Since 0.11.1 each release also carries `openshm-patcher-noguide-….apk`, the same app without the guide and without an accessibility service. An affected user still needs to report that it installs. + - :mag: **Blocked with "Harmful app blocked".** Play Protect flags the release files since 0.10.10. Confirmed on a clean device. The flag is tied to the published files, not to anything the app does on the phone, and its cause is not known. The build without the guide does not address it, and it is not yet known whether that file gets the same flag. + - **Workaround:** install the APK from a PC over ADB with **Verify apps over USB** turned off in Developer options; Play Protect stays on for everything else. [↑ Back to contents](#contents) @@ -580,7 +590,9 @@ JAVA_HOME=/path/to/jdk17 patcher-app/gradlew :engine:test :app:testDebugUnitTest Builds are signed with `patcher.p12` and `patcher.pass` from `OPENSHM_KEYS_DIR` (key alias `PATCHER_KEY_ALIAS`, default `patcher`). Without them, builds fall back to the SDK debug key. The published releases are built by `.github/workflows/patcher-release.yml` and signed with the -LibreStatic release key. +LibreStatic release key. `-PnoGuide` (or `PATCHER_NO_GUIDE=1`) builds the variant without the +interactive guide (package `io.openshm.patcher.noguide`, no accessibility service); the workflow +publishes both. [↑ Back to contents](#contents) diff --git a/patcher-app/app/build.gradle.kts b/patcher-app/app/build.gradle.kts index af64fb30..25900184 100644 --- a/patcher-app/app/build.gradle.kts +++ b/patcher-app/app/build.gradle.kts @@ -6,6 +6,11 @@ plugins { alias(libs.plugins.kotlin.compose) } +// -PnoGuide (or PATCHER_NO_GUIDE=1) builds the variant without Tic, the interactive guide: a separate +// package that declares no accessibility service (src/noguide/AndroidManifest.xml removes it), for +// phones whose Play Protect blocks sideloaded apps that declare one. Default builds are unchanged. +val noGuide = providers.gradleProperty("noGuide").isPresent || System.getenv("PATCHER_NO_GUIDE") == "1" + android { // Lists the translated locales for the per-app language setting (Android 13+). androidResources { @@ -16,6 +21,7 @@ android { defaultConfig { applicationId = "io.openshm.patcher" + if (noGuide) applicationIdSuffix = ".noguide" minSdk = 31 targetSdk = 36 // CI sets PATCHER_VERSION_CODE (the workflow run number) so every published APK upgrades the last. @@ -23,7 +29,7 @@ android { val catalogueMinApp = Regex("\"minAppVersion\":\\s*(\\d+)") .find(rootProject.file("../catalogue/catalogue.json").readText())?.groupValues?.get(1)?.toInt() ?: 1 versionCode = System.getenv("PATCHER_VERSION_CODE")?.toIntOrNull() ?: catalogueMinApp - versionName = "0.11.0" + versionName = "0.11.1" // Base URL of the raw `catalogue/` directory of the public repository (config.env CATALOGUE_URL, // or -PcatalogueUrl). Empty disables catalogue updates. Only https is accepted. val catalogueUrl = (providers.gradleProperty("catalogueUrl").orNull ?: System.getenv("CATALOGUE_URL") ?: "").trim() @@ -38,6 +44,10 @@ android { "UPDATE_REPO must look like owner/name" } buildConfigField("String", "UPDATE_REPO", "\"$updateRepo\"") + buildConfigField("boolean", "GUIDE_AVAILABLE", (!noGuide).toString()) + // Prefix of the release asset the self-update downloads (`--r.apk`), so each build + // updates itself from its own file. + buildConfigField("String", "UPDATE_ASSET_PREFIX", if (noGuide) "\"openshm-patcher-noguide\"" else "\"openshm-patcher\"") // Hash of the code that decides what a built APK contains (the engine, its library versions and the // build package of the app), so a build is only reused while that code is unchanged (see // BuildFacts.outputFingerprint). @@ -183,6 +193,9 @@ apply { from("own-code.gradle.kts") } @Suppress("UNCHECKED_CAST") val ownCodeAssets = extra["ownCode.assetsTask"] as TaskProvider androidComponents.onVariants { variant -> + if (noGuide) { + variant.sources.manifests.addStaticManifestFile("src/noguide/AndroidManifest.xml") + } variant.sources.assets?.addGeneratedSourceDirectory(ownCodeAssets, { task: Task -> // The task's `assets` property (DirectoryProperty), read reflectively: its class lives in the script. @Suppress("UNCHECKED_CAST") diff --git a/patcher-app/app/src/main/kotlin/io/openshm/patcher/data/AppUpdater.kt b/patcher-app/app/src/main/kotlin/io/openshm/patcher/data/AppUpdater.kt index 148d5f87..b92d37c2 100644 --- a/patcher-app/app/src/main/kotlin/io/openshm/patcher/data/AppUpdater.kt +++ b/patcher-app/app/src/main/kotlin/io/openshm/patcher/data/AppUpdater.kt @@ -30,13 +30,14 @@ sealed interface AppUpdateResult { /** * Asks the GitHub Releases API of [repo] (`owner/name`) for the latest release and decides whether it * is a newer patcher build than [versionCode]. The release tag is `patcher-v-r`, where N is the - * build number (CI sets versionCode to it); it must carry the APK `openshm-patcher--r.apk` and + * build number (CI sets versionCode to it); it must carry the APK `--r.apk` and * a `SHA256SUMS` listing it, otherwise nothing is offered. Pure logic over [CatalogueFetcher]. */ class AppUpdater( private val repo: String, private val versionCode: Long, private val fetcher: CatalogueFetcher, + private val assetPrefix: String = "openshm-patcher", ) { fun check(): AppUpdateResult { if (repo.isBlank()) return AppUpdateResult.Disabled @@ -56,7 +57,7 @@ class AppUpdater( if (build <= versionCode) return AppUpdateResult.UpToDate val assets = (release["assets"] as? List<*>).orEmpty().filterIsInstance>() - val apkName = "openshm-patcher-$versionName-r$build.apk" + val apkName = "$assetPrefix-$versionName-r$build.apk" val apk = assets.firstOrNull { it["name"] == apkName } ?: return AppUpdateResult.Failed("the release has no $apkName") val sums = assets.firstOrNull { it["name"] == "SHA256SUMS" } ?: return AppUpdateResult.Failed("the release has no SHA256SUMS") val apkUrl = apk["browser_download_url"] as? String ?: return AppUpdateResult.Failed("the APK has no download link") diff --git a/patcher-app/app/src/main/kotlin/io/openshm/patcher/device/guide/SettingsLauncher.kt b/patcher-app/app/src/main/kotlin/io/openshm/patcher/device/guide/SettingsLauncher.kt index 28d37b9b..daea94f9 100644 --- a/patcher-app/app/src/main/kotlin/io/openshm/patcher/device/guide/SettingsLauncher.kt +++ b/patcher-app/app/src/main/kotlin/io/openshm/patcher/device/guide/SettingsLauncher.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.LifecycleEventEffect import io.openshm.patcher.ui.components.PatcherAlertDialog +import io.openshm.patcher.BuildConfig import io.openshm.patcher.R import io.openshm.patcher.data.Automation import io.openshm.patcher.device.LaunchRequest @@ -80,7 +81,7 @@ fun rememberSettingsLauncher(): (LaunchRequest) -> Unit { return remember(context) { { request -> when { - request.guide == null || !Automation.state.value.guidePet -> startPlain(context, request) + request.guide == null || !BuildConfig.GUIDE_AVAILABLE || !Automation.state.value.guidePet -> startPlain(context, request) GuideAccessibilityService.isEnabled(context) -> startGuided(context, request) else -> asking = request } diff --git a/patcher-app/app/src/main/kotlin/io/openshm/patcher/ui/screens/welcome/AutomationToggles.kt b/patcher-app/app/src/main/kotlin/io/openshm/patcher/ui/screens/welcome/AutomationToggles.kt index 47da0af1..0ce65522 100644 --- a/patcher-app/app/src/main/kotlin/io/openshm/patcher/ui/screens/welcome/AutomationToggles.kt +++ b/patcher-app/app/src/main/kotlin/io/openshm/patcher/ui/screens/welcome/AutomationToggles.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.text.fromHtml import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp import io.openshm.patcher.ui.components.PatcherAlertDialog +import io.openshm.patcher.BuildConfig import io.openshm.patcher.R import io.openshm.patcher.data.AutomationState import io.openshm.patcher.data.Region @@ -50,25 +51,29 @@ enum class AutomationHelp(@StringRes val title: Int, @StringRes val body: Int) { } /** - * The automation switches under "Get started": the guide pet first, then unattended mode and its two - * dependent switches, which are shown off and disabled while unattended mode is off, and China mode - * where it was detected or ever set. + * The automation switches under "Get started": the guide pet first (left out when [guideAvailable] is + * false, in the build without the guide), then unattended mode and its two dependent switches, which + * are shown off and disabled while unattended mode is off, and China mode where it was detected or + * ever set. */ @Composable internal fun AutomationToggles( automation: AutomationState, onEvent: (WelcomeEvent) -> Unit, modifier: Modifier = Modifier, + guideAvailable: Boolean = BuildConfig.GUIDE_AVAILABLE, ) { val dependent = automation.unattended Column(modifier.fillMaxWidth()) { - AutomationRow( - label = R.string.automation_guide_title, - checked = automation.guidePet, - enabled = true, - onChange = { onEvent(WelcomeEvent.SetGuidePet(it)) }, - onHelp = { onEvent(WelcomeEvent.ShowHelp(AutomationHelp.Guide)) }, - ) + if (guideAvailable) { + AutomationRow( + label = R.string.automation_guide_title, + checked = automation.guidePet, + enabled = true, + onChange = { onEvent(WelcomeEvent.SetGuidePet(it)) }, + onHelp = { onEvent(WelcomeEvent.ShowHelp(AutomationHelp.Guide)) }, + ) + } AutomationRow( label = R.string.automation_unattended_title, checked = automation.unattended, diff --git a/patcher-app/app/src/main/kotlin/io/openshm/patcher/update/AppUpdateBackground.kt b/patcher-app/app/src/main/kotlin/io/openshm/patcher/update/AppUpdateBackground.kt index 5e91f2e9..b04fb9ad 100644 --- a/patcher-app/app/src/main/kotlin/io/openshm/patcher/update/AppUpdateBackground.kt +++ b/patcher-app/app/src/main/kotlin/io/openshm/patcher/update/AppUpdateBackground.kt @@ -35,7 +35,7 @@ internal fun newAppUpdateChecker(context: Context, settings: AppUpdatePrefs = Ap return AppUpdateChecker( BuildConfig.UPDATE_REPO, settings, - { AppUpdater(BuildConfig.UPDATE_REPO, BuildConfig.VERSION_CODE.toLong(), fetcher).check() }, + { AppUpdater(BuildConfig.UPDATE_REPO, BuildConfig.VERSION_CODE.toLong(), fetcher, BuildConfig.UPDATE_ASSET_PREFIX).check() }, versionCode = BuildConfig.VERSION_CODE.toLong(), ) } diff --git a/patcher-app/app/src/noguide/AndroidManifest.xml b/patcher-app/app/src/noguide/AndroidManifest.xml new file mode 100644 index 00000000..84527e36 --- /dev/null +++ b/patcher-app/app/src/noguide/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppUpdaterTest.kt b/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppUpdaterTest.kt index ff099c90..d87a1976 100644 --- a/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppUpdaterTest.kt +++ b/patcher-app/app/src/test/kotlin/io/openshm/patcher/AppUpdaterTest.kt @@ -77,6 +77,27 @@ class AppUpdaterTest { assertEquals(12345L, result.update.sizeBytes) } + @Test fun aCustomAssetPrefixPicksItsOwnApkAndHashFromAReleaseWithBoth() { + val noGuideApkUrl = "https://example.invalid/openshm-patcher-noguide-0.1.0-r9.apk" + val noGuideHash = "cd".repeat(32) + val both = """{"tag_name":"patcher-v0.1.0-r9","body":"","assets":[ + {"name":"openshm-patcher-0.1.0-r9.apk","browser_download_url":"$apkUrl","size":12345}, + {"name":"openshm-patcher-noguide-0.1.0-r9.apk","browser_download_url":"$noGuideApkUrl","size":6789}, + {"name":"SHA256SUMS","browser_download_url":"$sumsUrl","size":200}]}""".toByteArray() + val sums = "$hash openshm-patcher-0.1.0-r9.apk\n$noGuideHash openshm-patcher-noguide-0.1.0-r9.apk\n" + val noGuide = AppUpdater("owner/name", 6, fetcher(both, sums), "openshm-patcher-noguide").check() as AppUpdateResult.Available + assertEquals("openshm-patcher-noguide-0.1.0-r9.apk", noGuide.update.apkName) + assertEquals(noGuideApkUrl, noGuide.update.apkUrl) + assertEquals(noGuideHash, noGuide.update.sha256) + assertEquals(6789L, noGuide.update.sizeBytes) + val regular = check(fetcher(both, sums)) as AppUpdateResult.Available + assertEquals("openshm-patcher-0.1.0-r9.apk", regular.update.apkName) + assertEquals(apkUrl, regular.update.apkUrl) + assertEquals(hash, regular.update.sha256) + // A release that only carries the regular APK offers nothing to the build without the guide. + assertTrue(AppUpdater("owner/name", 6, fetcher(release()), "openshm-patcher-noguide").check() is AppUpdateResult.Failed) + } + @Test fun theSameOrAnOlderBuildIsUpToDate() { assertEquals(AppUpdateResult.UpToDate, check(fetcher(release()), versionCode = 9)) assertEquals(AppUpdateResult.UpToDate, check(fetcher(release()), versionCode = 12))