Release script, manifest and build: fixes from the pre-release audit

release.ps1:
- The release is created as a draft, both APKs are uploaded, then it is
  published, so /releases/latest (and the QR code) never points at a
  release without its APK; a draft left by an interrupted run is cleaned
  up or resumed.
- Before publishing, the APK's signing certificate is compared with the
  release keystore's, so an APK signed with another key is never
  published.
- With -SkipBuild, an APK not built from the commit being tagged is
  refused.

flexera/AndroidManifest.xml: the home screen's database provider is no
longer exported. Lawnchair's manifest removes the definitions of its
READ_SETTINGS and WRITE_SETTINGS permissions, so any app could have
defined them and read or erased the home screen; the launcher itself
never goes through the provider.

build.gradle: github, the channel that is released, is the default
flavour, and Flexera's folders are wired into the nightly and play
variants too, so assembleDebug, lint and Android Studio's default
variant build; the lines Flexera changed carry markers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TMCandClaude Opus 5.5 committed 2026-11-14 18:50:51 +01:00
1 parent a800a54592
commit f5df10b4cc
3 files changed
+200 -19

No files matched your search

+25 -4
View File
@@ -243,6 +243,7 @@ android {
// Flexera Launcher: debug builds always use the debug key, so the release key in
// keystore.properties signs releases only.
signingConfig signingConfigs.debug
// Flexera Launcher: the app's name, as Android and the app's own screens show it.
resValue("string", "derived_app_name", "Flexera Launcher (Debug)")
manifestPlaceholders.quickstepMinSdk = "0"
@@ -252,6 +253,7 @@ android {
}
release {
// Flexera Launcher: the app's name, as Android and the app's own screens show it.
resValue("string", "derived_app_name", "Flexera Launcher")
minifyEnabled true
shrinkResources true
@@ -282,20 +284,28 @@ android {
minSdk = 26
}
// Flexera Launcher: its own application ids, so it installs beside Lawnchair, never over it.
// The github one must never change: Android updates an installed copy only from an APK with
// the same id, the updater (app.flexera.update.FlexeraUpdater) accepts no other, and
// flexera/release.ps1 starts and checks the release under it.
github {
applicationId 'com.sema.flexeralauncher'
dimension "channel"
// Flexera Launcher: github is the channel that is released, so Android Studio and the
// lint task use it by default. Lawnchair made play the default, and a play build
// switches features off (isPlayStoreFlavor), so it would not test what is released.
isDefault true
}
nightly {
applicationId 'com.sema.flexeralauncher.nightly'
applicationId 'com.sema.flexeralauncher.nightly' // Flexera Launcher: its own, as for github.
dimension "channel"
}
play {
applicationId "com.sema.flexeralauncher.play"
applicationId "com.sema.flexeralauncher.play" // Flexera Launcher: its own, as for github.
dimension "channel"
isDefault true
// Flexera Launcher: not the default channel; github is.
}
configureEach {
@@ -343,7 +353,9 @@ android {
lawnWithQuickstepGithub {
manifest.srcFile "quickstep/AndroidManifest-launcher.xml"
// Flexera Launcher: branding and default overrides. This variant-level source set
// outranks 'lawn' and 'main', so nothing upstream has to be edited.
// outranks 'lawn' and 'main', so nothing upstream has to be edited. Lawnchair's and
// Launcher3's code calls into these folders, so the nightly and play variants below
// get them too; without them those variants do not compile.
res.srcDirs = ['flexera/res']
java.srcDirs = ['flexera/src']
kotlin.directories.add('flexera/src')
@@ -361,10 +373,18 @@ android {
lawnWithQuickstepNightly {
manifest.srcFile "quickstep/AndroidManifest-launcher.xml"
// Flexera Launcher: the same folders as the github variant; see there.
res.srcDirs = ['flexera/res']
java.srcDirs = ['flexera/src']
kotlin.directories.add('flexera/src')
}
lawnWithQuickstepPlay {
manifest.srcFile "quickstep/AndroidManifest-launcher.xml"
// Flexera Launcher: the same folders as the github variant; see there.
res.srcDirs = ['flexera/res']
java.srcDirs = ['flexera/src']
kotlin.directories.add('flexera/src')
}
withQuickstep {
@@ -380,6 +400,7 @@ androidComponents {
onVariants(selector().all()) { variant ->
def channel = variant.productFlavors.last().second
variant.outputs.forEach { output ->
// Flexera Launcher: flexera/release.ps1 looks for the release APK under this name.
output.outputFileName.set("FlexeraLauncher.${output.versionName.get()}.$channel.${variant.buildType}.apk")
}
+16 -1
View File
@@ -7,7 +7,8 @@
the app's own update check (app.flexera.update.FlexeraUpdater). Lawnchair's online features stay
switched off in code; see app.flexera.FlexeraNetwork.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<!-- Lets the app hand a downloaded update to Android's installer. The owner still confirms each install. -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
@@ -64,6 +65,20 @@
android:exported="false"
android:theme="@style/Theme.Transparent" />
<!--
The home screen's database. Not exported, so other apps cannot reach it. Launcher3 exports
it for system apps that hold its READ_SETTINGS and WRITE_SETTINGS permissions, but
Lawnchair's manifest removes the definitions of those two permissions, so nothing ties
them to this app's signing key: any app could define them for itself and then read,
change or erase the home screen. The launcher itself never goes through this provider;
it uses the database directly. Only android:exported changes here; the rest of the
declaration is in AndroidManifest-common.xml.
-->
<provider
android:name="com.android.launcher3.LauncherProvider"
android:exported="false"
tools:replace="android:exported" />
</application>
</manifest>
+159 -14
View File
@@ -5,12 +5,15 @@
.DESCRIPTION
One command per release. It
1. writes the new version to flexera/version.properties and commits it,
2. builds the signed release APK, compiling the Kotlin code from scratch,
3. checks that the APK is signed with the release key (not the debug key),
2. builds the signed release APK, compiling the Kotlin code from scratch, and records the
commit it was built from (source edited while it builds counts as uncommitted changes),
3. checks that the APK carries the release certificate, the one every installed copy has,
4. installs the APK on the running Android emulator, starts it and looks for a crash,
5. creates the release "v<version>" in https://git.mariosem.es/msemes/Flexera-Launcher-Releases,
6. attaches the APK to it, and
7. tags the source commit it was built from.
5. creates the release "v<version>" in https://git.mariosem.es/msemes/Flexera-Launcher-Releases
as a draft, which only you can see,
6. attaches the APK to it and then publishes it, and
7. tags the source commit it was built from. A tag of that version already on another
commit stops the script before anything is published, and -BuildOnly warns of it.
Installed copies of the app look at that repository once a day (app.flexera.update.FlexeraUpdater)
and offer the new version. A release that crashes at start would therefore reach the phone on
@@ -34,7 +37,13 @@
-SkipBuild to publish that same file.
.PARAMETER SkipBuild
Use the APK that is already in build\outputs instead of building again.
Use the APK that is already in build\outputs instead of building again. Every build of this
script records, in a file next to the APK, the commit it was built from and the APK's SHA-256,
and step 7 tags that commit. -SkipBuild stops when that record is missing (the APK was built
some other way, or by an older copy of this script) or describes another file (the APK was
built again since), and when the commits since the build change anything but this script and
WEBSITE\: the APK would be published without those changes. An APK built with uncommitted
changes (with -AllowDirty, or edited while it built) is published only with -AllowDirty again.
.PARAMETER NoSmokeTest
Skip step 4. Only for a machine without an emulator; try the APK on a phone yourself first.
@@ -76,6 +85,11 @@ $HomeActivity = "$AppId/app.lawnchair.LawnchairLauncher"
$JavaHome = 'C:\Program Files\Android\Android Studio\jbr'
$Adb = Join-Path $env:LOCALAPPDATA 'Android\Sdk\platform-tools\adb.exe'
$SmokeTestSeconds = 25
# The certificate every release is signed with, as the "certificate SHA-256 digest" that apksigner
# prints. Android installs an update only when it is signed with the same certificate as the copy
# already installed, so an APK signed with any other key, a keystore made anew under the same name
# included, could not update a single installed copy. It is no secret: every published APK carries it.
$ReleaseCertificateDigest = 'c5584f64eae90ba27f9b39dad2baa7ed6f60d248175578acd8cf1f178facfc70'
$Root = Split-Path -Parent $PSScriptRoot
Set-Location $Root
@@ -101,6 +115,9 @@ function Get-ApiClient {
}
function Read-Response($response, [string]$what) {
# A request that got no answer at all (no connection, a time-out) arrives here as nothing:
# Windows PowerShell gives $null for the result of a failed request instead of an error.
if (-not $response) { throw "$what failed: no answer from $Server" }
$text = $response.Content.ReadAsStringAsync().Result
if (-not $response.IsSuccessStatusCode) {
throw "$what failed: HTTP $([int]$response.StatusCode) $text"
@@ -108,6 +125,16 @@ function Read-Response($response, [string]$what) {
if ($text) { return $text | ConvertFrom-Json }
}
function Remove-Draft($release) {
Read-Response ($client.DeleteAsync("$Api/releases/$($release.id)").Result) "Removing the draft $($release.tag_name)" | Out-Null
# Gitea keeps the name of a removed release on record as a tag, even for a draft, which never
# had a git tag. That record goes too.
$response = $client.DeleteAsync("$Api/tags/$($release.tag_name)").Result
if (-not ($response -and ($response.IsSuccessStatusCode -or [int]$response.StatusCode -eq 404))) {
Write-Warning "The draft $($release.tag_name) is gone, but Gitea still keeps its name on record. That does no harm: the next release of that version reuses it."
}
}
# --- 1. Version ----------------------------------------------------------------------------------
Step "1/7 Version $Version"
@@ -155,6 +182,13 @@ if ($current -ne $Version) {
# --- 2. Build ------------------------------------------------------------------------------------
$apk = Join-Path $Root "build\outputs\apk\lawnWithQuickstepGithub\release\FlexeraLauncher.$Version.github.release.apk"
# A file in build\outputs says nothing about the source it came from, so each build records its
# commit next to it, with the APK's SHA-256 to tie the record to that very file. -SkipBuild
# publishes an APK only on that record's word, and step 7 tags the commit it names.
$buildRecord = [IO.Path]::ChangeExtension($apk, '.build.json')
# The files that never go into the APK, as git pathspecs. A commit that changes only these, such
# as a fix to this script between -BuildOnly and -SkipBuild, leaves the APK as current as it was.
$notInApk = @(':(exclude)flexera/release.ps1', ':(exclude)WEBSITE')
if ($SkipBuild) {
Step "2/7 Build skipped"
@@ -163,6 +197,10 @@ if ($SkipBuild) {
if (-not (Test-Path (Join-Path $Root 'keystore.properties'))) {
throw "keystore.properties is missing, so the APK would be signed with the debug key and could not update an installed copy."
}
# Read before Gradle starts, because that is when Gradle takes the commit it builds into the
# app: the About screen shows it after the version number.
$builtCommit = git rev-parse HEAD
$builtDirty = [bool](git status --porcelain -- . $notInApk)
# A release compiles its Kotlin code from scratch. Compiled output reused from an earlier
# build has produced an APK that crashed at start after a preference class had changed
# (NoSuchFieldError: $stable), so nothing compiled earlier is trusted here.
@@ -178,6 +216,57 @@ if ($SkipBuild) {
}
if (-not (Test-Path $apk)) { throw "Expected the APK at $apk, but it is not there." }
$apkSha256 = (Get-FileHash -Algorithm SHA256 -LiteralPath $apk).Hash
if ($SkipBuild) {
# A record that is missing or cannot be read counts as none.
$record = $null
try { $record = [IO.File]::ReadAllText($buildRecord) | ConvertFrom-Json } catch { }
if (-not $record -or $record.commit -notmatch '^[0-9a-f]{40}$' -or $record.sha256 -ne $apkSha256) {
throw "Nothing records which commit $(Split-Path $apk -Leaf) was built from, or the APK was built again outside this script since. -SkipBuild publishes only an APK that this script built: run it again without -SkipBuild."
}
$builtCommit = $record.commit
$builtDirty = $record.dirty
} else {
# Gradle compiles each file when it gets to it, so an edit made while it builds may be in the
# APK, whole or in part, though no commit has it. The APK then counts as one built with
# uncommitted changes.
$edited = git status --porcelain -- . $notInApk
if ($edited -and -not $builtDirty) {
Write-Warning "The source was changed while the APK was being built, so the APK may hold changes that no commit has:`n$($edited -join "`n")"
$builtDirty = $true
}
}
$changed = git diff --name-only $builtCommit HEAD -- . $notInApk
if ($LASTEXITCODE -ne 0) {
throw "Commit $builtCommit, which the APK was built from, is not in this repository. Build the APK again (run the script without -SkipBuild)."
}
if ($changed) {
throw "The APK was built from commit $builtCommit, but the commits after it change the app, which the APK may not have. Nothing was published; build it again from the current commit (run the script without -SkipBuild).`n$($changed -join "`n")"
}
if (-not $SkipBuild) {
[IO.File]::WriteAllText($buildRecord, ([ordered]@{ commit = $builtCommit; sha256 = $apkSha256; dirty = $builtDirty } | ConvertTo-Json))
}
# Step 1 needs -AllowDirty for any uncommitted edit, the website's included, so the flag says
# nothing about the APK itself. Whether the APK holds uncommitted changes is said here, in the
# run that publishes it too.
if ($builtDirty) {
Write-Warning "Built from commit $builtCommit, but with uncommitted changes: the APK may hold changes that no commit has."
} else {
Write-Host "Built from commit $builtCommit."
}
if ($builtDirty -and -not $AllowDirty -and -not $BuildOnly) {
throw "The APK was built while the source had uncommitted changes, so it matches no commit. Nothing was published. Commit them and build again, or publish this APK as it is with -SkipBuild -AllowDirty."
}
# Step 7 puts the tag v<version> on that commit. A tag of that name already on another commit, left
# from a withdrawn release of this version, would go on marking the wrong source. -BuildOnly
# publishes nothing, so it only warns, in time to remove the tag before the run that publishes.
$tagged = git rev-parse -q --verify "refs/tags/v$Version^{commit}"
if ($tagged -and $tagged -ne $builtCommit) {
$staleTag = "The tag v$Version is already on commit $tagged, but the APK was built from $builtCommit, and the script publishes nothing while that tag is there. If it marks a release that was withdrawn, remove it (git tag -d v$Version, and if it was pushed, git push origin :refs/tags/v$Version too) and run the script again with -SkipBuild."
if ($BuildOnly) { Write-Warning $staleTag } else { throw $staleTag }
}
# --- 3. Signature --------------------------------------------------------------------------------
Step "3/7 Checking the signature"
@@ -190,6 +279,13 @@ $certificate = & $apksigner.FullName verify --print-certs $apk
if ($LASTEXITCODE -ne 0) { throw "The APK's signature does not verify." }
$signer = ($certificate | Where-Object { $_ -match 'certificate DN' }) -join '; '
if ($signer -match 'Android Debug') { throw "The APK is signed with the debug key ($signer). Check keystore.properties." }
# apksigner writes "Signer #1 certificate SHA-256 digest: ..." and, from build-tools 37 on,
# "V2 Signer: certificate SHA-256 digest: ...".
$digests = @($certificate | ForEach-Object { if ($_ -match 'certificate SHA-256 digest: ([0-9a-f]+)') { $Matches[1] } } | Sort-Object -Unique)
if ($digests.Count -ne 1 -or $digests[0] -ne $ReleaseCertificateDigest) {
$certificate | ForEach-Object { Write-Host $_ }
throw "The APK is not signed with the release certificate (SHA-256 $ReleaseCertificateDigest), so it could not update any installed copy. keystore.properties must name the original flexera-release.jks; a keystore made anew cannot sign updates."
}
Write-Host $signer
Write-Host ("APK: {0} ({1:N1} MB)" -f (Split-Path $apk -Leaf), ((Get-Item $apk).Length / 1MB))
@@ -243,13 +339,30 @@ if ($BuildOnly) {
Step "5/7 Creating release v$Version in $ReleaseRepository"
$body = @{ tag_name = "v$Version"; name = "Flexera Launcher $Version"; body = $Notes; draft = $false; prerelease = $false } | ConvertTo-Json
# The release starts as a draft, which neither the app's update check nor the QR code's address
# sees, and is published in step 6 once both APKs are attached to it. A run that was stopped in
# between (Ctrl+C, a closed window, a lost connection) leaves its draft behind, and the server
# would not take a second release of the same version.
$drafts = Read-Response ($client.GetAsync("$Api/releases?draft=true&limit=50").Result) 'Looking for an unfinished draft'
foreach ($draft in $drafts) {
if ($draft.draft -and $draft.tag_name -eq "v$Version") {
Remove-Draft $draft
Write-Host "Removed the unfinished draft of v$Version that an earlier run left behind."
}
}
# The release is made on the release repository's default branch. Gitea would pick that branch by
# itself, except for a version whose name it still keeps on record, as it does after a draft was
# removed by hand in Gitea: then it takes the branch from this request alone, and publishing a
# release without one fails.
$branch = (Read-Response ($client.GetAsync($Api).Result) 'Reading the release repository').default_branch
$body = @{ tag_name = "v$Version"; target_commitish = $branch; name = "Flexera Launcher $Version"; body = $Notes; draft = $true; prerelease = $false } | ConvertTo-Json
$content = New-Object System.Net.Http.StringContent($body, [Text.Encoding]::UTF8, 'application/json')
$release = Read-Response ($client.PostAsync("$Api/releases", $content).Result) 'Creating the release'
# --- 6. APK --------------------------------------------------------------------------------------
Step "6/7 Uploading the APK"
Step "6/7 Uploading the APK and publishing the release"
# The APK goes up twice. Once under a name with its version, which is what a person looking at
# the release sees and what the app's updater downloads. And once under a name that never
@@ -258,6 +371,7 @@ Step "6/7 Uploading the APK"
# The versioned one goes first, because the updater takes the first .apk it finds.
$assetNames = @("FlexeraLauncher-$Version.apk", 'FlexeraLauncher.apk')
$uploaded = @()
$publishing = $false
try {
foreach ($assetName in $assetNames) {
$stream = [IO.File]::OpenRead($apk)
@@ -271,11 +385,36 @@ try {
$stream.Dispose()
}
}
# Only now, with both APKs attached, does the release become the one that the app's update
# check and the QR code's address find.
$publish = New-Object System.Net.Http.HttpRequestMessage((New-Object System.Net.Http.HttpMethod 'PATCH'), "$Api/releases/$($release.id)")
$publish.Content = New-Object System.Net.Http.StringContent('{"draft": false}', [Text.Encoding]::UTF8, 'application/json')
$publishing = $true
if ((Read-Response ($client.SendAsync($publish).Result) 'Publishing the release').draft) {
throw "Publishing the release failed: the server kept it as a draft."
}
} catch {
# A release without its APK would make every installed copy report a failed check.
$client.DeleteAsync("$Api/releases/$($release.id)").Result | Out-Null
$client.DeleteAsync("$Api/tags/v$Version").Result | Out-Null
throw
# The app does not see the draft, but it would stand in the next run's way. A release whose
# publishing went through with only the answer lost stays, though: it has both APKs.
$failure = $_
$state = $null
try {
$state = Read-Response ($client.GetAsync("$Api/releases/$($release.id)").Result) 'Reading the draft'
if ($state.draft) {
Remove-Draft $state
Write-Host "The draft v$Version was removed again; nothing was published."
} else {
Write-Warning "v$Version was published after all, with both APKs. Only the source tag is missing: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit"
}
} catch {
# Once the request to publish has gone out, a release that cannot be read back may be live.
if ($publishing -and -not $state) {
Write-Warning "Whether v$Version was published could not be checked ($($_.Exception.Message)). If $Api/releases/latest names v$Version, it was, with both APKs, and only the source tag is missing: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit. If not, the next run removes the draft."
} else {
Write-Warning "The draft v$Version could not be removed ($($_.Exception.Message)). Only you can see it, and the next run removes it."
}
}
throw $failure
}
$uploaded | ForEach-Object { Write-Host "Uploaded: $($_.browser_download_url)" }
@@ -283,8 +422,14 @@ $uploaded | ForEach-Object { Write-Host "Uploaded: $($_.browser_download_url)" }
Step "7/7 Tagging the source"
git tag -a "v$Version" -m "Flexera Launcher $Version"
if ($LASTEXITCODE -ne 0) { Write-Warning "Could not create the tag v$Version (does it exist already?)." }
# The commit the APK was built from, which need not be HEAD: a fix to this script may have been
# committed after it, and the branch may have moved on while the APK went up.
if ($tagged) {
Write-Host "The tag v$Version is already on $builtCommit."
} else {
git tag -a "v$Version" -m "Flexera Launcher $Version" $builtCommit
if ($LASTEXITCODE -ne 0) { Write-Warning "Could not create the tag v$Version. Create it with: git tag -a v$Version -m `"Flexera Launcher $Version`" $builtCommit" }
}
if ($PushSource) {
git push origin HEAD "v$Version"