Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
In-app updates: download the release APK and install it with Android's installer
kota-zo529dcc680418
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8b9fd44f..1e31e501 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ A new engine, written from scratch, and a cleaner app on top of it.- **Downloads ask their quality** if you want ("Ask each time"): once for a whole playlist, kept for its new songs.- **Liked Songs update at once** after a like or an unlike, without reloading the whole list.- **No more "bop" between two songs** on the phone's speaker: the sound output stays awake across the change.+- **Updates install in the app**: "Update" downloads the new version with a progress bar and hands it to Android's installer; no trip to GitHub. The first time, Android asks to allow installs from Myspoti.- **Haptics work again**: buttons, likes and the debug icon vibrate.- **Solid bottom bar** as an option in Settings, Display.- **Settings page**: sound quality, downloads, data and battery, display and language, in one place (profile menu or Library's account menu).diff --git a/README.md b/README.mdindex 62863f1a..6cab0227 100644--- a/README.md+++ b/README.md@@ -96,7 +96,7 @@ google-chrome --user-data-dir="$HOME/.myspoti-chrome" --remote-debugging-port=92./gradlew :host-cdp:test -Pcdp=http://localhost:9222```-Every push builds and tests on GitHub Actions. A `v*` tag publishes a signed APK in Releases, which the app checks for updates.+Every push builds and tests on GitHub Actions. A `v*` tag publishes a signed APK in Releases; the app finds it, downloads it and installs it through Android's installer.## Creditsdiff --git a/base/app/src/androidTest/java/com/music/spotui/data/api/AppUpdaterTest.kt b/base/app/src/androidTest/java/com/music/spotui/data/api/AppUpdaterTest.ktnew file mode 100644index 00000000..8ca494cf--- /dev/null+++ b/base/app/src/androidTest/java/com/music/spotui/data/api/AppUpdaterTest.kt@@ -0,0 +1,39 @@+package com.music.spotui.data.api++import androidx.test.ext.junit.runners.AndroidJUnit4+import androidx.test.platform.app.InstrumentationRegistry+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.runBlocking+import kotlinx.coroutines.withTimeout+import org.junit.Assert.assertTrue+import org.junit.Test+import org.junit.runner.RunWith++/**+ * Downloads a real release APK and hands it to the package installer. The release is+ * another app id (app.myspoti) than this test build, so the installer must refuse it:+ * that answer proves the download, the session and the status receiver work end to end.+ */+@RunWith(AndroidJUnit4::class)+class AppUpdaterTest {+ @Test fun downloadsAndReachesTheInstaller() = runBlocking {+ val context = InstrumentationRegistry.getInstrumentation().targetContext+ InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(+ "appops set ${context.packageName} REQUEST_INSTALL_PACKAGES allow").close()+ Thread.sleep(500)+ val release = UpdateChecker.Release(+ "2.0.0-beta.3", "",+ apkUrl = "https://github.com/kota-zo/myspoti/releases/download/v2.0.0-beta.3/myspoti-2.0.0-beta.3.apk",+ )+ AppUpdater.reset()+ AppUpdater.update(context, release)+ withTimeout(60_000) {+ AppUpdater.state.first {+ it is AppUpdater.State.Failed+ }+ }+ val state = AppUpdater.state.value+ android.util.Log.i("AppUpdaterTest", "installer said: $state")+ assertTrue("state: $state", state is AppUpdater.State.Failed)+ }+}diff --git a/base/app/src/main/AndroidManifest.xml b/base/app/src/main/AndroidManifest.xmlindex cc8dcaa5..d486967c 100644--- a/base/app/src/main/AndroidManifest.xml+++ b/base/app/src/main/AndroidManifest.xml@@ -3,6 +3,8 @@xmlns:tools="http://schemas.android.com/tools"><uses-permission android:name="android.permission.VIBRATE" />+ <!-- In-app updates: the release APK goes through Android's package installer. -->+ <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.FOREGROUND_SERVICE" />@@ -174,6 +176,9 @@android:exported="false"><meta-data android:name="autoStoreLocales" android:value="true" /></service>+ <receiver+ android:name="com.music.spotui.data.api.AppUpdater$StatusReceiver"+ android:exported="false" /><receiverandroid:name="androidx.media.session.MediaButtonReceiver"android:exported="true">diff --git a/base/app/src/main/java/com/music/spotui/App.kt b/base/app/src/main/java/com/music/spotui/App.ktindex c00f4c99..55e53073 100644--- a/base/app/src/main/java/com/music/spotui/App.kt+++ b/base/app/src/main/java/com/music/spotui/App.kt@@ -18,7 +18,9 @@ import androidx.annotation.RequiresApiimport androidx.compose.foundation.layout.navigationBarsPaddingimport androidx.compose.material3.Scaffoldimport androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsStateimport androidx.compose.runtime.getValue+import kotlinx.coroutines.launchimport androidx.compose.runtime.setValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.saveable.rememberSaveable@@ -184,22 +186,66 @@ private fun UpdatePrompt() {}updateCardOpen.value = release != nullval r = release ?: return- val dismiss = { com.music.spotui.data.api.UpdateChecker.dismiss(context, r); release = null }+ val scope = androidx.compose.runtime.rememberCoroutineScope()+ val updater = com.music.spotui.data.api.AppUpdater+ val state by updater.state.collectAsState()+ val start = { scope.launch { updater.update(context, r) }; Unit }+ // Back from the "Install unknown apps" page with the switch on: carry on by itself.+ val lifecycle = androidx.lifecycle.compose.LocalLifecycleOwner.current.lifecycle+ androidx.compose.runtime.DisposableEffect(lifecycle) {+ val observer = androidx.lifecycle.LifecycleEventObserver { _, event ->+ if (event == androidx.lifecycle.Lifecycle.Event.ON_RESUME &&+ updater.state.value == com.music.spotui.data.api.AppUpdater.State.NeedsPermission &&+ updater.canInstall(context)) start()+ }+ lifecycle.addObserver(observer)+ onDispose { lifecycle.removeObserver(observer) }+ }+ val dismiss = { updater.reset(); com.music.spotui.data.api.UpdateChecker.dismiss(context, r); release = null }+ val res = context.resources+ val status = when (val s = state) {+ is com.music.spotui.data.api.AppUpdater.State.Downloading ->+ res.getString(app.myspoti.engine.R.string.update_downloading, (s.progress.coerceAtLeast(0f) * 100).toInt())+ com.music.spotui.data.api.AppUpdater.State.Installing -> res.getString(app.myspoti.engine.R.string.update_installing)+ com.music.spotui.data.api.AppUpdater.State.NeedsPermission -> res.getString(app.myspoti.engine.R.string.update_needs_permission)+ is com.music.spotui.data.api.AppUpdater.State.Failed -> res.getString(app.myspoti.engine.R.string.update_failed, s.message)+ com.music.spotui.data.api.AppUpdater.State.Idle -> null+ }+ val busy = state is com.music.spotui.data.api.AppUpdater.State.Downloading || state == com.music.spotui.data.api.AppUpdater.State.InstallingUpdateDialog(version = r.version,notes = r.notes,+ status = status,+ progress = (state as? com.music.spotui.data.api.AppUpdater.State.Downloading)?.progress,+ button = res.getString(when (state) {+ com.music.spotui.data.api.AppUpdater.State.NeedsPermission -> app.myspoti.engine.R.string.update_allow+ is com.music.spotui.data.api.AppUpdater.State.Failed -> app.myspoti.engine.R.string.update_retry+ else -> app.myspoti.engine.R.string.version_sunsetting_dialog_cta_update+ }),onUpdate = {- release = null- context.startActivity(android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(r.pageUrl))- .addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK))+ when {+ busy -> Unit+ // A release without an APK: its page, as before.+ r.apkUrl.isBlank() -> {+ release = null+ context.startActivity(android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(r.pageUrl))+ .addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK))+ }+ state == com.music.spotui.data.api.AppUpdater.State.NeedsPermission && !updater.canInstall(context) ->+ updater.openInstallSettings(context)+ else -> start()+ }},- onLater = dismiss,+ onLater = { if (!busy) dismiss() },)}/** The update card, in the app's own style (dark sheet, green pill), not a system dialog. */@Composable-private fun UpdateDialog(version: String, notes: String, onUpdate: () -> Unit, onLater: () -> Unit) {+private fun UpdateDialog(+ version: String, notes: String, status: String?, progress: Float?, button: String,+ onUpdate: () -> Unit, onLater: () -> Unit,+) {androidx.compose.ui.window.Dialog(onDismissRequest = onLater) {androidx.compose.foundation.layout.Column(horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally,@@ -233,6 +279,21 @@ private fun UpdateDialog(version: String, notes: String, onUpdate: () -> Unit, omodifier = Modifier.padding(top = 16.dp).fillMaxWidth().heightIn(max = 240.dp).verticalScroll(androidx.compose.foundation.rememberScrollState()),)+ // The download and install, under the notes.+ if (status != null) androidx.compose.material3.Text(+ status, color = androidx.compose.ui.graphics.Color.White.copy(alpha = 0.8f),+ fontFamily = com.music.spotui.ui.theme.AppSans, fontSize = 14.sp,+ textAlign = androidx.compose.ui.text.style.TextAlign.Center,+ modifier = Modifier.padding(top = 16.dp).fillMaxWidth(),+ )+ if (progress != null) {+ val bar = Modifier.padding(top = 10.dp).fillMaxWidth().height(4.dp).clip(androidx.compose.foundation.shape.RoundedCornerShape(50))+ if (progress < 0f) androidx.compose.material3.LinearProgressIndicator(+ modifier = bar, color = com.music.spotui.ui.theme.AppAccent, trackColor = androidx.compose.ui.graphics.Color.White.copy(alpha = 0.15f))+ else androidx.compose.material3.LinearProgressIndicator(+ progress = { progress }, modifier = bar, color = com.music.spotui.ui.theme.AppAccent,+ trackColor = androidx.compose.ui.graphics.Color.White.copy(alpha = 0.15f), drawStopIndicator = {})+ }androidx.compose.foundation.layout.Box(contentAlignment = androidx.compose.ui.Alignment.Center,modifier = Modifier@@ -244,7 +305,7 @@ private fun UpdateDialog(version: String, notes: String, onUpdate: () -> Unit, o.background(com.music.spotui.ui.theme.AppAccent),) {androidx.compose.material3.Text(- androidx.compose.ui.res.stringResource(app.myspoti.engine.R.string.version_sunsetting_dialog_cta_update),+ button,color = androidx.compose.ui.graphics.Color.Black, fontFamily = com.music.spotui.ui.theme.AppSans,fontWeight = androidx.compose.ui.text.font.FontWeight.Bold, fontSize = 16.sp,)diff --git a/base/app/src/main/java/com/music/spotui/data/api/AppUpdater.kt b/base/app/src/main/java/com/music/spotui/data/api/AppUpdater.ktnew file mode 100644index 00000000..f7be1ad0--- /dev/null+++ b/base/app/src/main/java/com/music/spotui/data/api/AppUpdater.kt@@ -0,0 +1,147 @@+package com.music.spotui.data.api++import android.app.PendingIntent+import android.content.BroadcastReceiver+import android.content.Context+import android.content.Intent+import android.content.pm.PackageInstaller+import android.net.Uri+import android.os.Build+import android.provider.Settings+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.withContext+import okhttp3.OkHttpClient+import okhttp3.Request+import java.io.File+import java.util.concurrent.TimeUnit++/**+ * Downloads a release's APK and installs it over this app with Android's package+ * installer: the system asks the user to confirm, nothing opens in a browser.+ * The APK is signed with the same key as the installed app, or Android refuses it.+ */+object AppUpdater {+ sealed interface State {+ data object Idle : State+ /** [progress] 0..1, or -1 while the size is unknown. */+ data class Downloading(val progress: Float) : State+ /** Handed to the system installer, waiting for the user's confirmation. */+ data object Installing : State+ /** Android needs "Install unknown apps" allowed for Myspoti first. */+ data object NeedsPermission : State+ data class Failed(val message: String) : State+ }++ private val _state = MutableStateFlow<State>(State.Idle)+ val state: StateFlow<State> = _state++ private const val ACTION = "app.myspoti.UPDATE_STATUS"+ private val http by lazy {+ OkHttpClient.Builder().connectTimeout(20, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build()+ }++ /** Android lets this app install packages (the "Install unknown apps" switch). */+ fun canInstall(context: Context): Boolean = context.packageManager.canRequestPackageInstalls()++ /** The system page with Myspoti's "Install unknown apps" switch. */+ fun openInstallSettings(context: Context) {+ context.startActivity(+ Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:${context.packageName}"))+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),+ )+ }++ /** Downloads [release]'s APK, then starts the install. Updates [state] as it goes. */+ suspend fun update(context: Context, release: UpdateChecker.Release) {+ val app = context.applicationContext+ if (!canInstall(app)) { _state.value = State.NeedsPermission; return }+ _state.value = State.Downloading(-1f)+ val result = runCatching {+ val apk = download(app, release)+ install(app, apk)+ }+ result.exceptionOrNull()?.let {+ android.util.Log.w("AppUpdater", "update failed", it)+ _state.value = State.Failed(it.message ?: it.javaClass.simpleName)+ }+ }++ fun reset() { _state.value = State.Idle }++ private suspend fun download(context: Context, release: UpdateChecker.Release): File = withContext(Dispatchers.IO) {+ val dir = File(context.cacheDir, "updates").apply { mkdirs() }+ dir.listFiles()?.forEach { it.delete() }+ val file = File(dir, "myspoti-${release.version}.apk")+ http.newCall(Request.Builder().url(release.apkUrl).build()).execute().use { r ->+ if (!r.isSuccessful) throw java.io.IOException("HTTP ${r.code}")+ val total = r.body.contentLength()+ var done = 0L+ var shown = -1+ r.body.byteStream().use { input ->+ file.outputStream().use { out ->+ val buf = ByteArray(64 * 1024)+ while (true) {+ val n = input.read(buf)+ if (n < 0) break+ out.write(buf, 0, n)+ done += n+ if (total > 0) {+ val pct = (done * 100 / total).toInt()+ if (pct != shown) { shown = pct; _state.value = State.Downloading(pct / 100f) }+ }+ }+ }+ }+ if (total > 0 && done != total) throw java.io.IOException("download cut at $done / $total bytes")+ }+ file+ }++ /** Streams the APK into an installer session; [StatusReceiver] gets the outcome. */+ private suspend fun install(context: Context, apk: File) = withContext(Dispatchers.IO) {+ _state.value = State.Installing+ val installer = context.packageManager.packageInstaller+ val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL).apply {+ setAppPackageName(context.packageName)+ setSize(apk.length())+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)+ setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED)+ }+ val id = installer.createSession(params)+ installer.openSession(id).use { session ->+ session.openWrite("myspoti.apk", 0, apk.length()).use { out ->+ apk.inputStream().use { it.copyTo(out) }+ session.fsync(out)+ }+ val callback = PendingIntent.getBroadcast(+ context, id,+ Intent(ACTION).setPackage(context.packageName).setClass(context, StatusReceiver::class.java),+ // Mutable: the installer adds the status extras.+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE,+ )+ session.commit(callback.intentSender)+ }+ }++ /** The installer's answer: ask the user to confirm, or report the failure. */+ class StatusReceiver : BroadcastReceiver() {+ override fun onReceive(context: Context, intent: Intent) {+ when (val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) {+ PackageInstaller.STATUS_PENDING_USER_ACTION -> {+ @Suppress("DEPRECATION")+ val confirm = if (Build.VERSION.SDK_INT >= 33) intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent::class.java)+ else intent.getParcelableExtra(Intent.EXTRA_INTENT)+ confirm?.let { context.startActivity(it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) }+ }+ // On success this process is replaced by the new version.+ PackageInstaller.STATUS_SUCCESS -> _state.value = State.Idle+ PackageInstaller.STATUS_FAILURE_ABORTED -> _state.value = State.Idle+ else -> _state.value = State.Failed(+ intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) ?: "install status $status",+ )+ }+ }+ }+}diff --git a/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt b/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.ktindex b1b0fd04..9c034e36 100644--- a/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt+++ b/base/app/src/main/java/com/music/spotui/data/api/UpdateChecker.kt@@ -12,11 +12,12 @@ import java.util.concurrent.TimeUnit/*** New version check against the GitHub releases of [BuildConfig.UPDATE_REPO]* (set by the CI build; empty in local builds, which never check).- * At most one request every 3 hours (releases can come several a day); the app only- * opens the release page, never installs.+ * At most one request every 3 hours (releases can come several a day). The release's+ * APK is downloaded and installed in the app ([AppUpdater]).*/object UpdateChecker {- data class Release(val version: String, val pageUrl: String, val notes: String = "")+ /** [apkUrl]: the release's signed APK; blank when the release has none (then its page opens). */+ data class Release(val version: String, val pageUrl: String, val notes: String = "", val apkUrl: String = "")private const val INTERVAL_MS = 3 * 3_600_000Lprivate val http by lazy { OkHttpClient.Builder().callTimeout(10, TimeUnit.SECONDS).addInterceptor(com.music.spotui.data.DataSaver.interceptor).build() }@@ -38,13 +39,13 @@ object UpdateChecker {val list = if (isBeta) org.json.JSONArray(text).let { a -> (0 until a.length()).map { a.getJSONObject(it) } } else listOf(JSONObject(text))// Betas and releases are two apps: each one is offered its own channel only.list.filter { !it.optBoolean("draft") && (!isBeta || it.optBoolean("prerelease")) }- .map { Release(it.getString("tag_name").removePrefix("v"), it.getString("html_url"), cleanNotes(it.optString("body"))) }+ .map { Release(it.getString("tag_name").removePrefix("v"), it.getString("html_url"), cleanNotes(it.optString("body")), apkAsset(it)) }.reduceOrNull { best, next -> if (isNewer(next.version, best.version)) next else best }}}.getOrNull()prefs.edit().putLong("checked_at", now).putString("version", release?.version).putString("url", release?.pageUrl)- .putString("notes", release?.notes).apply()+ .putString("notes", release?.notes).putString("apk", release?.apkUrl).apply()pending(prefs)}@@ -53,7 +54,15 @@ object UpdateChecker {val version = prefs.getString("version", null) ?: return nullval url = prefs.getString("url", null) ?: return nullif (prefs.getString("dismissed", null) == version) return null- return Release(version, url, prefs.getString("notes", null).orEmpty()).takeIf { isNewer(version, BuildConfig.VERSION_NAME) }+ return Release(version, url, prefs.getString("notes", null).orEmpty(), prefs.getString("apk", null).orEmpty()).takeIf { isNewer(version, BuildConfig.VERSION_NAME) }+ }++ /** The release's APK download link (the CI uploads one `myspoti-<version>.apk`). */+ internal fun apkAsset(release: JSONObject): String {+ val assets = release.optJSONArray("assets") ?: return ""+ return (0 until assets.length()).map { assets.getJSONObject(it) }+ .firstOrNull { it.optString("name").endsWith(".apk", ignoreCase = true) }+ ?.optString("browser_download_url").orEmpty()}fun dismiss(context: Context, release: Release) {diff --git a/base/app/src/main/res/values-fr/myspoti_strings.xml b/base/app/src/main/res/values-fr/myspoti_strings.xmlindex 5742ee71..913c0d02 100644--- a/base/app/src/main/res/values-fr/myspoti_strings.xml+++ b/base/app/src/main/res/values-fr/myspoti_strings.xml@@ -249,4 +249,10 @@<string name="quality_now">En cours : %1$s</string><string name="quality_now_unknown">Pas encore connue : lancez un titre</string><string name="spotiflac_verify_in_browser">Résolvez la vérification dans l\'onglet du navigateur qui s\'est ouvert, puis revenez ici.</string>+ <string name="update_downloading">Téléchargement… %1$d%%</string>+ <string name="update_installing">Installation…</string>+ <string name="update_needs_permission">Pour mettre à jour, autorisez Myspoti à installer des applications, puis revenez ici.</string>+ <string name="update_allow">Autoriser</string>+ <string name="update_failed">La mise à jour a échoué : %1$s</string>+ <string name="update_retry">Réessayer</string></resources>diff --git a/base/app/src/main/res/values-it/myspoti_strings.xml b/base/app/src/main/res/values-it/myspoti_strings.xmlindex 5aef3d18..2c2e8089 100644--- a/base/app/src/main/res/values-it/myspoti_strings.xml+++ b/base/app/src/main/res/values-it/myspoti_strings.xml@@ -249,4 +249,10 @@<string name="quality_now">In riproduzione: %1$s</string><string name="quality_now_unknown">Non ancora nota: avvia un brano</string><string name="spotiflac_verify_in_browser">Completa la verifica nella scheda del browser che si è aperta, poi torna qui.</string>+ <string name="update_downloading">Download… %1$d%%</string>+ <string name="update_installing">Installazione…</string>+ <string name="update_needs_permission">Per aggiornare, consenti a Myspoti di installare app, poi torna qui.</string>+ <string name="update_allow">Consenti</string>+ <string name="update_failed">Aggiornamento non riuscito: %1$s</string>+ <string name="update_retry">Riprova</string></resources>diff --git a/base/app/src/main/res/values/myspoti_strings.xml b/base/app/src/main/res/values/myspoti_strings.xmlindex 6b7a5a76..20cd13cb 100644--- a/base/app/src/main/res/values/myspoti_strings.xml+++ b/base/app/src/main/res/values/myspoti_strings.xml@@ -249,4 +249,10 @@<string name="quality_now">Playing now: %1$s</string><string name="quality_now_unknown">Not known yet: start a song</string><string name="spotiflac_verify_in_browser">Solve the check in the browser tab that opened, then come back here.</string>+ <string name="update_downloading">Downloading… %1$d%%</string>+ <string name="update_installing">Installing…</string>+ <string name="update_needs_permission">To update, allow Myspoti to install apps, then come back here.</string>+ <string name="update_allow">Allow</string>+ <string name="update_failed">The update failed: %1$s</string>+ <string name="update_retry">Try again</string></resources>diff --git a/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt b/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.ktindex d5176f30..8f9f6208 100644--- a/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt+++ b/base/app/src/test/java/com/music/spotui/data/api/UpdateCheckerTest.kt@@ -25,4 +25,11 @@ class UpdateCheckerTest {val body = "- **Local Files**: a folder\n - nested [link](https://x.y)\n\n**Full Changelog**: https://github.com/a/b/compare/v1...v2"assertEquals("• Local Files: a folder\n • nested link", UpdateChecker.cleanNotes(body))}+ @Test fun findsTheReleaseApk() {+ val release = org.json.JSONObject("""{"assets":[+ {"name":"checksums.txt","browser_download_url":"https://x/c.txt"},+ {"name":"myspoti-2.0.0-beta.4.apk","browser_download_url":"https://x/myspoti.apk"}]}""")+ assertEquals("https://x/myspoti.apk", UpdateChecker.apkAsset(release))+ assertEquals("", UpdateChecker.apkAsset(org.json.JSONObject("{}")))+ }}