diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 433e315..47c5c8f 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -43,7 +43,7 @@ android { } val releaseSigning = if (hasReleaseKeystore) signingConfigs.getByName("release") else null - val baseVersionName = "2.5.4" + val baseVersionName = "2.5.5" defaultConfig { applicationId = "me.shirobyte42.glosso" @@ -58,7 +58,9 @@ android { // 2222 is 2.5.0: American English, "Your turn" and spaced review. // 2223 is 2.5.1: Russian A1 rewritten from Russian culture. // 2226 is 2.5.4: the v2 usage statistics and crash reports. - versionCode = 2226 + // 2227 is 2.5.5: Spanish, the course switcher and the first F-Droid build. + // 2227 is 2.5.5: the first F-Droid release; server-anchored time for streaks. + versionCode = 2227 versionName = baseVersionName testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/androidApp/src/main/java/com/glosso/app/GlossoApplication.kt b/androidApp/src/main/java/com/glosso/app/GlossoApplication.kt index 0d47818..d584581 100644 --- a/androidApp/src/main/java/com/glosso/app/GlossoApplication.kt +++ b/androidApp/src/main/java/com/glosso/app/GlossoApplication.kt @@ -36,6 +36,7 @@ class GlossoApplication : Application(), SingletonImageLoader.Factory { wireSharedCode() ServerPreferences.init(this, BuildConfig.API_BASE_URL) DeviceId.init(this) + TrustedClock.init(this) Analytics.init(this) CrashReporter.install(this) ApiCache.init(this) diff --git a/deploy/.env.example b/deploy/.env.example index 3508880..c583969 100644 --- a/deploy/.env.example +++ b/deploy/.env.example @@ -84,7 +84,8 @@ GLOSSO_ASSET_CHECKSUMS= # Reconocimientos simultaneos (2 vCPU: no subir de 1-2). GLOSSO_MAX_CONCURRENT=1 # Espera maxima en cola antes de devolver 503 (ms). -GLOSSO_QUEUE_WAIT_MS=30000 +GLOSSO_QUEUE_WAIT_MS=12000 +GLOSSO_MAX_QUEUED=8 # 1 = logs del engine (fonemas). Dejar vacio en produccion. GLOSSO_DEBUG= # Origenes CORS permitidos para web, separados por coma. Vacio = sin CORS. diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 0552ab2..eb870e9 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -112,7 +112,8 @@ services: GLOSSO_INGEST_TOKEN: ${GLOSSO_INGEST_TOKEN:-} GLOSSO_BOOTSTRAP: ${GLOSSO_BOOTSTRAP:-} GLOSSO_MAX_CONCURRENT: ${GLOSSO_MAX_CONCURRENT:-1} - GLOSSO_QUEUE_WAIT_MS: ${GLOSSO_QUEUE_WAIT_MS:-30000} + GLOSSO_QUEUE_WAIT_MS: ${GLOSSO_QUEUE_WAIT_MS:-12000} + GLOSSO_MAX_QUEUED: ${GLOSSO_MAX_QUEUED:-8} GLOSSO_DEBUG: ${GLOSSO_DEBUG:-} GLOSSO_ANALYTICS_RETENTION_DAYS: ${GLOSSO_ANALYTICS_RETENTION_DAYS:-180} # Copia de los eventos de la app en umami (docs/ANALYTICS-BETA.md). Vacio diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 726cd8a..3bfbb00 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -66,7 +66,8 @@ sudo systemctl enable --now glosso-server | `GLOSSO_ASSETS_DIR` | `data/assets` | Carpeta de assets estaticos | | `GLOSSO_BOOTSTRAP` | (vacio) | `1` descarga modelo/vocab/CMUdict en el primer arranque | | `GLOSSO_MAX_CONCURRENT` | `1` | Reconocimientos simultaneos admitidos | -| `GLOSSO_QUEUE_WAIT_MS` | `30000` | Espera maxima en cola antes de devolver 503 | +| `GLOSSO_QUEUE_WAIT_MS` | `12000` | Espera maxima en cola antes de devolver 503; menor que el timeout de puntuacion de la app (30 s) | +| `GLOSSO_MAX_QUEUED` | `8` | Puntuaciones en espera como maximo; con la cola llena el servidor responde 503 al instante y la app reintenta | | `GLOSSO_DEBUG` | (vacio) | `1` activa logs del engine (fonemas) | | `GLOSSO_ADMIN_TOKEN` | (vacio) | Token que protege `/metrics`, `/stats` y las vistas de analitica. Sin el, cerrados | | `GLOSSO_API_KEY` | (vacio) | Credencial de cliente (`X-Api-Key`) que protege `/v1/score`. Sin ella, scoring abierto (dev/emulador). **No definir en produccion hasta que la app envie la cabecera** | diff --git a/docs/FDROID.md b/docs/FDROID.md index 9a6e7e5..aadef9f 100644 --- a/docs/FDROID.md +++ b/docs/FDROID.md @@ -89,6 +89,14 @@ The only binary in git is `gradle/wrapper/gradle-wrapper.jar`, which the scanner removes on its own. Repositories are only `google()`, `mavenCentral()` and the Gradle plugin portal. The model, vocabulary and content are gitignored. +**The web app's binaries.** The repository also holds the web app (`docs/WEB.md`), +whose Ogg decoder is a committed WebAssembly build of the vendored stb_vorbis +(`shared/src/wasmJsMain/resources/stb_vorbis.wasm`, built from source by +`shared/src/nativeInterop/stb_vorbis/build-wasm.sh`). `fdroid scanner` flags it +as a binary. The Android app never uses it, so the recipe deletes it (`rm:`) and +turns the web target off (`glosso.web=false`), which also keeps the Kotlin/Wasm +toolchain (a prebuilt Node download) out of the F-Droid build. + **Self-updater.** None. The server's version policy is only a dismissible notice with no link and no download. @@ -123,3 +131,25 @@ ones `tools/fetch-assets.sh` downloads. Lesson packs are not importable: they are fetched per lesson from the content manifest and have no file format of their own yet. + +## Releasing a version to F-Droid + +Checked for 2.5.5 (2227) on 2026-11-22: the steps below passed locally. + +1. Bump `baseVersionName` and `versionCode` in `androidApp/build.gradle.kts`, add + `fastlane/metadata/android//changelogs/.txt` (max 500 + characters) for every locale, and set the same version in the recipe's build + entry, `CurrentVersion` and `CurrentVersionCode`. +2. Check the recipe and the build the way F-Droid runs them: + - `fdroid readmeta` and `fdroid lint me.shirobyte42.glosso` in a directory with + the recipe under `metadata/` and fdroiddata's `config/` (sparse clone of + https://gitlab.com/fdroid/fdroiddata). + - From a fresh clone of the tagged commit, delete the `rm:` paths, then + `ANDROID_HOME=... ./gradlew :androidApp:assembleFdroidRelease -Pglosso.ios=false -Pglosso.web=false`. + - `fdroid scanner --exit-code` on that APK, and the scanner's `scan_source` on + the clone: the only source finding is the `rm:`'d `stb_vorbis.wasm`. +3. Tag the release commit `v` and push the tag. F-Droid builds from + tags (`UpdateCheckMode: Tags`), and the recipe's `commit:` is the tag. +4. First submission only: open the merge request to fdroiddata with + `metadata/me.shirobyte42.glosso.yml`. Later versions are picked up from new + tags (`AutoUpdateMode: Version`). diff --git a/fastlane/metadata/android/ar/full_description.txt b/fastlane/metadata/android/ar/full_description.txt index c696531..6c26d55 100644 --- a/fastlane/metadata/android/ar/full_description.txt +++ b/fastlane/metadata/android/ar/full_description.txt @@ -1,6 +1,6 @@ تطبيق Glosso دورة لغات تقيس نطقك فعلًا. يستمع إلى كل تسجيل، ويتعرف على الأصوات التي نطقتها حقًا، ويقارنها بالأصوات المتوقعة، ثم يخبرك بالضبط أي صوت تحتاج إلى تصحيحه. -اللغات: الإنجليزية (البريطانية والأمريكية) والفرنسية والألمانية والروسية. +الدورات: الإنجليزية (البريطانية والأمريكية)، إضافة إلى الروسية والإسبانية كدورتين تجريبيتين للمبتدئين. ما ستحصل عليه
    diff --git a/fastlane/metadata/android/de-DE/changelogs/2227.txt b/fastlane/metadata/android/de-DE/changelogs/2227.txt new file mode 100644 index 0000000..56641a6 --- /dev/null +++ b/fastlane/metadata/android/de-DE/changelogs/2227.txt @@ -0,0 +1,9 @@ +- Neu: Spanisch lernen (experimentell) und ein umfangreicherer Russischkurs. +- Kurs mit einem Tipp unter Heute oder Lektionen wechseln. +- Freies Üben ist jetzt unter Heute. +- Das Üben konzentriert sich auf deine schwierigsten Laute. +- Klarere Korrekturen und gemischte Antworten. +- Jede Sprache steht unter ihrem eigenen Namen. +- Flüssigerer Startbildschirm. +- Serien zählen nach Serverzeit, nicht nach der Handyuhr. +- Ein Download ohne Verbindung zeigt nun, dass er wartet. diff --git a/fastlane/metadata/android/de-DE/full_description.txt b/fastlane/metadata/android/de-DE/full_description.txt index 110c0da..8045849 100644 --- a/fastlane/metadata/android/de-DE/full_description.txt +++ b/fastlane/metadata/android/de-DE/full_description.txt @@ -1,6 +1,6 @@ Glosso ist ein Sprachkurs, der deine Aussprache wirklich misst. Er hört jeden Versuch, erkennt die Laute, die du tatsächlich gesprochen hast, vergleicht sie mit den erwarteten und sagt dir genau, welchen Laut du verbessern solltest. -Sprachen: Englisch (britisch und amerikanisch), Französisch, Deutsch und Russisch. +Kurse: Englisch (britisch und amerikanisch), dazu Russisch und Spanisch als experimentelle Anfängerkurse. Was du bekommst
      diff --git a/fastlane/metadata/android/en-US/changelogs/2227.txt b/fastlane/metadata/android/en-US/changelogs/2227.txt new file mode 100644 index 0000000..68849b1 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/2227.txt @@ -0,0 +1,9 @@ +- New: learn Spanish (experimental), and a fuller Russian course. +- Switch course in one tap from Today or Lessons. +- Free practice is now on Today. +- Practice focuses on the sounds you miss most. +- Clearer corrections and shuffled answers. +- Each language appears under its own name. +- Smoother first-run screen. +- Streaks count by the server's time, not the phone's clock. +- A model download started offline now shows that it is waiting. diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt index ae391a4..f9053d4 100644 --- a/fastlane/metadata/android/en-US/full_description.txt +++ b/fastlane/metadata/android/en-US/full_description.txt @@ -1,6 +1,6 @@ Glosso is a language course that measures your pronunciation for real. It listens to each take, recognizes the sounds you actually made, compares them with the expected ones and tells you exactly which sound to fix. -Languages: English (British and American), French, German and Russian. +Courses: English (British and American), plus Russian and Spanish as experimental beginner courses. What you get
        diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png index 3c27856..defb308 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png index 9eff311..c4f6fe7 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png index 4bcd39d..b701a03 100644 Binary files a/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png and b/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png new file mode 100644 index 0000000..552cc5a Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png new file mode 100644 index 0000000..e7d95fa Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/6.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/6.png new file mode 100644 index 0000000..30e56f1 Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/6.png differ diff --git a/fastlane/metadata/android/en-US/images/phoneScreenshots/7.png b/fastlane/metadata/android/en-US/images/phoneScreenshots/7.png new file mode 100644 index 0000000..54ee8e5 Binary files /dev/null and b/fastlane/metadata/android/en-US/images/phoneScreenshots/7.png differ diff --git a/fastlane/metadata/android/es-ES/changelogs/2227.txt b/fastlane/metadata/android/es-ES/changelogs/2227.txt new file mode 100644 index 0000000..2e6bc7e --- /dev/null +++ b/fastlane/metadata/android/es-ES/changelogs/2227.txt @@ -0,0 +1,9 @@ +- Nuevo: aprende español (experimental) y un curso de ruso más completo. +- Cambia de curso con un toque desde Hoy o Lecciones. +- La práctica libre ahora está en Hoy. +- La práctica se centra en los sonidos que más fallas. +- Correcciones más claras y respuestas barajadas. +- Cada idioma aparece con su propio nombre. +- Pantalla de bienvenida más fluida. +- Las rachas usan la hora del servidor, no la del móvil. +- Una descarga del modelo sin conexión ahora indica que está esperando. diff --git a/fastlane/metadata/android/es-ES/full_description.txt b/fastlane/metadata/android/es-ES/full_description.txt index 41298f5..96c6f80 100644 --- a/fastlane/metadata/android/es-ES/full_description.txt +++ b/fastlane/metadata/android/es-ES/full_description.txt @@ -1,6 +1,6 @@ Glosso es un curso de idiomas que mide tu pronunciación de verdad. Escucha cada intento, reconoce los sonidos que has hecho de verdad, los compara con los esperados y te dice exactamente qué sonido corregir. -Idiomas: inglés (británico y americano), francés, alemán y ruso. +Cursos: inglés (británico y americano), además de ruso y español como cursos experimentales de nivel inicial. Qué incluye
          diff --git a/fastlane/metadata/android/fr-FR/changelogs/2227.txt b/fastlane/metadata/android/fr-FR/changelogs/2227.txt new file mode 100644 index 0000000..672f499 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/2227.txt @@ -0,0 +1,9 @@ +- Nouveau : apprenez l'espagnol (expérimental), et un cours de russe plus complet. +- Changez de cours en un geste depuis Aujourd'hui ou Leçons. +- La pratique libre est maintenant sur Aujourd'hui. +- La pratique cible les sons que vous ratez le plus. +- Corrections plus claires et réponses mélangées. +- Chaque langue apparaît sous son propre nom. +- Écran d'accueil plus fluide. +- Les séries suivent l'heure du serveur, pas celle du téléphone. +- Un téléchargement hors ligne indique son attente. diff --git a/fastlane/metadata/android/fr-FR/full_description.txt b/fastlane/metadata/android/fr-FR/full_description.txt index daeb33a..24e8ab1 100644 --- a/fastlane/metadata/android/fr-FR/full_description.txt +++ b/fastlane/metadata/android/fr-FR/full_description.txt @@ -1,6 +1,6 @@ Glosso est un cours de langues qui mesure vraiment votre prononciation. Il écoute chaque essai, reconnaît les sons que vous avez réellement produits, les compare aux sons attendus et vous dit exactement quel son corriger. -Langues : anglais (britannique et américain), français, allemand et russe. +Cours : anglais (britannique et américain), ainsi que russe et espagnol en cours expérimentaux pour débutants. Ce que vous obtenez
            diff --git a/fastlane/metadata/android/hi-IN/full_description.txt b/fastlane/metadata/android/hi-IN/full_description.txt index 6ab2929..aaddbe5 100644 --- a/fastlane/metadata/android/hi-IN/full_description.txt +++ b/fastlane/metadata/android/hi-IN/full_description.txt @@ -1,6 +1,6 @@ Glosso एक भाषा कोर्स है जो आपके उच्चारण को सच में जाँचता है। यह आपकी हर रिकॉर्डिंग सुनता है, पहचानता है कि आपने असल में कौन से साउंड बोले, उन्हें सही साउंड से मिलाता है और ठीक-ठीक बताता है कि कौन सा साउंड सुधारना है। -भाषाएँ: अंग्रेज़ी (ब्रिटिश और अमेरिकन), फ़्रेंच, जर्मन और रूसी। +कोर्स: अंग्रेज़ी (ब्रिटिश और अमेरिकन), साथ ही रूसी और स्पैनिश शुरुआती स्तर के प्रायोगिक कोर्स के रूप में। आपको क्या मिलता है
              diff --git a/fastlane/metadata/android/ru-RU/full_description.txt b/fastlane/metadata/android/ru-RU/full_description.txt index f5d0f38..5463fc1 100644 --- a/fastlane/metadata/android/ru-RU/full_description.txt +++ b/fastlane/metadata/android/ru-RU/full_description.txt @@ -1,6 +1,6 @@ Glosso - курс иностранных языков, который по-настоящему оценивает ваше произношение. Приложение слушает каждую попытку, распознаёт звуки, которые вы действительно произнесли, сравнивает их с эталоном и точно говорит, какой звук нужно исправить. -Языки: английский (британский и американский), французский, немецкий и русский. +Курсы: английский (британский и американский), а также русский и испанский как экспериментальные курсы для начинающих. Что вы получаете
                diff --git a/metadata/me.shirobyte42.glosso.yml b/metadata/me.shirobyte42.glosso.yml index ab1be64..2a4c705 100644 --- a/metadata/me.shirobyte42.glosso.yml +++ b/metadata/me.shirobyte42.glosso.yml @@ -17,16 +17,19 @@ RepoType: git Repo: https://github.com/IgnacioLD/glosso.git Builds: - - versionName: 2.5.4 - versionCode: 2226 - commit: v2.5.4 + - versionName: 2.5.5 + versionCode: 2227 + commit: v2.5.5 subdir: androidApp + rm: + - shared/src/wasmJsMain/resources/stb_vorbis.wasm gradle: - fdroid gradleprops: - glosso.ios=false + - glosso.web=false AutoUpdateMode: Version UpdateCheckMode: Tags -CurrentVersion: 2.5.4 -CurrentVersionCode: 2226 +CurrentVersion: 2.5.5 +CurrentVersionCode: 2227 diff --git a/server/src/main/kotlin/com/glosso/server/Application.kt b/server/src/main/kotlin/com/glosso/server/Application.kt index a181403..1640bd5 100644 --- a/server/src/main/kotlin/com/glosso/server/Application.kt +++ b/server/src/main/kotlin/com/glosso/server/Application.kt @@ -51,9 +51,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.withContext -import kotlinx.coroutines.withTimeoutOrNull import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonElement @@ -728,10 +726,14 @@ fun Application.module( // test shows the host benefits from it. val maxConcurrent = System.getenv("GLOSSO_MAX_CONCURRENT")?.toIntOrNull()?.coerceAtLeast(1) ?: 1 - val queueWaitMs = System.getenv("GLOSSO_QUEUE_WAIT_MS")?.toLongOrNull() ?: 30_000L - val inferenceSlots = Semaphore(maxConcurrent) + // Below the app's 30 s score timeout minus a slow inference, so a busy server + // answers 503 (the app retries) instead of the phone timing out mid-wait. + val queueWaitMs = System.getenv("GLOSSO_QUEUE_WAIT_MS")?.toLongOrNull() ?: 12_000L + // Beyond this many waiting takes the server answers 503 at once (the app retries). + val maxQueued = System.getenv("GLOSSO_MAX_QUEUED")?.toIntOrNull()?.coerceAtLeast(0) ?: 8 + val inferenceGate = InferenceGate(maxConcurrent, maxQueued, queueWaitMs) val inFlight = AtomicInteger(0) - logger.info { "Inference gate: maxConcurrent=$maxConcurrent, queueWaitMs=$queueWaitMs" } + logger.info { "Inference gate: maxConcurrent=$maxConcurrent, maxQueued=$maxQueued, queueWaitMs=$queueWaitMs" } // First-party analytics: the store the caller passed (the production // overload builds it from the environment); null disables it cleanly. @@ -1297,10 +1299,7 @@ fun Application.module( // Suspend while waiting for a slot; never block a thread, or the // dispatcher starves and inference collapses. - val admitted = withTimeoutOrNull(queueWaitMs) { - inferenceSlots.acquire() - true - } ?: false + val admitted = inferenceGate.admit() if (!admitted) { scoreBusy.increment() call.response.header(HttpHeaders.RetryAfter, "2") @@ -1334,7 +1333,7 @@ fun Application.module( analysis.recognition.ipa } finally { inFlight.decrementAndGet() - inferenceSlots.release() + inferenceGate.release() } } else if (!request.actualIpa.isNullOrBlank()) { request.actualIpa @@ -1474,10 +1473,7 @@ fun Application.module( ErrorResponse("Recognition model is not ready"), ) } - val admitted = withTimeoutOrNull(queueWaitMs) { - inferenceSlots.acquire() - true - } ?: false + val admitted = inferenceGate.admit() if (!admitted) { scoreBusy.increment() call.response.header(HttpHeaders.RetryAfter, "2") @@ -1491,7 +1487,7 @@ fun Application.module( withContext(Dispatchers.Default) { recognizer.recognize(request.audioBase64) } } finally { inFlight.decrementAndGet() - inferenceSlots.release() + inferenceGate.release() } if (ipa.isNullOrBlank()) { scoreError.increment() @@ -1550,10 +1546,7 @@ fun Application.module( ErrorResponse("Recognition model is not ready"), ) } - val admitted = withTimeoutOrNull(queueWaitMs) { - inferenceSlots.acquire() - true - } ?: false + val admitted = inferenceGate.admit() if (!admitted) { scoreBusy.increment() call.response.header(HttpHeaders.RetryAfter, "2") @@ -1567,7 +1560,7 @@ fun Application.module( withContext(Dispatchers.Default) { recognizer.analyze(request.audioBase64, expectedIpa) } } finally { inFlight.decrementAndGet() - inferenceSlots.release() + inferenceGate.release() } if (analysis == null) { scoreError.increment() @@ -2250,7 +2243,8 @@ fun Application.module( mapOf( "inFlight" to inFlight.get(), "maxConcurrent" to maxConcurrent, - "availableSlots" to inferenceSlots.availablePermits, + "availableSlots" to inferenceGate.availablePermits, + "queued" to inferenceGate.queued, ), ) } diff --git a/server/src/main/kotlin/com/glosso/server/InferenceGate.kt b/server/src/main/kotlin/com/glosso/server/InferenceGate.kt new file mode 100644 index 0000000..014fe7c --- /dev/null +++ b/server/src/main/kotlin/com/glosso/server/InferenceGate.kt @@ -0,0 +1,35 @@ +package com.glosso.server + +import java.util.concurrent.atomic.AtomicInteger +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.withTimeoutOrNull + +/** + * Admission to the CPU-bound recognizer: [maxConcurrent] runs at a time, at most + * [maxWaiting] requests queued behind them, each for at most [waitMs]. A full + * queue is refused at once, so a burst gets a fast 503 the app retries instead + * of everyone waiting out the clock and failing together. + */ +class InferenceGate(maxConcurrent: Int, private val maxWaiting: Int, private val waitMs: Long) { + private val slots = Semaphore(maxConcurrent) + private val waiting = AtomicInteger(0) + + val availablePermits: Int get() = slots.availablePermits + val queued: Int get() = waiting.get() + + /** True with a slot held (pair with [release]); false means answer 503. */ + suspend fun admit(): Boolean { + if (slots.tryAcquire()) return true + if (waiting.incrementAndGet() > maxWaiting) { + waiting.decrementAndGet() + return false + } + return try { + withTimeoutOrNull(waitMs) { slots.acquire(); true } ?: false + } finally { + waiting.decrementAndGet() + } + } + + fun release() = slots.release() +} diff --git a/server/src/test/kotlin/com/glosso/server/InferenceGateTest.kt b/server/src/test/kotlin/com/glosso/server/InferenceGateTest.kt new file mode 100644 index 0000000..197ced7 --- /dev/null +++ b/server/src/test/kotlin/com/glosso/server/InferenceGateTest.kt @@ -0,0 +1,33 @@ +package com.glosso.server + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlinx.coroutines.async +import kotlinx.coroutines.test.advanceTimeBy +import kotlinx.coroutines.test.runTest + +class InferenceGateTest { + + @Test + fun fullQueueIsRefusedAtOnce() = runTest { + val gate = InferenceGate(maxConcurrent = 1, maxWaiting = 1, waitMs = 10_000) + assertTrue(gate.admit()) + val queued = async { gate.admit() } + advanceTimeBy(1) + assertEquals(1, gate.queued) + assertFalse(gate.admit()) // the queue is full: no wait + gate.release() + assertTrue(queued.await()) + assertEquals(0, gate.queued) + } + + @Test + fun waitRunsOut() = runTest { + val gate = InferenceGate(maxConcurrent = 1, maxWaiting = 4, waitMs = 1_000) + assertTrue(gate.admit()) + assertFalse(gate.admit()) + assertEquals(0, gate.queued) + } +} diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 4dba725..48a220b 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -162,6 +162,7 @@ kotlin { dependencies { implementation(kotlin("test")) implementation(libs.kotlinx.coroutines.test) + implementation(libs.ktor.client.mock) } } findByName("androidMain")?.dependencies { diff --git a/shared/src/androidMain/kotlin/com/glosso/app/platform/Time.android.kt b/shared/src/androidMain/kotlin/com/glosso/app/platform/Time.android.kt index cdedf5c..a2180bb 100644 --- a/shared/src/androidMain/kotlin/com/glosso/app/platform/Time.android.kt +++ b/shared/src/androidMain/kotlin/com/glosso/app/platform/Time.android.kt @@ -1,5 +1,11 @@ package com.glosso.app.platform -import java.time.LocalDate +import android.os.SystemClock +import java.time.Instant +import java.time.ZoneId -actual fun todayEpochDay(): Long = LocalDate.now().toEpochDay() +// Counts deep sleep too, so an anchored time stays right overnight. +actual fun monotonicMillis(): Long = SystemClock.elapsedRealtime() + +actual fun epochDayAt(epochMillis: Long): Long = + Instant.ofEpochMilli(epochMillis).atZone(ZoneId.systemDefault()).toLocalDate().toEpochDay() diff --git a/shared/src/commonMain/composeResources/files/licenses.json b/shared/src/commonMain/composeResources/files/licenses.json index 96ca4bd..e4ea20a 100644 --- a/shared/src/commonMain/composeResources/files/licenses.json +++ b/shared/src/commonMain/composeResources/files/licenses.json @@ -20,7 +20,7 @@ "id": "androidx.activity:activity", "name": "activity", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -33,7 +33,7 @@ "id": "androidx.activity:activity-compose", "name": "activity-compose", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -46,7 +46,7 @@ "id": "androidx.activity:activity-ktx", "name": "activity-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -59,7 +59,7 @@ "id": "androidx.annotation:annotation", "name": "annotation", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -72,7 +72,7 @@ "id": "androidx.annotation:annotation-experimental", "name": "annotation-experimental", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -85,7 +85,7 @@ "id": "androidx.annotation:annotation-jvm", "name": "annotation-jvm", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -98,7 +98,7 @@ "id": "androidx.appcompat:appcompat", "name": "appcompat", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -111,7 +111,7 @@ "id": "androidx.appcompat:appcompat-resources", "name": "appcompat-resources", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -124,7 +124,7 @@ "id": "androidx.arch.core:core-common", "name": "core-common", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -137,7 +137,7 @@ "id": "androidx.arch.core:core-runtime", "name": "core-runtime", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -150,7 +150,7 @@ "id": "androidx.autofill:autofill", "name": "autofill", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -163,7 +163,7 @@ "id": "androidx.biometric:biometric", "name": "biometric", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -176,7 +176,7 @@ "id": "androidx.collection:collection", "name": "collection", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -189,7 +189,7 @@ "id": "androidx.collection:collection-jvm", "name": "collection-jvm", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -202,7 +202,7 @@ "id": "androidx.collection:collection-ktx", "name": "collection-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -215,7 +215,7 @@ "id": "androidx.compose.animation:animation", "name": "animation", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -228,7 +228,7 @@ "id": "androidx.compose.animation:animation-android", "name": "animation-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -241,7 +241,7 @@ "id": "androidx.compose.animation:animation-core", "name": "animation-core", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -254,7 +254,7 @@ "id": "androidx.compose.animation:animation-core-android", "name": "animation-core-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -267,7 +267,7 @@ "id": "androidx.compose.foundation:foundation", "name": "foundation", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -280,7 +280,7 @@ "id": "androidx.compose.foundation:foundation-android", "name": "foundation-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -293,7 +293,7 @@ "id": "androidx.compose.foundation:foundation-layout", "name": "foundation-layout", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -306,7 +306,7 @@ "id": "androidx.compose.foundation:foundation-layout-android", "name": "foundation-layout-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -319,7 +319,7 @@ "id": "androidx.compose.material3:material3", "name": "material3", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -332,7 +332,7 @@ "id": "androidx.compose.material3:material3-android", "name": "material3-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -345,7 +345,7 @@ "id": "androidx.compose.material:material-icons-core", "name": "material-icons-core", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -358,7 +358,7 @@ "id": "androidx.compose.material:material-icons-core-android", "name": "material-icons-core-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -371,7 +371,7 @@ "id": "androidx.compose.material:material-icons-extended", "name": "material-icons-extended", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -384,7 +384,7 @@ "id": "androidx.compose.material:material-icons-extended-android", "name": "material-icons-extended-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -397,7 +397,7 @@ "id": "androidx.compose.material:material-ripple", "name": "material-ripple", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -410,7 +410,7 @@ "id": "androidx.compose.material:material-ripple-android", "name": "material-ripple-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -423,7 +423,7 @@ "id": "androidx.compose.runtime:runtime", "name": "runtime", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -436,7 +436,7 @@ "id": "androidx.compose.runtime:runtime-android", "name": "runtime-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -449,7 +449,7 @@ "id": "androidx.compose.runtime:runtime-annotation", "name": "runtime-annotation", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -462,7 +462,7 @@ "id": "androidx.compose.runtime:runtime-annotation-android", "name": "runtime-annotation-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -475,7 +475,7 @@ "id": "androidx.compose.runtime:runtime-retain", "name": "runtime-retain", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -488,7 +488,7 @@ "id": "androidx.compose.runtime:runtime-retain-android", "name": "runtime-retain-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -501,7 +501,7 @@ "id": "androidx.compose.runtime:runtime-saveable", "name": "runtime-saveable", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -514,7 +514,7 @@ "id": "androidx.compose.runtime:runtime-saveable-android", "name": "runtime-saveable-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -527,7 +527,7 @@ "id": "androidx.compose.ui:ui", "name": "ui", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -540,7 +540,7 @@ "id": "androidx.compose.ui:ui-android", "name": "ui-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -553,7 +553,7 @@ "id": "androidx.compose.ui:ui-geometry", "name": "ui-geometry", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -566,7 +566,7 @@ "id": "androidx.compose.ui:ui-geometry-android", "name": "ui-geometry-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -579,7 +579,7 @@ "id": "androidx.compose.ui:ui-graphics", "name": "ui-graphics", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -592,7 +592,7 @@ "id": "androidx.compose.ui:ui-graphics-android", "name": "ui-graphics-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -605,7 +605,7 @@ "id": "androidx.compose.ui:ui-test-junit4", "name": "ui-test-junit4", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Test-only dependency; not shipped in the app.", "distribution": "test", "license": "Apache-2.0", @@ -618,7 +618,7 @@ "id": "androidx.compose.ui:ui-test-manifest", "name": "ui-test-manifest", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -631,7 +631,7 @@ "id": "androidx.compose.ui:ui-text", "name": "ui-text", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -644,7 +644,7 @@ "id": "androidx.compose.ui:ui-text-android", "name": "ui-text-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -657,7 +657,7 @@ "id": "androidx.compose.ui:ui-tooling", "name": "ui-tooling", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -670,7 +670,7 @@ "id": "androidx.compose.ui:ui-tooling-android", "name": "ui-tooling-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -683,7 +683,7 @@ "id": "androidx.compose.ui:ui-tooling-data", "name": "ui-tooling-data", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -696,7 +696,7 @@ "id": "androidx.compose.ui:ui-tooling-data-android", "name": "ui-tooling-data-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -709,7 +709,7 @@ "id": "androidx.compose.ui:ui-tooling-preview", "name": "ui-tooling-preview", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -722,7 +722,7 @@ "id": "androidx.compose.ui:ui-tooling-preview-android", "name": "ui-tooling-preview-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -735,7 +735,7 @@ "id": "androidx.compose.ui:ui-unit", "name": "ui-unit", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -748,7 +748,7 @@ "id": "androidx.compose.ui:ui-unit-android", "name": "ui-unit-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -761,7 +761,7 @@ "id": "androidx.compose.ui:ui-util", "name": "ui-util", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -774,7 +774,7 @@ "id": "androidx.compose.ui:ui-util-android", "name": "ui-util-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -800,7 +800,7 @@ "id": "androidx.concurrent:concurrent-futures", "name": "concurrent-futures", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -813,7 +813,7 @@ "id": "androidx.core:core", "name": "core", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -826,7 +826,7 @@ "id": "androidx.core:core-ktx", "name": "core-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -839,7 +839,7 @@ "id": "androidx.core:core-viewtree", "name": "core-viewtree", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -852,7 +852,7 @@ "id": "androidx.credentials:credentials", "name": "credentials", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -865,7 +865,7 @@ "id": "androidx.credentials:credentials-play-services-auth", "name": "credentials-play-services-auth", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -878,7 +878,7 @@ "id": "androidx.cursoradapter:cursoradapter", "name": "cursoradapter", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -891,7 +891,7 @@ "id": "androidx.customview:customview", "name": "customview", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -904,7 +904,7 @@ "id": "androidx.customview:customview-poolingcontainer", "name": "customview-poolingcontainer", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -917,7 +917,7 @@ "id": "androidx.drawerlayout:drawerlayout", "name": "drawerlayout", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -930,7 +930,7 @@ "id": "androidx.emoji2:emoji2", "name": "emoji2", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -943,7 +943,7 @@ "id": "androidx.emoji2:emoji2-views-helper", "name": "emoji2-views-helper", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -956,7 +956,7 @@ "id": "androidx.exifinterface:exifinterface", "name": "exifinterface", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -969,7 +969,7 @@ "id": "androidx.fragment:fragment", "name": "fragment", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -982,7 +982,7 @@ "id": "androidx.graphics:graphics-path", "name": "graphics-path", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -995,7 +995,7 @@ "id": "androidx.interpolator:interpolator", "name": "interpolator", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1008,7 +1008,7 @@ "id": "androidx.lifecycle:lifecycle-common", "name": "lifecycle-common", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1021,7 +1021,7 @@ "id": "androidx.lifecycle:lifecycle-common-java8", "name": "lifecycle-common-java8", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1034,7 +1034,7 @@ "id": "androidx.lifecycle:lifecycle-common-jvm", "name": "lifecycle-common-jvm", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1047,7 +1047,7 @@ "id": "androidx.lifecycle:lifecycle-livedata-core", "name": "lifecycle-livedata-core", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1060,7 +1060,7 @@ "id": "androidx.lifecycle:lifecycle-process", "name": "lifecycle-process", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1073,7 +1073,7 @@ "id": "androidx.lifecycle:lifecycle-runtime", "name": "lifecycle-runtime", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1086,7 +1086,7 @@ "id": "androidx.lifecycle:lifecycle-runtime-android", "name": "lifecycle-runtime-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1099,7 +1099,7 @@ "id": "androidx.lifecycle:lifecycle-runtime-compose", "name": "lifecycle-runtime-compose", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1112,7 +1112,7 @@ "id": "androidx.lifecycle:lifecycle-runtime-compose-android", "name": "lifecycle-runtime-compose-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1125,7 +1125,7 @@ "id": "androidx.lifecycle:lifecycle-runtime-ktx", "name": "lifecycle-runtime-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1138,7 +1138,7 @@ "id": "androidx.lifecycle:lifecycle-runtime-ktx-android", "name": "lifecycle-runtime-ktx-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1151,7 +1151,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel", "name": "lifecycle-viewmodel", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1164,7 +1164,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-android", "name": "lifecycle-viewmodel-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1177,7 +1177,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-compose", "name": "lifecycle-viewmodel-compose", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1190,7 +1190,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-compose-android", "name": "lifecycle-viewmodel-compose-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1203,7 +1203,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-ktx", "name": "lifecycle-viewmodel-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1216,7 +1216,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-savedstate", "name": "lifecycle-viewmodel-savedstate", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1229,7 +1229,7 @@ "id": "androidx.lifecycle:lifecycle-viewmodel-savedstate-android", "name": "lifecycle-viewmodel-savedstate-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1242,7 +1242,7 @@ "id": "androidx.loader:loader", "name": "loader", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1255,7 +1255,7 @@ "id": "androidx.navigationevent:navigationevent", "name": "navigationevent", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1268,7 +1268,7 @@ "id": "androidx.navigationevent:navigationevent-android", "name": "navigationevent-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1281,7 +1281,7 @@ "id": "androidx.navigationevent:navigationevent-compose", "name": "navigationevent-compose", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1294,7 +1294,7 @@ "id": "androidx.navigationevent:navigationevent-compose-android", "name": "navigationevent-compose-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1307,7 +1307,7 @@ "id": "androidx.profileinstaller:profileinstaller", "name": "profileinstaller", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1320,7 +1320,7 @@ "id": "androidx.resourceinspection:resourceinspection-annotation", "name": "resourceinspection-annotation", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1333,7 +1333,7 @@ "id": "androidx.savedstate:savedstate", "name": "savedstate", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1346,7 +1346,7 @@ "id": "androidx.savedstate:savedstate-android", "name": "savedstate-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1359,7 +1359,7 @@ "id": "androidx.savedstate:savedstate-compose", "name": "savedstate-compose", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1372,7 +1372,7 @@ "id": "androidx.savedstate:savedstate-compose-android", "name": "savedstate-compose-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1385,7 +1385,7 @@ "id": "androidx.savedstate:savedstate-ktx", "name": "savedstate-ktx", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1398,7 +1398,7 @@ "id": "androidx.startup:startup-runtime", "name": "startup-runtime", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1411,7 +1411,7 @@ "id": "androidx.test.ext:junit", "name": "junit", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Test-only dependency; not shipped in the app.", "distribution": "test", "license": "Apache-2.0", @@ -1424,7 +1424,7 @@ "id": "androidx.tracing:tracing", "name": "tracing", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1437,7 +1437,7 @@ "id": "androidx.tracing:tracing-android", "name": "tracing-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1450,7 +1450,7 @@ "id": "androidx.vectordrawable:vectordrawable", "name": "vectordrawable", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1463,7 +1463,7 @@ "id": "androidx.vectordrawable:vectordrawable-animated", "name": "vectordrawable-animated", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1476,7 +1476,7 @@ "id": "androidx.versionedparcelable:versionedparcelable", "name": "versionedparcelable", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1489,7 +1489,7 @@ "id": "androidx.viewpager:viewpager", "name": "viewpager", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1502,7 +1502,7 @@ "id": "androidx.window:window", "name": "window", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1515,7 +1515,7 @@ "id": "androidx.window:window-core", "name": "window-core", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1528,7 +1528,7 @@ "id": "androidx.window:window-core-android", "name": "window-core-android", "author": "The Android Open Source Project", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1567,7 +1567,7 @@ "id": "com.caverock:androidsvg-aar", "name": "androidsvg-aar", "author": "com.caverock", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1580,7 +1580,7 @@ "id": "com.charleskorn.kaml:kaml", "name": "kaml", "author": "com.charleskorn.kaml", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1593,7 +1593,7 @@ "id": "com.charleskorn.kaml:kaml-jvm", "name": "kaml-jvm", "author": "com.charleskorn.kaml", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1606,7 +1606,7 @@ "id": "com.github.codemonstur:embedded-redis", "name": "embedded-redis", "author": "Jurgen Voorneveld", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Test-only dependency; not shipped in the app.", "distribution": "test", "license": "Apache-2.0", @@ -1619,7 +1619,7 @@ "id": "com.google.accompanist:accompanist-drawablepainter", "name": "accompanist-drawablepainter", "author": "Google LLC", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1762,7 +1762,7 @@ "id": "com.google.guava:listenablefuture", "name": "listenablefuture", "author": "Google LLC", - "url": null, + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1814,7 +1814,7 @@ "id": "com.squareup.okhttp3:okhttp", "name": "okhttp", "author": "Square, Inc.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1827,7 +1827,7 @@ "id": "com.squareup.okio:okio", "name": "okio", "author": "Square, Inc.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -1840,7 +1840,7 @@ "id": "com.squareup.okio:okio-fakefilesystem", "name": "okio-fakefilesystem", "author": "Square, Inc.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Build-time or catalog-only dependency; not shipped in the app.", "distribution": "build", "license": "Apache-2.0", @@ -1853,7 +1853,7 @@ "id": "com.squareup.okio:okio-jvm", "name": "okio-jvm", "author": "Square, Inc.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -2893,7 +2893,7 @@ "id": "it.krzeminski:snakeyaml-engine-kmp", "name": "snakeyaml-engine-kmp", "author": "it.krzeminski", - "url": "https://opensource.org/licenses/Apache-2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -2906,7 +2906,7 @@ "id": "it.krzeminski:snakeyaml-engine-kmp-jvm", "name": "snakeyaml-engine-kmp-jvm", "author": "it.krzeminski", - "url": "https://opensource.org/licenses/Apache-2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -3660,7 +3660,7 @@ "id": "org.jetbrains.kotlin:kotlin-stdlib-common", "name": "kotlin-stdlib-common", "author": "JetBrains s.r.o.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -3673,7 +3673,7 @@ "id": "org.jetbrains.kotlin:kotlin-stdlib-jdk7", "name": "kotlin-stdlib-jdk7", "author": "JetBrains s.r.o.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -3686,7 +3686,7 @@ "id": "org.jetbrains.kotlin:kotlin-stdlib-jdk8", "name": "kotlin-stdlib-jdk8", "author": "JetBrains s.r.o.", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -3972,7 +3972,7 @@ "id": "org.jspecify:jspecify", "name": "jspecify", "author": "JSpecify", - "url": "http://www.apache.org/licenses/LICENSE-2.0.txt", + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Transitive Android runtime dependency.", "distribution": "app", "license": "Apache-2.0", @@ -4050,7 +4050,7 @@ "id": "redis.clients:jedis", "name": "jedis", "author": "Redis Inc.", - "url": "https://github.com/redis/jedis/blob/master/LICENSE", + "url": "https://opensource.org/license/mit", "usage": "Server-side dependency; not shipped in the app.", "distribution": "server", "license": "MIT", @@ -4063,7 +4063,7 @@ "id": "software.amazon.awssdk:s3", "name": "s3", "author": "Amazon.com, Inc.", - "url": null, + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Server-side dependency; not shipped in the app.", "distribution": "server", "license": "Apache-2.0", @@ -4076,7 +4076,7 @@ "id": "software.amazon.awssdk:url-connection-client", "name": "url-connection-client", "author": "Amazon.com, Inc.", - "url": null, + "url": "https://www.apache.org/licenses/LICENSE-2.0.txt", "usage": "Server-side dependency; not shipped in the app.", "distribution": "server", "license": "Apache-2.0", diff --git a/shared/src/commonMain/composeResources/values-de/strings.xml b/shared/src/commonMain/composeResources/values-de/strings.xml index aec9bcc..358fcb5 100644 --- a/shared/src/commonMain/composeResources/values-de/strings.xml +++ b/shared/src/commonMain/composeResources/values-de/strings.xml @@ -10,6 +10,7 @@ Prüfe deine Verbindung und versuche es erneut. Offline. Prüfe deine Verbindung und versuche es erneut. Der Server ist nicht erreichbar. Versuche es gleich erneut. + Datum und Uhrzeit des Handys scheinen falsch zu sein, deshalb schlagen sichere Verbindungen fehl. Schalte automatisches Datum und Uhrzeit ein und versuche es erneut. Offline Du kannst ohne Verbindung weiterüben. Lade das Modell einmal herunter (etwa %1$s). Modell herunterladen diff --git a/shared/src/commonMain/composeResources/values-es/strings.xml b/shared/src/commonMain/composeResources/values-es/strings.xml index 0583f38..4967c2d 100644 --- a/shared/src/commonMain/composeResources/values-es/strings.xml +++ b/shared/src/commonMain/composeResources/values-es/strings.xml @@ -10,6 +10,7 @@ Mira tu conexión e inténtalo de nuevo. Sin conexión. Comprueba tu red e inténtalo de nuevo. No se pudo contactar con el servidor. Inténtalo en un momento. + La fecha y la hora del móvil parecen incorrectas, así que las conexiones seguras fallan. Activa la fecha y hora automáticas y vuelve a intentarlo. Sin conexión Puedes seguir practicando sin conexión. Descarga el modelo una vez (unos %1$s). Descargar modelo diff --git a/shared/src/commonMain/composeResources/values-fr/strings.xml b/shared/src/commonMain/composeResources/values-fr/strings.xml index dcfeeed..f1ed622 100644 --- a/shared/src/commonMain/composeResources/values-fr/strings.xml +++ b/shared/src/commonMain/composeResources/values-fr/strings.xml @@ -10,6 +10,7 @@ Vérifie ta connexion et réessaie. Hors ligne. Vérifie ton réseau et réessaie. Impossible de joindre le serveur. Réessaie dans un instant. + La date et l'heure du téléphone semblent incorrectes, donc les connexions sécurisées échouent. Active la date et l'heure automatiques, puis réessaie. Hors ligne Tu peux continuer à t'entraîner sans connexion. Télécharge le modèle une fois (environ %1$s). Télécharger le modèle diff --git a/shared/src/commonMain/composeResources/values/strings.xml b/shared/src/commonMain/composeResources/values/strings.xml index 9115490..b97bcaa 100644 --- a/shared/src/commonMain/composeResources/values/strings.xml +++ b/shared/src/commonMain/composeResources/values/strings.xml @@ -18,6 +18,7 @@ Check your connection and try again. No connection. Check your network and try again. Couldn't reach the server. Try again in a moment. + Your phone's date and time look wrong, so secure connections fail. Turn on automatic date and time, then try again. No connection You can keep practicing without a connection. Download the model once (about %1$s). Download model diff --git a/shared/src/commonMain/kotlin/com/glosso/app/CourseSwitcher.kt b/shared/src/commonMain/kotlin/com/glosso/app/CourseSwitcher.kt index b035de1..53a6718 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/CourseSwitcher.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/CourseSwitcher.kt @@ -44,8 +44,9 @@ import org.jetbrains.compose.resources.stringResource internal fun switchCourse(pack: LanguagePack) { if (pack.code == LanguagePreferences.code.value) return UsageEvents.settingChanged("target_language", pack.code) - LanguagePreferences.set(pack.code) + // Voice first: setting the language wakes the loaders, which read the accent. VoicePreferences.onLanguageChanged(pack) + LanguagePreferences.set(pack.code) } /** diff --git a/shared/src/commonMain/kotlin/com/glosso/app/DownloadUi.kt b/shared/src/commonMain/kotlin/com/glosso/app/DownloadUi.kt index 28c7705..0879e1f 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/DownloadUi.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/DownloadUi.kt @@ -69,6 +69,23 @@ internal fun downloadStatusText(item: DownloadItemState): String = when (item.st } } +/** + * One line for a download that is waiting, for the offline strip: there it can + * only be waiting for a connection, so a progress bar would say nothing. + */ +@Composable +internal fun PendingDownloadLine(item: DownloadItemState, modifier: Modifier = Modifier) { + Row(modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { + Text( + "${item.title} · ${downloadStatusText(item)}", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.weight(1f), + ) + DownloadControls(item) + } +} + /** A compact block for one active download, for the offline drawer. */ @Composable internal fun ActiveDownloadRow(item: DownloadItemState, modifier: Modifier = Modifier) { diff --git a/shared/src/commonMain/kotlin/com/glosso/app/GlossoApp.kt b/shared/src/commonMain/kotlin/com/glosso/app/GlossoApp.kt index 6473114..6897891 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/GlossoApp.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/GlossoApp.kt @@ -1,5 +1,7 @@ package com.glosso.app +import com.glosso.app.download.DownloadIds +import com.glosso.app.download.LocalDownloader import com.glosso.app.platform.currentPlatformContext import com.glosso.app.platform.rememberConnectivity import com.glosso.app.platform.PlatformBackHandler @@ -248,6 +250,10 @@ fun GlossoApp() { val scorer by scoringVm.state.collectAsState() val offlineHintDismissed by OfflineModelHint.dismissed.collectAsState() val requestNotifications = rememberNotificationPermissionRequest() + val downloads by LocalDownloader.current.state.collectAsState() + // Started from the offline strip, the download waits for a connection; the + // strip keeps showing it so the tap visibly did something. + val modelDownload = downloads.item(DownloadIds.MODEL)?.takeIf { it.isActive } // The offline strip's offer is a one-time tip, not a loop: it only appears // while offline without the model, and never again once hidden or started. @@ -359,7 +365,8 @@ fun GlossoApp() { // A wide window (a tablet, a desktop browser) gets the tabs as a side rail // and the screens at a phone's reading width, centred. - BoxWithConstraints(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) { + // Not composed behind the welcome: it would redraw and reload on every language tap. + if (onboardingDone) BoxWithConstraints(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) { val wide = maxWidth >= Sizes.wideLayout val bottomBar = showBar && !wide Row(Modifier.fillMaxSize()) { @@ -464,6 +471,11 @@ fun GlossoApp() { }, onHide = { OfflineModelHint.dismiss(context) }, ) + } else if (modelDownload != null) { + PendingDownloadLine( + modelDownload, + Modifier.padding(start = Space.gutter, end = Space.x4, bottom = Space.x4), + ) } } if (bottomBar) { @@ -477,12 +489,11 @@ fun GlossoApp() { AchievementOverlay(modifier = Modifier.align(Alignment.TopCenter)) } - // First run only: the short welcome, over the course, until it is dismissed. - // The guard keeps a tap on its empty areas from reaching the app behind. + // First run only: the short welcome, until it is dismissed. if (!onboardingDone) { TrackScreen("onboarding") Box( - Modifier.fillMaxSize().consumePointerEvents().background(MaterialTheme.colorScheme.background), + Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background), contentAlignment = Alignment.TopCenter, ) { Box(Modifier.widthIn(max = Sizes.contentMaxWidth)) { diff --git a/shared/src/commonMain/kotlin/com/glosso/app/LessonViewModel.kt b/shared/src/commonMain/kotlin/com/glosso/app/LessonViewModel.kt index 7b66621..65cbad8 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/LessonViewModel.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/LessonViewModel.kt @@ -30,6 +30,8 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.Job +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.launch import kotlinx.coroutines.withTimeoutOrNull import org.jetbrains.compose.resources.getString @@ -181,6 +183,9 @@ private const val REVIEW_WORDING_TIMEOUT_MS = 2_000L class LessonViewModel(private val services: AppServices) : ViewModel() { + private var refreshJob: Job? = null + private var lessonsJob: Job? = null + private val api = appApi private val profiles = ProfileStore.get(services.context) private val platform = platformInfo(services.context) @@ -279,9 +284,13 @@ class LessonViewModel(private val services: AppServices) : ViewModel() { * up without reinstalling. Falls back to downloaded packs when offline. */ fun refresh() { - viewModelScope.launch { + // Latest wins: a reload for the new language must not be overwritten by a + // slower one still running for the old language. + refreshJob?.cancel() + refreshJob = viewModelScope.launch { _state.value = _state.value.copy(loading = true, error = null) val manifest = runCatching { api.manifest() }.getOrNull() + ensureActive() if (manifest != null) { _state.value = _state.value.copy( levels = orderedLevels(manifest.levels), @@ -293,6 +302,7 @@ class LessonViewModel(private val services: AppServices) : ViewModel() { // no manifest at all): derive the levels from the whole lesson bank. if (_state.value.levels.isEmpty()) { val all = runCatching { api.lessons(limit = 200) }.getOrNull() + ensureActive() val derived = if (all != null) { orderedLevels(all.map { it.level }) } else { @@ -309,11 +319,12 @@ class LessonViewModel(private val services: AppServices) : ViewModel() { } fun loadLessons() { - viewModelScope.launch { + lessonsJob?.cancel() + lessonsJob = viewModelScope.launch { _state.value = _state.value.copy(loading = true, error = null) val level = _state.value.level val offlineIds = OfflineStore.state.value.downloadedIds - runCatching { api.lessons(level = level.takeIf { it != "ALL" }) } + runCatching { api.lessons(level = level.takeIf { it != "ALL" }) }.also { ensureActive() } .onSuccess { list -> _state.value = _state.value.copy( loading = false, diff --git a/shared/src/commonMain/kotlin/com/glosso/app/LessonsScreen.kt b/shared/src/commonMain/kotlin/com/glosso/app/LessonsScreen.kt index d32923d..dce85cc 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/LessonsScreen.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/LessonsScreen.kt @@ -174,6 +174,8 @@ fun LessonsScreen( Row(verticalAlignment = Alignment.CenterVertically) { StreakChip(days = progress.shownDailyStreak()) Spacer(Modifier.width(Space.x12)) + CourseSwitcher() + Spacer(Modifier.width(Space.x12)) LevelButton( level = state.level, pickable = state.levels.size > 1, diff --git a/shared/src/commonMain/kotlin/com/glosso/app/NetworkError.kt b/shared/src/commonMain/kotlin/com/glosso/app/NetworkError.kt index 1fec329..085e1a6 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/NetworkError.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/NetworkError.kt @@ -6,9 +6,14 @@ import org.jetbrains.compose.resources.getString /** * The honest one-liner for a failed fetch: offline when there is no connection, - * a server problem otherwise. Keeps "no connection" copy from claiming a server + * the device clock when it is wrong (TLS rejects every certificate then), a + * server problem otherwise. Keeps "no connection" copy from claiming a server * error was the learner's network. */ suspend fun networkOrServerError(connectivity: Connectivity): String = getString( - if (connectivity.isOnline()) Res.string.error_server else Res.string.error_offline, + when { + !connectivity.isOnline() -> Res.string.error_offline + TrustedClock.deviceClockLooksWrong() -> Res.string.error_clock + else -> Res.string.error_server + }, ) diff --git a/shared/src/commonMain/kotlin/com/glosso/app/OnboardingScreen.kt b/shared/src/commonMain/kotlin/com/glosso/app/OnboardingScreen.kt index e4152e3..1a84f0a 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/OnboardingScreen.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/OnboardingScreen.kt @@ -56,6 +56,8 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.draw.clip import androidx.compose.ui.geometry.CornerRadius import androidx.compose.ui.geometry.Offset @@ -99,7 +101,7 @@ fun OnboardingScreen(onFinish: () -> Unit) { val requestNotifications = rememberNotificationPermissionRequest() var page by remember { mutableIntStateOf(0) } - var targetLanguage by remember { mutableStateOf(LanguagePreferences.current.code) } + val targetLanguage by LanguagePreferences.code.collectAsState() // Usage statistics: once per onboarding, and whether it ended by the start // button after the seed or by one of the skips. @@ -216,10 +218,8 @@ fun OnboardingScreen(onFinish: () -> Unit) { 0 -> PromisePage( targetLanguage = targetLanguage, onTargetLanguage = { code -> - LanguagePreferences.set(code) - OfferedLanguages.orNull(code)?.let { VoicePreferences.onLanguageChanged(it) } + OfferedLanguages.orNull(code)?.let(::switchCourse) ProfileStore.get(context).setLanguage(code) - targetLanguage = code }, ) @@ -258,11 +258,15 @@ private fun PromisePage( onTargetLanguage: (String) -> Unit, ) { val scroll = rememberScrollState() + // Never shrinks: a course without accents would otherwise pull the list out from under the finger. + var tallest by remember { mutableIntStateOf(0) } Column( modifier = Modifier .fillMaxSize() .scrollEdgeFade(scroll) .verticalScroll(scroll) + .onSizeChanged { tallest = maxOf(tallest, it.height) } + .heightIn(min = with(LocalDensity.current) { tallest.toDp() }) .padding(horizontal = Space.gutter) .padding(top = Space.x24), ) { diff --git a/shared/src/commonMain/kotlin/com/glosso/app/OnboardingViewModel.kt b/shared/src/commonMain/kotlin/com/glosso/app/OnboardingViewModel.kt index d033940..2acc6ab 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/OnboardingViewModel.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/OnboardingViewModel.kt @@ -5,9 +5,10 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.glosso.engine.model.DrillModel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.launch /** How many reviewed phrases the seed step asks the learner to say. */ @@ -76,34 +77,33 @@ class OnboardingViewModel(private val services: AppServices) : ViewModel() { ) _seed.value = _seed.value.copy(previousScore = previous) } - load() - // The first page lets the learner pick the accent, and the phrases are - // worded per accent: fetch them again in the one just chosen. + // The first page picks the course and the accent, and the phrases (and + // their clips) belong to both: fetch again on any change. Latest wins, so + // the brief accent-before-language step never leaves the old course's + // phrases on screen. viewModelScope.launch { - VoicePreferences.accentFlow.drop(1).collect { load() } + contentReloadSignal(LanguagePreferences.code, UiLanguage.current).collectLatest { fetch() } } } fun load() { - viewModelScope.launch { - _seed.value = _seed.value.copy(loading = true, error = null) - // The bank is paged in row order, so the first few drills repeat the - // same sounds. Fetch a wide page and pick one phrase per trained - // sound, so the profile starts with breadth instead of two sounds. - runCatching { api.drills(limit = OnboardingSeed.POOL) } - .onSuccess { pool -> - _seed.value = SeedState( - loading = false, - drills = OnboardingSeed.select(pool, ONBOARDING_SEED_PHRASES), - ) - } - .onFailure { - _seed.value = SeedState( - loading = false, - error = networkOrServerError(services.connectivity), - ) - } + viewModelScope.launch { fetch() } + } + + private suspend fun fetch() { + _seed.value = _seed.value.copy(loading = true, error = null) + // The bank is paged in row order, so the first few drills repeat the + // same sounds. Fetch a wide page and pick one phrase per trained + // sound, so the profile starts with breadth instead of two sounds. + val pool = try { + api.drills(limit = OnboardingSeed.POOL) + } catch (e: CancellationException) { + throw e // a newer course or accent took over + } catch (_: Exception) { + _seed.value = SeedState(loading = false, error = networkOrServerError(services.connectivity)) + return } + _seed.value = SeedState(loading = false, drills = OnboardingSeed.select(pool, ONBOARDING_SEED_PHRASES)) } fun play(slow: Boolean = false) { diff --git a/shared/src/commonMain/kotlin/com/glosso/app/PracticeEngine.kt b/shared/src/commonMain/kotlin/com/glosso/app/PracticeEngine.kt index 378c4e2..fb24349 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/PracticeEngine.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/PracticeEngine.kt @@ -25,6 +25,8 @@ import kotlin.concurrent.Volatile import kotlin.io.encoding.Base64 import kotlin.time.TimeSource import kotlinx.io.IOException +import io.ktor.client.network.sockets.SocketTimeoutException +import io.ktor.client.plugins.HttpRequestTimeoutException import org.jetbrains.compose.resources.getString /** Everything about one spoken attempt: the recorder, the cloud score and the @@ -311,7 +313,7 @@ class PracticeEngine( if (e is CancellationException) throw e // The score is a cloud call. A dead connection reads as an // IOException: say so plainly instead of leaking a stack trace. - val offline = e is IOException + val offline = e.isOffline() // Offline with no on-device pack: the take is not scored and // cannot be, but the learner can install the pack and try // again, so the UI is told to offer it. @@ -490,7 +492,7 @@ class PracticeEngine( } .onFailure { e -> if (e is CancellationException) throw e - val offline = e is IOException + val offline = e.isOffline() val needsModel = offline && onDevice.supported && onDeviceLanguage() && !onDevice.available() _state.value = _state.value.copy( scoring = false, @@ -530,3 +532,11 @@ private const val MAX_LATENCY_MS = 120_000L */ fun referenceAudioPath(audio: Map): String? = audio.clipFor(VoicePreferences.accent) + +/** + * A connection that could not be made or broke. A timeout is an IOException in + * Ktor too, but it means a slow server on a working connection, so it is not + * reported (or shown) as offline. + */ +internal fun Throwable.isOffline(): Boolean = + this is IOException && this !is HttpRequestTimeoutException && this !is SocketTimeoutException diff --git a/shared/src/commonMain/kotlin/com/glosso/app/SettingsScreen.kt b/shared/src/commonMain/kotlin/com/glosso/app/SettingsScreen.kt index f76e370..d88c53b 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/SettingsScreen.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/SettingsScreen.kt @@ -68,7 +68,7 @@ import org.jetbrains.compose.resources.stringResource @Composable fun SettingsScreen(onBack: () -> Unit, vm: ScoringViewModel = scoringViewModel()) { - var language by remember { mutableStateOf(LanguagePreferences.current.code) } + val language by LanguagePreferences.code.collectAsState() val pack = LanguagePacks.byCode(language) var accent by remember(language) { mutableStateOf(VoicePreferences.accent) } val scorer by vm.state.collectAsState() @@ -151,7 +151,6 @@ fun SettingsScreen(onBack: () -> Unit, vm: ScoringViewModel = scoringViewModel() onSelect = { code -> OfferedLanguages.orNull(code)?.takeIf { it.code != language }?.let { newPack -> switchCourse(newPack) - language = newPack.code accent = VoicePreferences.accent } }, diff --git a/shared/src/commonMain/kotlin/com/glosso/app/TrustedClock.kt b/shared/src/commonMain/kotlin/com/glosso/app/TrustedClock.kt new file mode 100644 index 0000000..3069d22 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/glosso/app/TrustedClock.kt @@ -0,0 +1,118 @@ +package com.glosso.app + +import com.glosso.app.platform.KeyValueStore +import com.glosso.app.platform.PlatformContext +import com.glosso.app.platform.currentTimeMillis +import com.glosso.app.platform.keyValueStore +import com.glosso.app.platform.monotonicMillis +import kotlin.concurrent.Volatile + +/** + * The time the app counts days by. The device clock can be set to any date, which + * let a learner back-date practice, keep parallel streaks or read "26746 days + * since your last practice". The server's `Date` header anchors the time, and the + * monotonic clock (untouched by clock changes) carries it forward while offline. + * With no anchor yet in this run, the device clock is used, but never earlier than + * the latest trusted time seen, and not at all once the network has shown that + * the clock is wrong. + */ +object TrustedClock { + + private const val FILE = "glosso_trusted_clock" + private const val KEY_FLOOR = "floor_ms" + + /** A device clock this far from trusted time is wrong, not a time zone or drift. */ + const val WRONG_CLOCK_MS: Long = 24L * 60 * 60 * 1000 + + private class Anchor(val serverMillis: Long, val monotonic: Long) + + @Volatile + private var anchor: Anchor? = null + + @Volatile + private var floorMillis: Long = 0L + + /** A TLS failure on certificate dates: proof the device clock is off, with no server time to use. */ + @Volatile + private var certificateDateFailure = false + + private var store: KeyValueStore? = null + + fun init(context: PlatformContext) { + if (store != null) return + val loaded = keyValueStore(context, FILE) + store = loaded + floorMillis = maxOf(floorMillis, loaded.getString(KEY_FLOOR)?.toLongOrNull() ?: 0L) + } + + /** A server answered with its time: anchor to it, and raise the floor. */ + fun onServerTime(serverMillis: Long) { + anchor = Anchor(serverMillis, monotonicMillis()) + certificateDateFailure = false + if (serverMillis > floorMillis) { + floorMillis = serverMillis + store?.edit { putString(KEY_FLOOR, serverMillis.toString()) } + } + } + + /** A request failed; a certificate rejected on its dates means the device clock is wrong. */ + fun onNetworkFailure(error: Throwable) { + if (isCertificateDateFailure(error)) certificateDateFailure = true + } + + // The monotonic clock is read only with an anchor: nothing else needs it. + fun nowMillis(): Long = anchor.let { + trustedNow(it?.serverMillis, it?.monotonic, if (it != null) monotonicMillis() else 0, currentTimeMillis(), floorMillis, certificateDateFailure) + } + + /** True when the device clock is far enough off that network errors are the clock's doing. */ + fun deviceClockLooksWrong(): Boolean = anchor.let { + clockLooksWrong(it?.serverMillis, it?.monotonic, if (it != null) monotonicMillis() else 0, currentTimeMillis(), floorMillis, certificateDateFailure) + } + + /** + * The trusted time: the anchor carried forward by the monotonic clock when there + * is one; otherwise the device clock, but never before [floor], and the floor + * itself when certificates have shown the device clock is wrong. + */ + internal fun trustedNow( + anchorServer: Long?, + anchorMonotonic: Long?, + monotonic: Long, + device: Long, + floor: Long, + certificateDateFailure: Boolean, + ): Long = when { + anchorServer != null && anchorMonotonic != null -> anchorServer + (monotonic - anchorMonotonic).coerceAtLeast(0) + certificateDateFailure && floor > 0 -> floor + else -> maxOf(device, floor) + } + + internal fun clockLooksWrong( + anchorServer: Long?, + anchorMonotonic: Long?, + monotonic: Long, + device: Long, + floor: Long, + certificateDateFailure: Boolean, + ): Boolean { + if (certificateDateFailure) return true + if (anchorServer != null && anchorMonotonic != null) { + val trusted = trustedNow(anchorServer, anchorMonotonic, monotonic, device, floor, false) + return kotlin.math.abs(device - trusted) > WRONG_CLOCK_MS + } + return floor > 0 && device < floor - WRONG_CLOCK_MS + } + + /** + * The platform TLS errors for a certificate outside its validity dates: the JVM's + * CertificateExpired/NotYetValid exceptions, and URLSession's codes -1201 + * (bad date) and -1204 (not yet valid). + */ + internal fun isCertificateDateFailure(error: Throwable): Boolean = + generateSequence(error) { it.cause }.take(8).any { cause -> + val text = "${cause::class.simpleName} ${cause.message}" + listOf("CertificateExpired", "NotYetValid", "timestamp check failed", "BadDate", "-1201", "-1204") + .any { it in text } + } +} diff --git a/shared/src/commonMain/kotlin/com/glosso/app/api/GlossoApi.kt b/shared/src/commonMain/kotlin/com/glosso/app/api/GlossoApi.kt index 5cb01fa..49b9649 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/api/GlossoApi.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/api/GlossoApi.kt @@ -1,6 +1,7 @@ package com.glosso.app.api import com.glosso.app.CrashTrace +import com.glosso.app.TrustedClock import com.glosso.engine.model.ArticleModel import com.glosso.engine.model.ContentManifest import com.glosso.engine.model.DialogueModel @@ -17,11 +18,13 @@ import com.glosso.engine.model.localized import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.engine.HttpClientEngine +import io.ktor.client.plugins.HttpSend import io.ktor.client.plugins.HttpTimeout import io.ktor.client.plugins.cache.HttpCache import io.ktor.client.plugins.cache.storage.CacheStorage import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.plugins.defaultRequest +import io.ktor.client.plugins.plugin import io.ktor.client.request.delete import io.ktor.client.request.get import io.ktor.client.request.headers @@ -31,8 +34,12 @@ import io.ktor.client.request.setBody import io.ktor.client.statement.bodyAsText import io.ktor.http.ContentType import io.ktor.http.HttpHeaders +import kotlinx.coroutines.delay +import kotlin.random.Random +import io.ktor.client.plugins.timeout import io.ktor.http.HttpStatusCode import io.ktor.http.contentType +import io.ktor.http.fromHttpToGmtDate import io.ktor.http.isSuccess import io.ktor.serialization.kotlinx.json.json import kotlin.concurrent.Volatile @@ -217,6 +224,22 @@ class GlossoApi( install(HttpCache) { publicStorage(contentCache ?: CacheStorage.Disabled) } + }.also { client -> + // HttpSend sees only real exchanges, never a cache hit, so the Date header + // read here is the server's time now (TrustedClock counts days by it). + client.plugin(HttpSend).intercept { request -> + try { + execute(request).also { call -> + call.response.headers[HttpHeaders.Date]?.let { runCatching { it.fromHttpToGmtDate() }.getOrNull() } + ?.let { TrustedClock.onServerTime(it.timestamp) } + } + } catch (e: CancellationException) { + throw e + } catch (e: Throwable) { + TrustedClock.onNetworkFailure(e) + throw e + } + } } /** @@ -314,13 +337,15 @@ class GlossoApi( }.body>().map { it.forAccent(accent, authoredAccent) } suspend fun score(request: ScoreRequest): PronunciationFeedback { - val response = client.post("$baseUrl/v1/score") { - noCache() - contentType(ContentType.Application.Json) - // Only sent when the build carries a key; an empty key means an - // open server and no header, exactly the old behaviour. - if (apiKey.isNotBlank()) headers { append(API_KEY_HEADER, apiKey) } - setBody(request) + var response = postScore(request) + // Busy: the server queues takes and answers 503 before our timeout runs + // out. Retry after its Retry-After, with jitter so a burst of phones does + // not come back in step. + repeat(SCORE_BUSY_RETRIES) { + if (response.status != HttpStatusCode.ServiceUnavailable) return@repeat + val waitSeconds = response.headers[HttpHeaders.RetryAfter]?.toLongOrNull() ?: 2L + delay(waitSeconds.coerceIn(1L, 5L) * 1_000 + Random.nextLong(0, 1_000)) + response = postScore(request) } // The engine rejects recordings with no usable speech. The API answers // 422 for that - and its tiny body would otherwise deserialize into an @@ -329,9 +354,26 @@ class GlossoApi( if (response.status == HttpStatusCode.UnprocessableEntity) { return PronunciationFeedback(evaluated = false) } + // Any other failure is the server's, never a 0/100 decoded from an error body. + if (!response.status.isSuccess()) error("Scoring failed: HTTP ${response.status.value}") return response.body() } + private suspend fun postScore(request: ScoreRequest) = client.post("$baseUrl/v1/score") { + noCache() + contentType(ContentType.Application.Json) + // Only sent when the build carries a key; an empty key means an + // open server and no header, exactly the old behaviour. + if (apiKey.isNotBlank()) headers { append(API_KEY_HEADER, apiKey) } + // Longer than the server's queue wait plus a slow inference, so a busy + // server answers (503) instead of the phone giving up mid-wait. + timeout { + requestTimeoutMillis = SCORE_TIMEOUT_MS + socketTimeoutMillis = SCORE_TIMEOUT_MS + } + setBody(request) + } + /** A practice plan for this learner: weakest sound first, on-theme and on-target. */ suspend fun drillPlan(request: DrillPlanRequest): DrillPlanModel = client.post("$baseUrl/v1/drills") { @@ -645,6 +687,12 @@ class GlossoApi( /** Shared client credential the scoring oracle expects; see [GlossoApi.apiKey]. */ private const val API_KEY_HEADER = "X-Api-Key" +/** A score waits for the server queue (12 s at most) plus one inference. */ +internal const val SCORE_TIMEOUT_MS = 30_000L + +/** Retries of a take the server was too busy to admit. */ +private const val SCORE_BUSY_RETRIES = 2 + /** The device identity the server keys the user by; see [GlossoApi.deviceIdProvider]. */ private const val DEVICE_ID_HEADER = "X-Device-Id" diff --git a/shared/src/commonMain/kotlin/com/glosso/app/platform/Time.kt b/shared/src/commonMain/kotlin/com/glosso/app/platform/Time.kt index 5d4eebd..f88c5f1 100644 --- a/shared/src/commonMain/kotlin/com/glosso/app/platform/Time.kt +++ b/shared/src/commonMain/kotlin/com/glosso/app/platform/Time.kt @@ -1,9 +1,16 @@ package com.glosso.app.platform +import com.glosso.app.TrustedClock import kotlin.time.Clock /** Milliseconds since the epoch, as `System.currentTimeMillis()`. */ fun currentTimeMillis(): Long = Clock.System.now().toEpochMilliseconds() -/** Today in the device's time zone as days since 1970-01-01, as `LocalDate.now().toEpochDay()`. */ -expect fun todayEpochDay(): Long +/** Milliseconds on a clock that only moves forward and ignores changes to the device clock. */ +expect fun monotonicMillis(): Long + +/** The day of [epochMillis] in the device's time zone, as days since 1970-01-01. */ +expect fun epochDayAt(epochMillis: Long): Long + +/** Today in the device's time zone as days since 1970-01-01, by [TrustedClock], not the device clock. */ +fun todayEpochDay(): Long = epochDayAt(TrustedClock.nowMillis()) diff --git a/shared/src/commonTest/kotlin/com/glosso/app/TrustedClockTest.kt b/shared/src/commonTest/kotlin/com/glosso/app/TrustedClockTest.kt new file mode 100644 index 0000000..b562be8 --- /dev/null +++ b/shared/src/commonTest/kotlin/com/glosso/app/TrustedClockTest.kt @@ -0,0 +1,64 @@ +package com.glosso.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class TrustedClockTest { + + private val day = 24L * 60 * 60 * 1000 + private val realNow = 1_795_000_000_000L // a date in 2026 + private val year2100 = 4_102_444_800_000L + + @Test + fun `an anchored time follows the monotonic clock whatever the device clock says`() { + val now = TrustedClock.trustedNow( + anchorServer = realNow, anchorMonotonic = 1_000, monotonic = 1_000 + day, + device = year2100, floor = realNow, certificateDateFailure = false, + ) + assertEquals(realNow + day, now) + } + + @Test + fun `without an anchor the day never goes back before the last trusted time`() { + val now = TrustedClock.trustedNow( + anchorServer = null, anchorMonotonic = null, monotonic = 5, + device = realNow - 30 * day, floor = realNow, certificateDateFailure = false, + ) + assertEquals(realNow, now) + } + + @Test + fun `without an anchor a sane device clock is used`() { + val now = TrustedClock.trustedNow(null, null, 5, realNow + day, realNow, false) + assertEquals(realNow + day, now) + } + + @Test + fun `a certificate rejected on its dates freezes time at the last trusted moment`() { + assertEquals(realNow, TrustedClock.trustedNow(null, null, 5, year2100, realNow, true)) + // A first run with no trusted time yet can only use the device clock. + assertEquals(year2100, TrustedClock.trustedNow(null, null, 5, year2100, 0, true)) + } + + @Test + fun `the clock looks wrong when it is a day away from the anchor or behind the floor`() { + assertTrue(TrustedClock.clockLooksWrong(realNow, 0, 0, year2100, realNow, false)) + assertFalse(TrustedClock.clockLooksWrong(realNow, 0, 0, realNow + 60_000, realNow, false)) + assertTrue(TrustedClock.clockLooksWrong(null, null, 0, realNow - 2 * day, realNow, false)) + assertFalse(TrustedClock.clockLooksWrong(null, null, 0, realNow + 2 * day, realNow, false)) + assertTrue(TrustedClock.clockLooksWrong(null, null, 0, realNow, realNow, true)) + } + + @Test + fun `certificate date failures are recognised through the cause chain`() { + val jvm = RuntimeException( + "Chain validation failed", + RuntimeException("timestamp check failed", RuntimeException("Certificate expired at Sat Feb 13 2027")), + ) + assertTrue(TrustedClock.isCertificateDateFailure(jvm)) + assertTrue(TrustedClock.isCertificateDateFailure(RuntimeException("NSURLErrorDomain Code=-1204"))) + assertFalse(TrustedClock.isCertificateDateFailure(RuntimeException("Unable to resolve host"))) + } +} diff --git a/shared/src/commonTest/kotlin/com/glosso/app/api/ScoreRetryTest.kt b/shared/src/commonTest/kotlin/com/glosso/app/api/ScoreRetryTest.kt new file mode 100644 index 0000000..bef2889 --- /dev/null +++ b/shared/src/commonTest/kotlin/com/glosso/app/api/ScoreRetryTest.kt @@ -0,0 +1,63 @@ +package com.glosso.app.api + +import io.ktor.client.engine.mock.MockEngine +import io.ktor.client.engine.mock.respond +import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode +import io.ktor.http.headersOf +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlin.test.assertFalse + +class ScoreRetryTest { + + private val json = headersOf(HttpHeaders.ContentType, "application/json") + + private fun api(vararg replies: Pair): Pair Int> { + var calls = 0 + val engine = MockEngine { + val (status, body) = replies[calls++] + respond(body, status, if (status == HttpStatusCode.ServiceUnavailable) headersOf(HttpHeaders.RetryAfter, "1") else json) + } + val scope = object : ContentScope { + override val language = "en" + override val accent = "en-GB" + override val authoredAccent = "en-GB" + override val uiLanguage = "en" + } + val api = GlossoApi({ "http://test" }, engine, null, AssetVersionStore.None, "", { null }, { false }, scope) + return api to { calls } + } + + @Test + fun busyServerIsRetriedOnce() = runTest { + val (api, calls) = api( + HttpStatusCode.ServiceUnavailable to """{"error":"busy"}""", + HttpStatusCode.OK to """{"score":87}""", + ) + assertEquals(87, api.score(ScoreRequest(text = "hi")).score) + assertEquals(2, calls()) + } + + @Test + fun aServerBusyThroughEveryRetryFails() = runTest { + val busy = HttpStatusCode.ServiceUnavailable to """{"error":"busy"}""" + val (api, calls) = api(busy, busy, busy) + assertFailsWith { api.score(ScoreRequest(text = "hi")) } + assertEquals(3, calls()) + } + + @Test + fun serverErrorIsAFailureNotAZeroScore() = runTest { + val (api, _) = api(HttpStatusCode.InternalServerError to """{"error":"boom"}""") + assertFailsWith { api.score(ScoreRequest(text = "hi")) } + } + + @Test + fun unusableSpeechIsNotEvaluated() = runTest { + val (api, _) = api(HttpStatusCode.UnprocessableEntity to "{}") + assertFalse(api.score(ScoreRequest(text = "hi")).evaluated) + } +} diff --git a/shared/src/iosMain/kotlin/com/glosso/app/MainViewController.kt b/shared/src/iosMain/kotlin/com/glosso/app/MainViewController.kt index 97f98a4..0783180 100644 --- a/shared/src/iosMain/kotlin/com/glosso/app/MainViewController.kt +++ b/shared/src/iosMain/kotlin/com/glosso/app/MainViewController.kt @@ -100,6 +100,7 @@ private object IosHost { OfflineStore.downloader = downloader IosOnDeviceScorer.init(downloader) DeviceId.init(context) + TrustedClock.init(context) ApiCache.init(context) OfflineStore.init(context) ProductConfigRepository.init(context) diff --git a/shared/src/iosMain/kotlin/com/glosso/app/platform/Time.ios.kt b/shared/src/iosMain/kotlin/com/glosso/app/platform/Time.ios.kt index 5727668..caf3569 100644 --- a/shared/src/iosMain/kotlin/com/glosso/app/platform/Time.ios.kt +++ b/shared/src/iosMain/kotlin/com/glosso/app/platform/Time.ios.kt @@ -1,12 +1,19 @@ package com.glosso.app.platform +import kotlinx.cinterop.ExperimentalForeignApi import platform.Foundation.NSDate import platform.Foundation.NSTimeZone +import platform.Foundation.dateWithTimeIntervalSince1970 import platform.Foundation.localTimeZone -import platform.Foundation.timeIntervalSince1970 +import platform.posix.CLOCK_MONOTONIC +import platform.posix.clock_gettime_nsec_np -actual fun todayEpochDay(): Long { - val now = NSDate() - val localSeconds = now.timeIntervalSince1970.toLong() + NSTimeZone.localTimeZone.secondsFromGMTForDate(now) +// Darwin's CLOCK_MONOTONIC keeps counting while the device sleeps. +@OptIn(ExperimentalForeignApi::class) +actual fun monotonicMillis(): Long = (clock_gettime_nsec_np(CLOCK_MONOTONIC.toUInt()) / 1_000_000uL).toLong() + +actual fun epochDayAt(epochMillis: Long): Long { + val date = NSDate.dateWithTimeIntervalSince1970(epochMillis / 1000.0) + val localSeconds = epochMillis / 1000 + NSTimeZone.localTimeZone.secondsFromGMTForDate(date) return localSeconds.floorDiv(86_400L) } diff --git a/shared/src/wasmJsMain/kotlin/com/glosso/app/Main.kt b/shared/src/wasmJsMain/kotlin/com/glosso/app/Main.kt index c942e04..d241d6f 100644 --- a/shared/src/wasmJsMain/kotlin/com/glosso/app/Main.kt +++ b/shared/src/wasmJsMain/kotlin/com/glosso/app/Main.kt @@ -149,6 +149,7 @@ private fun wire(): AppServices { Analytics.askConsent = true Analytics.anonymous = true Analytics.init(context) + TrustedClock.init(context) ApiCache.init(context) OfflineStore.init(context) ProductConfigRepository.init(context) diff --git a/shared/src/wasmJsMain/kotlin/com/glosso/app/platform/Time.wasmJs.kt b/shared/src/wasmJsMain/kotlin/com/glosso/app/platform/Time.wasmJs.kt index d166e58..236686e 100644 --- a/shared/src/wasmJsMain/kotlin/com/glosso/app/platform/Time.wasmJs.kt +++ b/shared/src/wasmJsMain/kotlin/com/glosso/app/platform/Time.wasmJs.kt @@ -1,6 +1,10 @@ package com.glosso.app.platform -actual fun todayEpochDay(): Long = localEpochDay().toLong() +actual fun monotonicMillis(): Long = performanceNow().toLong() -private fun localEpochDay(): Double = - js("Math.floor((Date.now() - new Date().getTimezoneOffset() * 60000) / 86400000)") +actual fun epochDayAt(epochMillis: Long): Long = localEpochDay(epochMillis.toDouble()).toLong() + +private fun performanceNow(): Double = js("performance.now()") + +private fun localEpochDay(epochMillis: Double): Double = + js("Math.floor((epochMillis - new Date(epochMillis).getTimezoneOffset() * 60000) / 86400000)") diff --git a/tools/licensing/collect.py b/tools/licensing/collect.py index 4cfb3d1..341c324 100644 --- a/tools/licensing/collect.py +++ b/tools/licensing/collect.py @@ -118,7 +118,15 @@ def privacy_asset(locale): "proprietary": "Proprietary", } +# One canonical URL per licence id: a POM's own URL string only existed when that +# POM happened to be in the local Gradle cache, so the catalogue changed by machine. LICENSE_URLS = { + "Apache-2.0": "https://www.apache.org/licenses/LICENSE-2.0.txt", + "MIT": "https://opensource.org/license/mit", + "BSD-2-Clause": "https://opensource.org/license/bsd-2-clause", + "BSD-3-Clause": "https://opensource.org/license/bsd-3-clause", + "EPL-1.0": "https://www.eclipse.org/legal/epl-v10.html", + "OFL-1.1": "https://openfontlicense.org/open-font-license-official-text/", "Android-SDK": "https://developer.android.com/studio/terms.html", "Play-Core-ToS": "https://developer.android.com/guide/playcore/in-app-review", "CC-BY-2.0-FR": "https://creativecommons.org/licenses/by/2.0/fr/", @@ -586,6 +594,7 @@ def _auto_component(module_id, version=None, scope="app"): author = _group_author(group) if licence: name = LICENSE_NAMES[licence] + url = LICENSE_URLS.get(licence) or url notice = None else: licence, name = raw_name or "unknown", raw_name or "Unknown licence" diff --git a/tools/licensing/collect_test.py b/tools/licensing/collect_test.py index 978007f..f7d2fbb 100644 --- a/tools/licensing/collect_test.py +++ b/tools/licensing/collect_test.py @@ -62,6 +62,16 @@ def test_declared_modules_use_the_catalog_version(self): self.assertEqual(pinned["io.ktor:ktor-server-core"], pinned["io.ktor:ktor-client-mock"]) self.assertRegex(pinned["io.ktor:ktor-server-core"], r"^\d+\.\d+\.\d+$") + def test_known_licences_use_their_canonical_url(self): + # A POM's URL depends on the local Gradle cache; the canonical one does not. + curated = set(collect.CURATED_DEPS) | {c["id"] for c in collect.COMPONENTS} + drift = [ + c["id"] for c in _asset()["components"] + if c.get("license") in collect.LICENSE_URLS and c.get("url") != collect.LICENSE_URLS[c["license"]] + and c["id"] not in curated + ] + self.assertEqual(drift, [], f"entries not on their licence's canonical URL: {drift[:20]}") + def test_asset_is_in_lockstep_with_the_catalogue(self): self.assertEqual( _asset(),