From f2a2acf9966c65da435d4fffcce0936f14d2853e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Thu, 12 Nov 2026 09:58:07 +0000 Subject: [PATCH] Three APKs: the notification listener leaves the standard builds; releases drop x86_64 Google Play Protect blocked installing beta.7, most likely for the notification listener (notification summaries). - A second flavour dimension, `reading`: `standard` declares no listener and no permission of it; `notifications` is the full build plus the listener, with the same application id and key. Variants: fullStandard, fullNotifications, fdroidStandard (no F-Droid build with the listener). The listener class and its manifest entry live in src/notifications only. - Settings in a standard build says where notification summaries went and why. The self-updater installs only its own kind: a notifications build takes latest.json's optional `notifications {url, sha256}` or nothing. - Release builds carry arm64-v8a and armeabi-v7a only; debug keeps x86_64 for the emulator. The engine's unused C and C++ API libraries are left out. - scripts/check-apk.sh checks the built files (listener only where it may be, model stored, no x86 in a release); CI runs it on the three debug APKs and on an unsigned release build, release.yml on what it publishes. - release.yml publishes llembas-android-.apk, -notifications.apk and -fdroid.apk with SHA256SUMS. Co-Authored-By: Claude Fable 5.2 --- .github/workflows/ci.yml | 33 +++++-- .github/workflows/release.yml | 17 ++-- CHANGELOG.md | 9 ++ README.md | 15 +++- app/build.gradle.kts | 42 ++++++++- app/src/main/AndroidManifest.xml | 11 --- .../android/assist/AssistController.kt | 7 +- .../android/notify/NotificationReader.kt | 83 ++--------------- .../android/ui/settings/SettingsScreen.kt | 68 ++++++++------ .../java/eu/llembas/android/update/Updater.kt | 25 +++++- app/src/main/res/values-cs/strings.xml | 2 + app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-hu/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values-pl/strings.xml | 2 + app/src/main/res/values-sk/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/notifications/AndroidManifest.xml | 18 ++++ .../android/notify/NotificationAccess.kt | 88 +++++++++++++++++++ .../android/notify/NotificationAccess.kt | 21 +++++ .../eu/llembas/android/SmallThingsTest.kt | 18 ++++ .../java/eu/llembas/android/shots/Fakes.kt | 5 +- .../eu/llembas/android/shots/ScreenShots.kt | 2 + scripts/check-apk.sh | 45 ++++++++++ scripts/strings.py | 2 + scripts/strings_own.json | 16 ++++ 28 files changed, 403 insertions(+), 140 deletions(-) create mode 100644 app/src/notifications/AndroidManifest.xml create mode 100644 app/src/notifications/java/eu/llembas/android/notify/NotificationAccess.kt create mode 100644 app/src/standard/java/eu/llembas/android/notify/NotificationAccess.kt create mode 100755 scripts/check-apk.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 676520b..ceae0a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,22 +53,41 @@ jobs: - uses: gradle/actions/setup-gradle@v4 - - name: Unit tests and both builds - run: ./gradlew --no-daemon testFullDebugUnitTest assembleFullDebug assembleFdroidDebug + - name: Unit tests and the three builds + run: > + ./gradlew --no-daemon testFullStandardDebugUnitTest + assembleFullStandardDebug assembleFullNotificationsDebug assembleFdroidStandardDebug + + # The files themselves: only the notifications build declares a notification listener, the + # wake-word model is stored uncompressed, the F-Droid build has no engine. + - name: What the APKs declare + run: | + scripts/check-apk.sh app/build/outputs/apk/fullStandard/debug/app-full-standard-debug.apk standard + scripts/check-apk.sh app/build/outputs/apk/fullNotifications/debug/app-full-notifications-debug.apk notifications + scripts/check-apk.sh app/build/outputs/apk/fdroidStandard/debug/app-fdroid-standard-debug.apk fdroid + + # A release as the release workflow builds it, unsigned: shrunk by R8, and without the + # emulator's x86_64 libraries. Found here rather than at a tag. + - name: The release build's shape + run: | + ./gradlew --no-daemon assembleFullStandardRelease + scripts/check-apk.sh "$(ls app/build/outputs/apk/fullStandard/release/*.apk)" standard release - name: Android lint (report only, for now) - run: ./gradlew --no-daemon lintFullDebug + run: ./gradlew --no-daemon lintFullStandardDebug continue-on-error: true # The test build a tester installs (Actions › this run › Artifacts): debug-signed with the - # repository's public test key, so each one installs over the last. `full` is the one to - # use; `fdroid` is the same app without the updater. + # repository's public test key, so each one installs over the last. The plain one is the + # one to use; `-notifications` is the same app with the notification listener (it installs + # over the plain one and back); `-fdroid` is the app without the updater and the wake word. - name: Name the test builds run: | mkdir test-builds short="${GITHUB_SHA::7}" - cp app/build/outputs/apk/full/debug/app-full-debug.apk "test-builds/llembas-android-debug-$GITHUB_RUN_NUMBER-$short.apk" - cp app/build/outputs/apk/fdroid/debug/app-fdroid-debug.apk "test-builds/llembas-android-debug-$GITHUB_RUN_NUMBER-$short-fdroid.apk" + cp app/build/outputs/apk/fullStandard/debug/app-full-standard-debug.apk "test-builds/llembas-android-debug-$GITHUB_RUN_NUMBER-$short.apk" + cp app/build/outputs/apk/fullNotifications/debug/app-full-notifications-debug.apk "test-builds/llembas-android-debug-$GITHUB_RUN_NUMBER-$short-notifications.apk" + cp app/build/outputs/apk/fdroidStandard/debug/app-fdroid-standard-debug.apk "test-builds/llembas-android-debug-$GITHUB_RUN_NUMBER-$short-fdroid.apk" (cd test-builds && sha256sum *.apk > SHA256SUMS) - uses: actions/upload-artifact@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ddd581b..47860af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,8 @@ name: Release -# A signed tag `vX.Y.Z` builds both flavours, signed with the release key from the secrets, -# and publishes them with SHA256SUMS as the GitHub Release. The release notes are the tag's +# A signed tag `vX.Y.Z` builds the three APKs, signed with the release key from the secrets, +# and publishes them with SHA256SUMS as the GitHub Release: the standard one, `-notifications` +# (the same app, id and key, plus the notification listener) and `-fdroid`. The release notes are the tag's # message. The key never touches the repository: it is written to a temporary file here and # deleted with the runner. on: @@ -61,14 +62,20 @@ jobs: [ -n "$KEYSTORE_B64" ] || { echo "no release key in the secrets" >&2; exit 1; } export LEMBAS_KEYSTORE="$RUNNER_TEMP/release.jks" echo "$KEYSTORE_B64" | base64 -d > "$LEMBAS_KEYSTORE" - ./gradlew --no-daemon testFullReleaseUnitTest assembleFullRelease assembleFdroidRelease + ./gradlew --no-daemon testFullStandardReleaseUnitTest assembleFullStandardRelease assembleFullNotificationsRelease assembleFdroidStandardRelease rm -f "$LEMBAS_KEYSTORE" - name: Name the files and sum them run: | mkdir dist - cp app/build/outputs/apk/full/release/app-full-release.apk "dist/llembas-android-$VERSION.apk" - cp app/build/outputs/apk/fdroid/release/app-fdroid-release.apk "dist/llembas-android-$VERSION-fdroid.apk" + cp app/build/outputs/apk/fullStandard/release/app-full-standard-release.apk "dist/llembas-android-$VERSION.apk" + cp app/build/outputs/apk/fullNotifications/release/app-full-notifications-release.apk "dist/llembas-android-$VERSION-notifications.apk" + cp app/build/outputs/apk/fdroidStandard/release/app-fdroid-standard-release.apk "dist/llembas-android-$VERSION-fdroid.apk" + # What is about to be published, checked on the files: the listener only in + # -notifications, the model stored, no x86_64 library. + scripts/check-apk.sh "dist/llembas-android-$VERSION.apk" standard release + scripts/check-apk.sh "dist/llembas-android-$VERSION-notifications.apk" notifications release + scripts/check-apk.sh "dist/llembas-android-$VERSION-fdroid.apk" fdroid release { echo "# llembas-android $VERSION"; (cd dist && sha256sum *.apk); } > SHA256SUMS mv SHA256SUMS dist/ diff --git a/CHANGELOG.md b/CHANGELOG.md index dd3ab5a..4b0fb65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,15 @@ is in alpha and releases come off `main`. - The phrases' spelling in the model's token pieces is generated from the model's own tokenizer (`scripts/gen-wake-phrases.py`) and checked against its token table in CI, instead of written by hand. Elizabeth and Benjamin are left out: the tokenizer can only spell them letter by letter. +- **Notification summaries moved to a build of their own**, `llembas-android--notifications.apk`: + the same app with the same signature, plus the notification listener. Google Play Protect + blocked installing beta.7, most likely because an app from outside the Play Store that can read + notifications is what it looks for; the standard and F-Droid APKs now declare no notification + listener at all, and Settings says where notification summaries went and why. The + notifications build installs over the standard one as an ordinary update, and back; it updates + itself only to its own kind. +- **A smaller download.** Release APKs no longer carry the emulator's x86_64 libraries (about + 36 MB of beta.7's 98 MB) nor two libraries of the wake-word engine the app never calls. - **The wake word says what it is doing**, in its notification and under its switch in Settings: *Starting*, *Listening for "…"*, paused and why (screen off, battery saver, assistant open, no microphone permission, or the microphone gives no sound because another app has it or it is diff --git a/README.md b/README.md index 0b11b24..2d18a02 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,19 @@ the phone before the word. Not in the F-Droid build. ## Build -Builds run on GitHub Actions (`.github/workflows/ci.yml`); locally it is the usual -`./gradlew assembleFullDebug` with JDK 17 and the Android SDK. +Builds run on GitHub Actions (`.github/workflows/ci.yml`); locally it is +`scripts/fetch-wakeword.py` (the wake-word engine and model, hash-pinned, never committed) and +then the usual `./gradlew assembleFullStandardDebug` with JDK 17 and the Android SDK. + +A release is three APKs of one app, signed with one key: + +| File | Build | What it is | +|---|---|---| +| `llembas-android-.apk` | `fullStandard` | The app: updates itself, has the wake word. The one to install. | +| `llembas-android--notifications.apk` | `fullNotifications` | The same, plus a notification listener for *notification summaries*. Separate because Google Play Protect blocks installing an app from outside the Play Store that can read notifications; it installs over the standard one, and back. | +| `llembas-android--fdroid.apk` | `fdroidStandard` | No updater and no wake-word engine: only what F-Droid can build from source. | + +`scripts/check-apk.sh` checks each built file for what it must and must not declare. Three things are generated from the server at one ref; the first two are pinned with a lock file CI checks, and CI checks the strings against the code: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e643db7..c14b369 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -67,28 +67,46 @@ android { isShrinkResources = true proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") signingConfig = signingConfigs.findByName("release") + // The wake-word engine's native code, for phones only: a release carries no x86_64 + // library (36 MB that only an emulator would load). + ndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a") } } debug { applicationIdSuffix = ".debug" // CI's run number, so a tester can tell two test builds apart in Settings › About. versionNameSuffix = "-debug" + (System.getenv("GITHUB_RUN_NUMBER")?.let { ".$it" } ?: "") signingConfig = signingConfigs.getByName("debug") + // A test build also runs on the 64-bit emulator (not 32-bit x86). + ndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86_64") } } } - // `full` updates itself from llembas.eu; `fdroid` has no updater, because F-Droid updates it. - flavorDimensions += "distribution" + // Two questions, three APKs. + // + // `distribution`: `full` updates itself from llembas.eu and has the wake-word engine; `fdroid` + // has neither, because F-Droid updates it and builds every library from source. + // + // `reading`: whether the app declares a notification listener (notification summaries). + // `standard` does not -- no listener, no permission, nothing of it in the manifest -- because + // Google Play Protect blocks installing an app from outside the Play Store that can read + // notifications. `notifications` is the full build plus the listener: the same application + // id and the same key, so it installs over the standard one as an ordinary update. + flavorDimensions += listOf("distribution", "reading") productFlavors { create("full") { dimension = "distribution" buildConfigField("boolean", "SELF_UPDATE", "true") - // The wake-word engine's native code: phones and the 64-bit emulator, not 32-bit x86. - ndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a", "x86_64") } } create("fdroid") { dimension = "distribution" buildConfigField("boolean", "SELF_UPDATE", "false") } + create("standard") { + dimension = "reading" + } + create("notifications") { + dimension = "reading" + } } androidResources { @@ -97,6 +115,14 @@ android { noCompress += "onnx" } + packaging { + jniLibs { + // The engine is called through its JNI library alone, which needs only onnxruntime; + // the C and C++ API libraries its AAR also carries are for other kinds of caller. + excludes += listOf("**/libsherpa-onnx-c-api.so", "**/libsherpa-onnx-cxx-api.so") + } + } + buildFeatures { compose = true buildConfig = true @@ -138,6 +164,14 @@ android { } } +// fullStandard, fullNotifications and fdroidStandard: there is no F-Droid build with the listener. +androidComponents { + beforeVariants { variant -> + val flavors = variant.productFlavors.toMap() + if (flavors["distribution"] == "fdroid" && flavors["reading"] == "notifications") variant.enable = false + } +} + kotlin { jvmToolchain(17) } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 785a146..8427b38 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -184,17 +184,6 @@ android:exported="false" android:foregroundServiceType="microphone" /> - - - - - - - diff --git a/app/src/main/java/eu/llembas/android/assist/AssistController.kt b/app/src/main/java/eu/llembas/android/assist/AssistController.kt index 3f7641e..0bef4d3 100644 --- a/app/src/main/java/eu/llembas/android/assist/AssistController.kt +++ b/app/src/main/java/eu/llembas/android/assist/AssistController.kt @@ -17,6 +17,7 @@ import eu.llembas.android.api.ModelInfo import eu.llembas.android.api.Step import eu.llembas.android.api.StreamClient import eu.llembas.android.lembas +import eu.llembas.android.notify.NotificationAccess import eu.llembas.android.notify.NotificationReader import eu.llembas.android.push.Notifications import eu.llembas.android.ui.explain @@ -152,7 +153,7 @@ class AssistController(private val context: Context, private val scope: Coroutin signedIn = instance != null, instanceName = instance?.name?.ifBlank { instance.base }.orEmpty(), voiceReply = prefs.readAloudSpoken, - canReadNotifications = prefs.notificationSummaries && NotificationReader.granted(context), + canReadNotifications = prefs.notificationSummaries && NotificationAccess.granted(context), last = prefs.lastAssistChat.takeIf { id -> id.isNotBlank() && !prefs.assistantTemporary } ?.let { id -> LastAssist(id, prefs.lastAssistTitle, prefs.lastAssistAt) }, ) @@ -398,10 +399,10 @@ class AssistController(private val context: Context, private val scope: Coroutin if (withScreen) now.screenshot?.let { shot -> add(api.upload("screen.png", "image/png", png(shot), now.chatId).id) } } // The notifications, when asked for by the chip or by name ("my notifications") -- - // read now, only while unlocked (NotificationReader.read), and for this question only. + // read now, only while unlocked (NotificationAccess.read), and for this question only. val phrases = context.getString(R.string.assist_notifications_phrases).split("|") val notices = if (now.canReadNotifications && (notifications || NotificationReader.asksAbout(question, phrases))) { - NotificationReader.asText(NotificationReader.read(context)).ifBlank { NO_NOTIFICATIONS } + NotificationReader.asText(NotificationAccess.read(context)).ifBlank { NO_NOTIFICATIONS } } else { null } diff --git a/app/src/main/java/eu/llembas/android/notify/NotificationReader.kt b/app/src/main/java/eu/llembas/android/notify/NotificationReader.kt index 01eb088..996b757 100644 --- a/app/src/main/java/eu/llembas/android/notify/NotificationReader.kt +++ b/app/src/main/java/eu/llembas/android/notify/NotificationReader.kt @@ -1,85 +1,14 @@ package eu.llembas.android.notify -import android.app.KeyguardManager -import android.app.Notification -import android.content.ComponentName -import android.content.Context -import android.content.Intent -import android.os.Build -import android.provider.Settings -import android.service.notification.NotificationListenerService -import android.service.notification.StatusBarNotification -import androidx.core.app.NotificationManagerCompat - -/** - * Notification summaries on request: the assistant reads the notifications on the phone only when - * the person asks it to ("summarise my notifications", or the sheet's chip), and sends their text - * with that one question. Off by default, twice over: Android's own notification-access switch - * (which only the person can turn on, in the system's settings) and Settings › Assistant's. - * - * The listener keeps nothing: it is how Android lets an app read the notifications that are up - * right now ([activeNotifications]), and nothing is read until a question asks for it. Never over - * the lock screen ([read] returns nothing while the phone is locked). - */ -class LembasNotificationListener : NotificationListenerService() { - override fun onListenerConnected() { - super.onListenerConnected() - current = this - } - - override fun onListenerDisconnected() { - if (current === this) current = null - super.onListenerDisconnected() - } - - companion object { - @Volatile - var current: LembasNotificationListener? = null - private set - } -} - /** One notification, as the question carries it. */ data class Notice(val app: String, val title: String, val text: String, val at: Long) +/** + * Notification summaries, the half every build has: how the notifications are written into a + * question, and when a question asks for them. Reading them is [NotificationAccess]'s, which only + * the `notifications` build can do. + */ object NotificationReader { - /** Whether the person gave LLeMbas notification access in the system's settings. */ - fun granted(context: Context): Boolean = context.packageName in NotificationManagerCompat.getEnabledListenerPackages(context) - - /** The system's page for this app's notification access (the detail page where Android has one). */ - fun settingsIntent(context: Context): Intent = if (Build.VERSION.SDK_INT >= 30) { - Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS) - .putExtra(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, ComponentName(context, LembasNotificationListener::class.java).flattenToString()) - } else { - Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) - }.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - - /** The notifications up now, newest first -- or none, when locked or not allowed. */ - fun read(context: Context): List { - if (context.getSystemService(KeyguardManager::class.java).isKeyguardLocked) return emptyList() - val listener = LembasNotificationListener.current ?: return emptyList() - val shown = runCatching { listener.activeNotifications }.getOrNull().orEmpty() - return shown - .filter { it.packageName != context.packageName && !it.isOngoing && it.notification.flags and Notification.FLAG_GROUP_SUMMARY == 0 } - .sortedByDescending { it.postTime } - .mapNotNull { notice(context, it) } - .take(MAX_NOTICES) - } - - private fun notice(context: Context, sbn: StatusBarNotification): Notice? { - val extras = sbn.notification.extras - val title = extras.getCharSequence(Notification.EXTRA_TITLE)?.toString().orEmpty() - val lines = extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)?.joinToString("\n").orEmpty() - val text = (extras.getCharSequence(Notification.EXTRA_BIG_TEXT) ?: extras.getCharSequence(Notification.EXTRA_TEXT))?.toString() - ?.ifBlank { null } ?: lines - if (title.isBlank() && text.isBlank()) return null - val app = runCatching { - val pm = context.packageManager - pm.getApplicationLabel(pm.getApplicationInfo(sbn.packageName, 0)).toString() - }.getOrDefault(sbn.packageName) - return Notice(app, title, text.take(MAX_TEXT), sbn.postTime) - } - /** The notifications as the question's attachment of text: one block per notification. */ fun asText(notices: List, now: Long = System.currentTimeMillis()): String = notices.joinToString("\n\n") { n -> val minutes = ((now - n.at) / 60_000).coerceAtLeast(0) @@ -96,7 +25,5 @@ object NotificationReader { return phrases.map { it.trim().lowercase() }.any { it.isNotEmpty() && it in q } } - private const val MAX_NOTICES = 40 - private const val MAX_TEXT = 600 private const val MAX_CHARS = 12_000 } diff --git a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt index 17fdfa9..7c53536 100644 --- a/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/eu/llembas/android/ui/settings/SettingsScreen.kt @@ -96,7 +96,7 @@ import eu.llembas.android.assist.PhoneRecognizer import eu.llembas.android.auth.Instance import eu.llembas.android.auth.Prefs import eu.llembas.android.lembas -import eu.llembas.android.notify.NotificationReader +import eu.llembas.android.notify.NotificationAccess import eu.llembas.android.push.Push import eu.llembas.android.ui.theme.LocalPalette import eu.llembas.android.update.AppVersion @@ -179,6 +179,8 @@ data class SettingsState( val wakeTest: WakeTestShown = WakeTestShown(), /** Whether Android's notification access is given to LLeMbas. */ val notificationAccess: Boolean = false, + /** Whether this build can read notifications at all (only the `notifications` build declares the listener). */ + val notificationsBuild: Boolean = false, /** The navigation apps installed: NavApp ids. */ val navApps: List = emptyList(), ) @@ -318,11 +320,11 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) { // On: Android's own switch is the person's to flip, so its page opens if it is off. override fun notificationSummaries(on: Boolean) { scope.launch { store.savePrefs { it.copy(notificationSummaries = on) } } - if (on && !NotificationReader.granted(context)) notificationAccess() + if (on && !NotificationAccess.granted(context)) notificationAccess() } override fun notificationAccess() { - runCatching { context.startActivity(NotificationReader.settingsIntent(context)) } + NotificationAccess.settingsIntent(context)?.let { page -> runCatching { context.startActivity(page) } } } override fun navApp(id: String) { @@ -391,7 +393,8 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) { wakeState = wakeState, wakeTest = WakeTestShown(running = clock < trial.until, done = tested && clock >= trial.until, heard = if (tested) trial.heard else 0), // Read again each time Settings is composed: the person comes back from the system's page. - notificationAccess = NotificationReader.granted(context), + notificationAccess = NotificationAccess.granted(context), + notificationsBuild = NotificationAccess.AVAILABLE, navApps = remember { NavApp.installedApps(context).map { it.id } }, ), actions, @@ -815,36 +818,51 @@ private fun PhoneActionsGroup(state: SettingsState, actions: SettingsActions) { ) } -/** Notification summaries: off by default; on needs Android's notification access too, which this explains. */ +/** + * Notification summaries: off by default; on needs Android's notification access too, which this + * explains. In a build without the listener the group says which build has it, and why. + */ @Composable private fun NotificationSummaryGroup(state: SettingsState, actions: SettingsActions) { val palette = LocalPalette.current val on = state.prefs.notificationSummaries Group(stringResource(R.string.notification_summaries)) { - SettingRow( - Icons.Filled.Notifications, - stringResource(R.string.notification_summaries_switch), - subtitle = stringResource(R.string.notification_summaries_line), - onClick = { actions.notificationSummaries(!on) }, - trailing = { Switch(checked = on, onCheckedChange = actions::notificationSummaries) }, - ) - if (on) { - Rule() + if (!state.notificationsBuild) { SettingRow( - Icons.Filled.Security, - stringResource(R.string.notification_access), - subtitle = stringResource(if (state.notificationAccess) R.string.notification_access_on else R.string.notification_access_off), - tint = if (state.notificationAccess) null else palette.warning, - onClick = actions::notificationAccess, + Icons.Filled.Notifications, + stringResource(R.string.notification_summaries_switch), + subtitle = stringResource(R.string.notification_summaries_unavailable), + enabled = false, + onClick = {}, ) + } else { + SettingRow( + Icons.Filled.Notifications, + stringResource(R.string.notification_summaries_switch), + subtitle = stringResource(R.string.notification_summaries_line), + onClick = { actions.notificationSummaries(!on) }, + trailing = { Switch(checked = on, onCheckedChange = actions::notificationSummaries) }, + ) + if (on) { + Rule() + SettingRow( + Icons.Filled.Security, + stringResource(R.string.notification_access), + subtitle = stringResource(if (state.notificationAccess) R.string.notification_access_on else R.string.notification_access_off), + tint = if (state.notificationAccess) null else palette.warning, + onClick = actions::notificationAccess, + ) + } } } - Text( - stringResource(R.string.notification_summaries_privacy), - style = MaterialTheme.typography.bodySmall, - color = palette.inkFaint, - modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), - ) + if (state.notificationsBuild) { + Text( + stringResource(R.string.notification_summaries_privacy), + style = MaterialTheme.typography.bodySmall, + color = palette.inkFaint, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), + ) + } } @Composable diff --git a/app/src/main/java/eu/llembas/android/update/Updater.kt b/app/src/main/java/eu/llembas/android/update/Updater.kt index c1afd6f..c67cfe2 100644 --- a/app/src/main/java/eu/llembas/android/update/Updater.kt +++ b/app/src/main/java/eu/llembas/android/update/Updater.kt @@ -13,6 +13,7 @@ import eu.llembas.android.R import eu.llembas.android.api.LembasJson import eu.llembas.android.api.SharedHttp import eu.llembas.android.api.await +import eu.llembas.android.notify.NotificationAccess import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable @@ -20,9 +21,24 @@ import okhttp3.Request import java.io.File import java.security.MessageDigest -/** What llembas.eu says the newest release is (`site/android/latest.json`, written at release). */ +/** One APK of a release: where it is and its SHA-256. */ @Serializable -data class Latest(val version: String, val url: String, val sha256: String, val notes: String = "") +data class LatestFile(val url: String, val sha256: String) + +/** + * What llembas.eu says the newest release is (`site/android/latest.json`, written at release): + * the standard APK as [url] and [sha256], and the `notifications` build's (the same app with the + * notification listener) as [notifications] when the release has one. + */ +@Serializable +data class Latest(val version: String, val url: String, val sha256: String, val notes: String = "", val notifications: LatestFile? = null) { + /** + * The file this build updates itself to: its own kind, never the other. A `notifications` + * build that installed the standard APK would lose its listener without a word (same id, + * same key: Android takes it), so without its own file it installs nothing. + */ + fun fileFor(notificationsBuild: Boolean): LatestFile? = if (notificationsBuild) notifications else LatestFile(url, sha256) +} /** * The `full` build updates itself, as LLeMbas Desktop does: the manifest on the website names @@ -47,12 +63,13 @@ class Updater(private val context: Context) { ) return@withContext context.getString(R.string.update_allow_installs) } + val file = latest.fileFor(NotificationAccess.AVAILABLE) ?: return@withContext context.getString(R.string.update_notifications_manual) val apk = File(context.cacheDir, "update.apk") - SharedHttp.newCall(Request.Builder().url(latest.url).build()).await().use { response -> + SharedHttp.newCall(Request.Builder().url(file.url).build()).await().use { response -> if (!response.isSuccessful) return@withContext context.getString(R.string.update_unreachable) apk.outputStream().use { out -> response.body!!.byteStream().copyTo(out) } } - if (sha256(apk) != latest.sha256.lowercase()) { + if (sha256(apk) != file.sha256.lowercase()) { apk.delete() return@withContext context.getString(R.string.update_bad_file) } diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 913ad6f..ec3b60d 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -449,6 +449,8 @@ Shrnutí oznámení Dovolit asistentovi číst má oznámení, když o to požádám Řekněte „shrň moje oznámení“, nebo klepněte na tlačítko v asistentovi. + V tomto sestavení není. Čtení oznámení vyžaduje sestavení LLeMbas „notifications“, protože Google Play Protect blokuje instalaci aplikace mimo Obchod Play, která je umí číst. Je to stejná aplikace se stejným podpisem: na stránce vydání se soubor končící na -notifications.apk nainstaluje přes tuto. + Toto je sestavení „notifications“: aktualizaci nainstalujte ze stránky vydání, soubor končící na -notifications.apk. Přístup k oznámením Uděleno. Přepínač Androidu je v systémovém nastavení. Zatím neuděleno. Klepnutím otevřete přepínač Androidu pro LLeMbas. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index cc52bc5..a79c4f8 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -449,6 +449,8 @@ Zusammenfassungen der Benachrichtigungen Den Assistenten meine Benachrichtigungen lesen lassen, wenn ich frage Sag „fasse meine Benachrichtigungen zusammen“ oder tippe auf den Chip im Assistenten. + Nicht in diesem Build. Das Lesen von Benachrichtigungen braucht den „notifications“-Build von LLeMbas, weil Google Play Protect die Installation einer App von außerhalb des Play Store blockiert, die sie lesen kann. Es ist dieselbe App mit derselben Signatur: Auf der Release-Seite lässt sich die Datei, die auf -notifications.apk endet, über diese installieren. + Dies ist der „notifications“-Build: Installiere das Update von der Release-Seite, die Datei, die auf -notifications.apk endet. Zugriff auf Benachrichtigungen Erteilt. Der Schalter dafür ist in den Android-Einstellungen. Noch nicht erteilt. Tippe, um den Android-Schalter für LLeMbas zu öffnen. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 82189d8..949d24f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -449,6 +449,8 @@ Resúmenes de notificaciones Dejar que el asistente lea mis notificaciones cuando lo pida Pide «resume mis notificaciones» o toca el botón en el asistente. + No en esta versión. Leer notificaciones requiere la versión «notifications» de LLeMbas, porque Google Play Protect bloquea la instalación de una app de fuera de Play Store que pueda leerlas. Es la misma app con la misma firma: en la página de la versión, el archivo que termina en -notifications.apk se instala sobre esta. + Esta es la versión «notifications»: instala la actualización desde su página, el archivo que termina en -notifications.apk. Acceso a notificaciones Concedido. El interruptor de Android está en los ajustes del sistema. Aún no concedido. Toca para abrir el interruptor de Android para LLeMbas. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 4c7d027..bdbb41a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -449,6 +449,8 @@ Résumés des notifications Laisser l’assistant lire mes notifications quand je le demande Demandez « résume mes notifications », ou touchez la puce dans l’assistant. + Pas dans cette version. Lire les notifications demande la version « notifications » de LLeMbas, car Google Play Protect bloque l’installation d’une app hors du Play Store capable de les lire. C’est la même app avec la même signature : sur la page de la version, le fichier se terminant par -notifications.apk s’installe par-dessus celle-ci. + Ceci est la version « notifications » : installez la mise à jour depuis sa page, le fichier se terminant par -notifications.apk. Accès aux notifications Accordé. L’interrupteur d’Android est dans les paramètres du système. Pas encore accordé. Touchez pour ouvrir l’interrupteur d’Android pour LLeMbas. diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index eae7ed7..819ebc1 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -449,6 +449,8 @@ Értesítések összefoglalása Az asszisztens kérésemre elolvashatja az értesítéseimet Kérd, hogy „foglald össze az értesítéseimet”, vagy koppints a gombra az asszisztensben. + Ebben a változatban nincs. Az értesítések olvasásához a LLeMbas „notifications” változata kell, mert a Google Play Protect letiltja az olyan, Play Áruházon kívüli alkalmazás telepítését, amely olvasni tudja őket. Ugyanaz az alkalmazás ugyanazzal az aláírással: a kiadás oldalán a -notifications.apk végű fájl erre telepíthető rá. + Ez a „notifications” változat: a frissítést a kiadás oldaláról telepítsd, a -notifications.apk végű fájlt. Hozzáférés az értesítésekhez Megadva. Az Android kapcsolója a rendszerbeállításokban van. Még nincs megadva. Koppints az Android LLeMbas-kapcsolójának megnyitásához. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index fb6c7c6..ac7ec18 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -449,6 +449,8 @@ Riepiloghi delle notifiche Lascia che l’assistente legga le mie notifiche quando lo chiedo Chiedi «riassumi le mie notifiche» o tocca il pulsante nell’assistente. + Non in questa build. Leggere le notifiche richiede la build «notifications» di LLeMbas, perché Google Play Protect blocca l’installazione di un’app esterna al Play Store in grado di leggerle. È la stessa app con la stessa firma: nella pagina della release, il file che termina in -notifications.apk si installa sopra questa. + Questa è la build «notifications»: installa l’aggiornamento dalla pagina della release, il file che termina in -notifications.apk. Accesso alle notifiche Concesso. L’interruttore di Android è nelle impostazioni di sistema. Non ancora concesso. Tocca per aprire l’interruttore di Android per LLeMbas. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 063fabe..5236d6f 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -449,6 +449,8 @@ Podsumowania powiadomień Pozwól asystentowi czytać moje powiadomienia, gdy poproszę Poproś „podsumuj moje powiadomienia” albo dotknij przycisku w asystencie. + Nie w tej wersji. Czytanie powiadomień wymaga wersji „notifications” LLeMbas, bo Google Play Protect blokuje instalację aplikacji spoza Sklepu Play, która potrafi je czytać. To ta sama aplikacja z tym samym podpisem: na stronie wydania plik kończący się na -notifications.apk instaluje się na tę. + To jest wersja „notifications”: zainstaluj aktualizację ze strony wydania, plik kończący się na -notifications.apk. Dostęp do powiadomień Przyznany. Przełącznik Androida jest w ustawieniach systemu. Jeszcze nie przyznany. Dotknij, aby otworzyć przełącznik Androida dla LLeMbas. diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index b32b4b6..0eace23 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -449,6 +449,8 @@ Zhrnutia oznámení Dovoliť asistentovi čítať moje oznámenia, keď o to požiadam Povedzte „zhrň moje oznámenia“, alebo ťuknite na tlačidlo v asistentovi. + V tomto zostavení nie je. Čítanie oznámení vyžaduje zostavenie LLeMbas „notifications“, pretože Google Play Protect blokuje inštaláciu aplikácie mimo Obchodu Play, ktorá ich dokáže čítať. Je to tá istá aplikácia s tým istým podpisom: na stránke vydania sa súbor končiaci na -notifications.apk nainštaluje cez túto. + Toto je zostavenie „notifications“: aktualizáciu nainštalujte zo stránky vydania, súbor končiaci na -notifications.apk. Prístup k oznámeniam Udelený. Prepínač Androidu je v systémových nastaveniach. Zatiaľ neudelený. Ťuknutím otvoríte prepínač Androidu pre LLeMbas. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e07f63d..668f0b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -451,6 +451,8 @@ Notification summaries Let the assistant read my notifications when I ask Ask “summarise my notifications”, or tap the chip in the assistant. + Not in this build. Reading notifications needs the “notifications” build of LLeMbas, because Google Play Protect blocks installing an app from outside the Play Store that can read them. It is the same app with the same signature: on the release page, the file ending in -notifications.apk installs over this one. + This is the “notifications” build: install the update from its release page, the file ending in -notifications.apk. Notification access Given. Android\'s switch for it is in the system\'s settings. Not given yet. Tap to open Android\'s switch for LLeMbas. diff --git a/app/src/notifications/AndroidManifest.xml b/app/src/notifications/AndroidManifest.xml new file mode 100644 index 0000000..2216478 --- /dev/null +++ b/app/src/notifications/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/app/src/notifications/java/eu/llembas/android/notify/NotificationAccess.kt b/app/src/notifications/java/eu/llembas/android/notify/NotificationAccess.kt new file mode 100644 index 0000000..18a79aa --- /dev/null +++ b/app/src/notifications/java/eu/llembas/android/notify/NotificationAccess.kt @@ -0,0 +1,88 @@ +package eu.llembas.android.notify + +import android.app.KeyguardManager +import android.app.Notification +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.os.Build +import android.provider.Settings +import android.service.notification.NotificationListenerService +import android.service.notification.StatusBarNotification +import androidx.core.app.NotificationManagerCompat + +/** + * Notification summaries on request: the assistant reads the notifications on the phone only when + * the person asks it to ("summarise my notifications", or the sheet's chip), and sends their text + * with that one question. Off by default, twice over: Android's own notification-access switch + * (which only the person can turn on, in the system's settings) and Settings › Assistant's. + * + * The listener keeps nothing: it is how Android lets an app read the notifications that are up + * right now ([activeNotifications]), and nothing is read until a question asks for it. Never over + * the lock screen ([NotificationAccess.read] returns nothing while the phone is locked). + * + * Only the `notifications` build has this class and declares the service; the standard builds + * have a [NotificationAccess] that can do nothing. + */ +class LembasNotificationListener : NotificationListenerService() { + override fun onListenerConnected() { + super.onListenerConnected() + current = this + } + + override fun onListenerDisconnected() { + if (current === this) current = null + super.onListenerDisconnected() + } + + companion object { + @Volatile + var current: LembasNotificationListener? = null + private set + } +} + +/** Reading the phone's notifications, in the build that can. */ +object NotificationAccess { + const val AVAILABLE = true + + /** Whether the person gave LLeMbas notification access in the system's settings. */ + fun granted(context: Context): Boolean = context.packageName in NotificationManagerCompat.getEnabledListenerPackages(context) + + /** The system's page for this app's notification access (the detail page where Android has one). */ + fun settingsIntent(context: Context): Intent? = if (Build.VERSION.SDK_INT >= 30) { + Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS) + .putExtra(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, ComponentName(context, LembasNotificationListener::class.java).flattenToString()) + } else { + Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) + }.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + + /** The notifications up now, newest first -- or none, when locked or not allowed. */ + fun read(context: Context): List { + if (context.getSystemService(KeyguardManager::class.java).isKeyguardLocked) return emptyList() + val listener = LembasNotificationListener.current ?: return emptyList() + val shown = runCatching { listener.activeNotifications }.getOrNull().orEmpty() + return shown + .filter { it.packageName != context.packageName && !it.isOngoing && it.notification.flags and Notification.FLAG_GROUP_SUMMARY == 0 } + .sortedByDescending { it.postTime } + .mapNotNull { notice(context, it) } + .take(MAX_NOTICES) + } + + private fun notice(context: Context, sbn: StatusBarNotification): Notice? { + val extras = sbn.notification.extras + val title = extras.getCharSequence(Notification.EXTRA_TITLE)?.toString().orEmpty() + val lines = extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)?.joinToString("\n").orEmpty() + val text = (extras.getCharSequence(Notification.EXTRA_BIG_TEXT) ?: extras.getCharSequence(Notification.EXTRA_TEXT))?.toString() + ?.ifBlank { null } ?: lines + if (title.isBlank() && text.isBlank()) return null + val app = runCatching { + val pm = context.packageManager + pm.getApplicationLabel(pm.getApplicationInfo(sbn.packageName, 0)).toString() + }.getOrDefault(sbn.packageName) + return Notice(app, title, text.take(MAX_TEXT), sbn.postTime) + } + + private const val MAX_NOTICES = 40 + private const val MAX_TEXT = 600 +} diff --git a/app/src/standard/java/eu/llembas/android/notify/NotificationAccess.kt b/app/src/standard/java/eu/llembas/android/notify/NotificationAccess.kt new file mode 100644 index 0000000..e84e987 --- /dev/null +++ b/app/src/standard/java/eu/llembas/android/notify/NotificationAccess.kt @@ -0,0 +1,21 @@ +package eu.llembas.android.notify + +import android.content.Context +import android.content.Intent + +/** + * The standard builds cannot read the phone's notifications: they declare no notification + * listener at all, because Google Play Protect blocks installing an app from outside the Play + * Store that does. Notification summaries are in the `notifications` build -- the same app, the + * same signature, with the listener -- and Settings says so. Everything else about them is the + * same code in both, which here simply never has anything to read. + */ +object NotificationAccess { + const val AVAILABLE = false + + fun granted(context: Context): Boolean = false + + fun settingsIntent(context: Context): Intent? = null + + fun read(context: Context): List = emptyList() +} diff --git a/app/src/test/java/eu/llembas/android/SmallThingsTest.kt b/app/src/test/java/eu/llembas/android/SmallThingsTest.kt index 3557196..fd1d7f7 100644 --- a/app/src/test/java/eu/llembas/android/SmallThingsTest.kt +++ b/app/src/test/java/eu/llembas/android/SmallThingsTest.kt @@ -1,10 +1,14 @@ package eu.llembas.android +import eu.llembas.android.api.LembasJson import eu.llembas.android.assist.AssistController import eu.llembas.android.assist.Recorder +import eu.llembas.android.update.Latest +import eu.llembas.android.update.LatestFile import eu.llembas.android.update.Updater import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test @@ -17,6 +21,20 @@ class SmallThingsTest { assertFalse(Updater.newer("0.1.0", "0.2.0")) } + @Test + fun aBuildUpdatesItselfToItsOwnKindOnly() { + val plain = LembasJson.decodeFromString(Latest.serializer(), """{"version":"1.0.0","url":"https://example.org/a.apk","sha256":"aa"}""") + assertEquals(LatestFile("https://example.org/a.apk", "aa"), plain.fileFor(notificationsBuild = false)) + // A release that names no notifications APK: that build installs nothing, rather than lose its listener. + assertNull(plain.fileFor(notificationsBuild = true)) + val both = LembasJson.decodeFromString( + Latest.serializer(), + """{"version":"1.0.0","url":"https://example.org/a.apk","sha256":"aa","notifications":{"url":"https://example.org/a-notifications.apk","sha256":"bb"}}""", + ) + assertEquals(LatestFile("https://example.org/a-notifications.apk", "bb"), both.fileFor(notificationsBuild = true)) + assertEquals(LatestFile("https://example.org/a.apk", "aa"), both.fileFor(notificationsBuild = false)) + } + @Test fun aVoiceReadsNoMarkup() { val said = AssistController.plain("**Bake** it.\n\n```sh\nbake\n```\nSee [the recipe](https://example.org).") diff --git a/app/src/test/java/eu/llembas/android/shots/Fakes.kt b/app/src/test/java/eu/llembas/android/shots/Fakes.kt index 879a3f4..47c47e4 100644 --- a/app/src/test/java/eu/llembas/android/shots/Fakes.kt +++ b/app/src/test/java/eu/llembas/android/shots/Fakes.kt @@ -367,6 +367,7 @@ object Fakes { phoneRecognizer = true, wakeAvailable = true, wakeState = WakeState.Listening("OK Google"), + notificationsBuild = true, navApps = listOf("google", "osmand"), ) @@ -376,7 +377,9 @@ object Fakes { wakeState = WakeState.Failed(WakeFailure.Microphone, "IllegalStateException: recording did not start; another app may have the microphone"), wakeTest = WakeTestShown(done = true), ) - val settingsWakeTested = settings.copy(wakeTest = WakeTestShown(running = true, heard = 2)) + + /** A standard build: the test heard the phrase twice, and notification summaries are in the other build. */ + val settingsWakeTested = settings.copy(wakeTest = WakeTestShown(running = true, heard = 2), notificationsBuild = false) // The assistant's sheet, as it opens and as it answers. private val assistBase = AssistUiState( diff --git a/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt index 14373a4..048cef3 100644 --- a/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt +++ b/app/src/test/java/eu/llembas/android/shots/ScreenShots.kt @@ -193,7 +193,9 @@ class ScreenShots { // The wake word's rows: failed with its reason and a test that heard nothing; a test that heard it twice. shoot("08-settings-wake-failed", Phone.Scroll) { SettingsContent(Fakes.settingsWakeFailed, NoSettingsActions) } shoot("08-settings-wake-failed", Phone.SmallScroll, fontScale = 1.5f) { SettingsContent(Fakes.settingsWakeFailed, NoSettingsActions) } + // ...and, as a standard build has it, notification summaries explained instead of offered. shoot("08-settings-wake-tested", Phone.Scroll) { SettingsContent(Fakes.settingsWakeTested, NoSettingsActions) } + shoot("08-settings-wake-tested", Phone.SmallScroll, fontScale = 1.5f) { SettingsContent(Fakes.settingsWakeTested, NoSettingsActions) } } @Test diff --git a/scripts/check-apk.sh b/scripts/check-apk.sh new file mode 100755 index 0000000..30f1efe --- /dev/null +++ b/scripts/check-apk.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# What an APK declares and carries, checked on the built file rather than believed from the build +# script. CI runs it on every push's builds and the release workflow on what it is about to publish. +# +# scripts/check-apk.sh [release] +# +# is `standard` (the full build), `fdroid` or `notifications`: +# - only `notifications` may declare a notification listener or name its permission; the other +# two must have nothing of it in the manifest (Google Play Protect blocks installing an app +# from outside the Play Store that can read notifications); +# - `standard` and `notifications` carry the wake-word model, stored uncompressed, and the +# engine's library for arm64; `fdroid` carries neither; +# - with `release`, no x86_64 library (only an emulator would load it). +set -euo pipefail +apk="$1"; kind="$2"; release="${3:-}" +[ -f "$apk" ] || { echo "check-apk: no $apk" >&2; exit 1; } +fail() { echo "check-apk: $(basename "$apk"): $1" >&2; exit 1; } + +aapt2="$(find "${ANDROID_HOME:?ANDROID_HOME is not set}/build-tools" -name aapt2 -type f | sort -V | tail -1)" +[ -x "$aapt2" ] || fail "no aapt2 under ANDROID_HOME" +manifest="$("$aapt2" dump xmltree --file AndroidManifest.xml "$apk")" +listener=0 +grep -qiE "notification_?listener" <<<"$manifest" && listener=1 +case "$kind" in + notifications) [ "$listener" = 1 ] || fail "the notifications build declares no notification listener" ;; + standard|fdroid) [ "$listener" = 0 ] || fail "a $kind build must not declare a notification listener" ;; + *) fail "unknown kind $kind" ;; +esac + +files="$(unzip -v "$apk")" +models="$(awk '$NF ~ /^assets\/wakeword\/.*\.onnx$/' <<<"$files")" +if [ "$kind" = fdroid ]; then + [ -z "$models" ] || fail "the fdroid build carries the wake-word model" + ! grep -q " lib/.*libsherpa" <<<"$files" || fail "the fdroid build carries the wake-word engine" +else + [ "$(wc -l <<<"$models")" = 3 ] || fail "expected the three model files in assets/wakeword" + ! awk '$2 != "Stored"' <<<"$models" | grep -q . || fail "a model file is compressed (the engine's files must be stored)" + grep -q " assets/wakeword/version$" <<<"$files" || fail "no assets/wakeword/version" + grep -q " lib/arm64-v8a/libsherpa-onnx-jni.so$" <<<"$files" || fail "no arm64 wake-word engine" +fi +if [ "$release" = release ]; then + ! grep -q " lib/x86" <<<"$files" || fail "a release must carry no x86 library" +fi +size="$(stat -c %s "$apk")" +echo "check-apk: $(basename "$apk"): $kind${release:+ $release}, $((size / 1024 / 1024)) MB, as it should be" diff --git a/scripts/strings.py b/scripts/strings.py index 32e3684..19b1e15 100755 --- a/scripts/strings.py +++ b/scripts/strings.py @@ -476,6 +476,8 @@ STRINGS: dict[str, str] = { "notification_summaries": "Notification summaries", "notification_summaries_switch": "Let the assistant read my notifications when I ask", "notification_summaries_line": "Ask “summarise my notifications”, or tap the chip in the assistant.", + "notification_summaries_unavailable": "Not in this build. Reading notifications needs the “notifications” build of LLeMbas, because Google Play Protect blocks installing an app from outside the Play Store that can read them. It is the same app with the same signature: on the release page, the file ending in -notifications.apk installs over this one.", + "update_notifications_manual": "This is the “notifications” build: install the update from its release page, the file ending in -notifications.apk.", "notification_access": "Notification access", "notification_access_on": "Given. Android's switch for it is in the system's settings.", "notification_access_off": "Not given yet. Tap to open Android's switch for LLeMbas.", diff --git a/scripts/strings_own.json b/scripts/strings_own.json index bad3113..a349284 100644 --- a/scripts/strings_own.json +++ b/scripts/strings_own.json @@ -143,6 +143,7 @@ "notification_summaries_line": "Řekněte „shrň moje oznámení“, nebo klepněte na tlačítko v asistentovi.", "notification_summaries_privacy": "Ve výchozím stavu vypnuto. Když požádáte, text oznámení, která jsou v telefonu právě teď (aplikace, název, text), půjde s touto jedinou otázkou na vaši instanci a její model. Dřív se nic nečte, aplikace si nic neponechá a při zamčeném telefonu se nečte nic. Přístup k oznámením v Androidu dovolí aplikaci vidět každé oznámení, proto je na vás, zda ho dáte a zase vezmete.", "notification_summaries_switch": "Dovolit asistentovi číst má oznámení, když o to požádám", + "notification_summaries_unavailable": "V tomto sestavení není. Čtení oznámení vyžaduje sestavení LLeMbas „notifications“, protože Google Play Protect blokuje instalaci aplikace mimo Obchod Play, která je umí číst. Je to stejná aplikace se stejným podpisem: na stránce vydání se soubor končící na -notifications.apk nainstaluje přes tuto.", "notify_always": "Dá vědět pokaždé", "notify_matters": "Dá vědět, když na tom záleží", "notify_never": "Nedá vědět nikdy", @@ -254,6 +255,7 @@ "update_none": "Toto je nejnovější verze.", "update_notice_text": "Je k dispozici novější verze. Klepnutím otevřete stránku vydání.", "update_notice_title": "LLeMbas pro Android %1$s", + "update_notifications_manual": "Toto je sestavení „notifications“: aktualizaci nainstalujte ze stránky vydání, soubor končící na -notifications.apk.", "update_unreachable": "Aktualizaci se nepodařilo stáhnout.", "viewer_html_source": "Toto je zdrojový kód stránky. Samotnou stránku uvidíte po otevření v prohlížeči.", "viewer_long_markdown": "Dlouhý soubor, proto je zobrazen jako prostý text.", @@ -462,6 +464,7 @@ "notification_summaries_line": "Sag „fasse meine Benachrichtigungen zusammen“ oder tippe auf den Chip im Assistenten.", "notification_summaries_privacy": "Standardmäßig aus. Wenn du fragst, geht der Text der Benachrichtigungen, die gerade auf deinem Telefon sind (App, Titel, Text), mit dieser einen Frage an deine Instanz und ihr Modell. Vorher wird nichts gelesen, die App behält nichts davon, und bei gesperrtem Telefon wird nichts gelesen. Der Benachrichtigungszugriff von Android lässt eine App jede Benachrichtigung sehen; ihn zu erteilen und zu entziehen liegt bei dir.", "notification_summaries_switch": "Den Assistenten meine Benachrichtigungen lesen lassen, wenn ich frage", + "notification_summaries_unavailable": "Nicht in diesem Build. Das Lesen von Benachrichtigungen braucht den „notifications“-Build von LLeMbas, weil Google Play Protect die Installation einer App von außerhalb des Play Store blockiert, die sie lesen kann. Es ist dieselbe App mit derselben Signatur: Auf der Release-Seite lässt sich die Datei, die auf -notifications.apk endet, über diese installieren.", "notify_always": "Meldet sich jedes Mal", "notify_matters": "Meldet sich, wenn es wichtig ist", "notify_never": "Meldet sich nie", @@ -573,6 +576,7 @@ "update_none": "Dies ist die neueste Version.", "update_notice_text": "Eine neuere Version ist verfügbar. Tippen Sie, um die Release-Seite zu öffnen.", "update_notice_title": "LLeMbas für Android %1$s", + "update_notifications_manual": "Dies ist der „notifications“-Build: Installiere das Update von der Release-Seite, die Datei, die auf -notifications.apk endet.", "update_unreachable": "Das Update konnte nicht abgerufen werden.", "viewer_html_source": "Das ist der Quelltext der Seite. Die Seite selbst sehen Sie im Browser.", "viewer_long_markdown": "Eine lange Datei, daher wird sie als reiner Text angezeigt.", @@ -780,6 +784,7 @@ "notification_summaries_line": "Pide «resume mis notificaciones» o toca el botón en el asistente.", "notification_summaries_privacy": "Desactivado por defecto. Cuando lo pides, el texto de las notificaciones que hay ahora en tu teléfono (app, título, texto) va con esa única pregunta a tu instancia y su modelo. No se lee nada antes, la app no guarda nada y no se lee nada con el teléfono bloqueado. El acceso a notificaciones de Android permite a una app ver todas las notificaciones; darlo y retirarlo es cosa tuya.", "notification_summaries_switch": "Dejar que el asistente lea mis notificaciones cuando lo pida", + "notification_summaries_unavailable": "No en esta versión. Leer notificaciones requiere la versión «notifications» de LLeMbas, porque Google Play Protect bloquea la instalación de una app de fuera de Play Store que pueda leerlas. Es la misma app con la misma firma: en la página de la versión, el archivo que termina en -notifications.apk se instala sobre esta.", "notify_always": "Avisa siempre", "notify_matters": "Avisa cuando importa", "notify_never": "No avisa nunca", @@ -891,6 +896,7 @@ "update_none": "Esta es la versión más reciente.", "update_notice_text": "Hay una versión más reciente. Toque para abrir su página de publicación.", "update_notice_title": "LLeMbas para Android %1$s", + "update_notifications_manual": "Esta es la versión «notifications»: instala la actualización desde su página, el archivo que termina en -notifications.apk.", "update_unreachable": "No se pudo obtener la actualización.", "viewer_html_source": "Este es el código fuente de la página. Ábrala en el navegador para ver la página.", "viewer_long_markdown": "Un archivo largo, por eso se muestra como texto sin formato.", @@ -1099,6 +1105,7 @@ "notification_summaries_line": "Demandez « résume mes notifications », ou touchez la puce dans l’assistant.", "notification_summaries_privacy": "Désactivé par défaut. Quand vous le demandez, le texte des notifications présentes sur votre téléphone (app, titre, texte) part avec cette seule question vers votre instance et son modèle. Rien n’est lu avant, l’app n’en garde rien, et rien n’est lu téléphone verrouillé. L’accès aux notifications d’Android permet à une app de voir toutes les notifications : c’est à vous de l’accorder et de le retirer.", "notification_summaries_switch": "Laisser l’assistant lire mes notifications quand je le demande", + "notification_summaries_unavailable": "Pas dans cette version. Lire les notifications demande la version « notifications » de LLeMbas, car Google Play Protect bloque l’installation d’une app hors du Play Store capable de les lire. C’est la même app avec la même signature : sur la page de la version, le fichier se terminant par -notifications.apk s’installe par-dessus celle-ci.", "notify_always": "Prévient à chaque fois", "notify_matters": "Prévient quand c’est important", "notify_never": "Ne prévient jamais", @@ -1210,6 +1217,7 @@ "update_none": "C'est la version la plus récente.", "update_notice_text": "Une version plus récente est disponible. Touchez pour ouvrir sa page de publication.", "update_notice_title": "LLeMbas pour Android %1$s", + "update_notifications_manual": "Ceci est la version « notifications » : installez la mise à jour depuis sa page, le fichier se terminant par -notifications.apk.", "update_unreachable": "La mise à jour n'a pas pu être récupérée.", "viewer_html_source": "Ceci est le code source de la page. Ouvrez-la dans le navigateur pour voir la page elle-même.", "viewer_long_markdown": "Un fichier long, il est donc affiché en texte brut.", @@ -1418,6 +1426,7 @@ "notification_summaries_line": "Kérd, hogy „foglald össze az értesítéseimet”, vagy koppints a gombra az asszisztensben.", "notification_summaries_privacy": "Alapból ki van kapcsolva. Ha kéred, a telefonon éppen látható értesítések szövege (alkalmazás, cím, szöveg) ezzel az egy kérdéssel együtt a példányodhoz és a modelljéhez kerül. Előtte semmit nem olvas, az alkalmazás semmit nem tart meg, és zárolt telefonnál semmit nem olvas. Az Android értesítés-hozzáférése minden értesítést láthatóvá tesz egy alkalmazásnak, ezért rajtad múlik, megadod-e, és visszavonod-e.", "notification_summaries_switch": "Az asszisztens kérésemre elolvashatja az értesítéseimet", + "notification_summaries_unavailable": "Ebben a változatban nincs. Az értesítések olvasásához a LLeMbas „notifications” változata kell, mert a Google Play Protect letiltja az olyan, Play Áruházon kívüli alkalmazás telepítését, amely olvasni tudja őket. Ugyanaz az alkalmazás ugyanazzal az aláírással: a kiadás oldalán a -notifications.apk végű fájl erre telepíthető rá.", "notify_always": "Mindig szól", "notify_matters": "Szól, ha számít", "notify_never": "Soha nem szól", @@ -1529,6 +1538,7 @@ "update_none": "Ez a legújabb verzió.", "update_notice_text": "Újabb verzió érhető el. Koppintson a kiadás oldalának megnyitásához.", "update_notice_title": "LLeMbas Androidra %1$s", + "update_notifications_manual": "Ez a „notifications” változat: a frissítést a kiadás oldaláról telepítsd, a -notifications.apk végű fájlt.", "update_unreachable": "A frissítést nem sikerült letölteni.", "viewer_html_source": "Ez az oldal forráskódja. Magát az oldalt a böngészőben megnyitva láthatja.", "viewer_long_markdown": "Hosszú fájl, ezért egyszerű szövegként jelenik meg.", @@ -1736,6 +1746,7 @@ "notification_summaries_line": "Chiedi «riassumi le mie notifiche» o tocca il pulsante nell’assistente.", "notification_summaries_privacy": "Disattivato per impostazione predefinita. Quando lo chiedi, il testo delle notifiche presenti ora sul telefono (app, titolo, testo) va con quella sola domanda alla tua istanza e al suo modello. Prima non si legge nulla, l’app non conserva nulla e a telefono bloccato non si legge nulla. L’accesso alle notifiche di Android permette a un’app di vedere ogni notifica: concederlo e revocarlo spetta a te.", "notification_summaries_switch": "Lascia che l’assistente legga le mie notifiche quando lo chiedo", + "notification_summaries_unavailable": "Non in questa build. Leggere le notifiche richiede la build «notifications» di LLeMbas, perché Google Play Protect blocca l’installazione di un’app esterna al Play Store in grado di leggerle. È la stessa app con la stessa firma: nella pagina della release, il file che termina in -notifications.apk si installa sopra questa.", "notify_always": "Avvisa ogni volta", "notify_matters": "Avvisa quando conta", "notify_never": "Non avvisa mai", @@ -1847,6 +1858,7 @@ "update_none": "Questa è la versione più recente.", "update_notice_text": "È disponibile una versione più recente. Tocca per aprire la pagina della release.", "update_notice_title": "LLeMbas per Android %1$s", + "update_notifications_manual": "Questa è la build «notifications»: installa l’aggiornamento dalla pagina della release, il file che termina in -notifications.apk.", "update_unreachable": "Non è stato possibile scaricare l'aggiornamento.", "viewer_html_source": "Questo è il sorgente della pagina. Aprila nel browser per vedere la pagina.", "viewer_long_markdown": "Un file lungo, quindi è mostrato come testo semplice.", @@ -2054,6 +2066,7 @@ "notification_summaries_line": "Poproś „podsumuj moje powiadomienia” albo dotknij przycisku w asystencie.", "notification_summaries_privacy": "Domyślnie wyłączone. Gdy poprosisz, tekst powiadomień, które są teraz na telefonie (aplikacja, tytuł, treść), trafi z tym jednym pytaniem do Twojej instancji i jej modelu. Wcześniej nic nie jest czytane, aplikacja niczego nie zachowuje i nic nie jest czytane przy zablokowanym telefonie. Dostęp do powiadomień w Androidzie pozwala aplikacji widzieć każde powiadomienie, więc to Ty decydujesz, czy go dać i odebrać.", "notification_summaries_switch": "Pozwól asystentowi czytać moje powiadomienia, gdy poproszę", + "notification_summaries_unavailable": "Nie w tej wersji. Czytanie powiadomień wymaga wersji „notifications” LLeMbas, bo Google Play Protect blokuje instalację aplikacji spoza Sklepu Play, która potrafi je czytać. To ta sama aplikacja z tym samym podpisem: na stronie wydania plik kończący się na -notifications.apk instaluje się na tę.", "notify_always": "Powiadamia za każdym razem", "notify_matters": "Powiadamia, gdy to ważne", "notify_never": "Nigdy nie powiadamia", @@ -2165,6 +2178,7 @@ "update_none": "To jest najnowsza wersja.", "update_notice_text": "Dostępna jest nowsza wersja. Dotknij, aby otworzyć jej stronę wydania.", "update_notice_title": "LLeMbas na Androida %1$s", + "update_notifications_manual": "To jest wersja „notifications”: zainstaluj aktualizację ze strony wydania, plik kończący się na -notifications.apk.", "update_unreachable": "Nie udało się pobrać aktualizacji.", "viewer_html_source": "To jest źródło strony. Otwórz ją w przeglądarce, aby zobaczyć samą stronę.", "viewer_long_markdown": "Długi plik, dlatego jest pokazany jako zwykły tekst.", @@ -2372,6 +2386,7 @@ "notification_summaries_line": "Povedzte „zhrň moje oznámenia“, alebo ťuknite na tlačidlo v asistentovi.", "notification_summaries_privacy": "Predvolene vypnuté. Keď požiadate, text oznámení, ktoré sú v telefóne práve teraz (aplikácia, názov, text), pôjde s touto jedinou otázkou na vašu inštanciu a jej model. Predtým sa nič nečíta, aplikácia si nič neponechá a pri zamknutom telefóne sa nečíta nič. Prístup k oznámeniam v Androide dovolí aplikácii vidieť každé oznámenie, preto je na vás, či ho dáte a znova vezmete.", "notification_summaries_switch": "Dovoliť asistentovi čítať moje oznámenia, keď o to požiadam", + "notification_summaries_unavailable": "V tomto zostavení nie je. Čítanie oznámení vyžaduje zostavenie LLeMbas „notifications“, pretože Google Play Protect blokuje inštaláciu aplikácie mimo Obchodu Play, ktorá ich dokáže čítať. Je to tá istá aplikácia s tým istým podpisom: na stránke vydania sa súbor končiaci na -notifications.apk nainštaluje cez túto.", "notify_always": "Dá vedieť zakaždým", "notify_matters": "Dá vedieť, keď na tom záleží", "notify_never": "Nedá vedieť nikdy", @@ -2483,6 +2498,7 @@ "update_none": "Toto je najnovšia verzia.", "update_notice_text": "Je dostupná novšia verzia. Ťuknutím otvoríte stránku vydania.", "update_notice_title": "LLeMbas pre Android %1$s", + "update_notifications_manual": "Toto je zostavenie „notifications“: aktualizáciu nainštalujte zo stránky vydania, súbor končiaci na -notifications.apk.", "update_unreachable": "Aktualizáciu sa nepodarilo stiahnuť.", "viewer_html_source": "Toto je zdrojový kód stránky. Samotnú stránku uvidíte po otvorení v prehliadači.", "viewer_long_markdown": "Dlhý súbor, preto je zobrazený ako obyčajný text.",