Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 55 additions & 16 deletions .github/workflows/patcher-release.yml
Original file line number Diff line number Diff line change
@@ -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-<ver>-r<N>.apk (the full
# app) and openshm-patcher-noguide-<ver>-r<N>.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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -128,36 +133,70 @@ 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

- name: Publish the release
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" \
Expand All @@ -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" \
Expand Down
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ launcher `patcher-app/gradlew` is a jar-free shell script (the repo carries no j
JDK 17 (`JAVA_HOME=<jdk17> 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.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
To render a screen without an emulator (Compose Driver, dev-only, needs a JDK 21+): `JAVA_HOME=<jdk21+> patcher-app/tools/compose-driver/compose-driver.sh start WelcomeDriver`, then `tree` (semantics) and `shot <name>`, 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.

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-<version>-r<build>.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
Expand Down Expand Up @@ -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**
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
15 changes: 14 additions & 1 deletion patcher-app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,14 +21,15 @@ 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.
// Local builds use the bundled catalogue's minAppVersion, so they always accept their own catalogue.
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()
Expand All @@ -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 (`<prefix>-<ver>-r<N>.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).
Expand Down Expand Up @@ -183,6 +193,9 @@ apply { from("own-code.gradle.kts") }
@Suppress("UNCHECKED_CAST")
val ownCodeAssets = extra["ownCode.assetsTask"] as TaskProvider<Task>
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ver>-r<N>`, where N is the
* build number (CI sets versionCode to it); it must carry the APK `openshm-patcher-<ver>-r<N>.apk` and
* build number (CI sets versionCode to it); it must carry the APK `<assetPrefix>-<ver>-r<N>.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
Expand All @@ -56,7 +57,7 @@ class AppUpdater(
if (build <= versionCode) return AppUpdateResult.UpToDate

val assets = (release["assets"] as? List<*>).orEmpty().filterIsInstance<Map<*, *>>()
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Loading