Three APKs: the notification listener leaves the standard builds; releases drop x86_64
CI / check (push) Canceled after 0s

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-<version>.apk, -notifications.apk
  and -fdroid.apk with SHA256SUMS.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Fable 5.2 committed 2026-11-12 09:58:07 +00:00
1 parent 6a05f56e7c
commit f2a2acf996
28 files changed
+403 -140

No files matched your search

+38 -4
View File
@@ -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)
}
-11
View File
@@ -184,17 +184,6 @@
android:exported="false"
android:foregroundServiceType="microphone" />
<!-- Notification summaries (opt-in): read only when a question asks for them. -->
<service
android:name=".notify.LembasNotificationListener"
android:exported="true"
android:label="@string/notification_summaries"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<receiver
android:name=".wake.WakeBootReceiver"
android:exported="true">
@@ -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
}
@@ -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<Notice> {
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<Notice>, 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
}
@@ -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<String> = 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
@@ -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)
}
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Shrnutí oznámení</string>
<string name="notification_summaries_switch">Dovolit asistentovi číst má oznámení, když o to požádám</string>
<string name="notification_summaries_line">Řekněte „shrň moje oznámení“, nebo klepněte na tlačítko v asistentovi.</string>
<string name="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.</string>
<string name="update_notifications_manual">Toto je sestavení „notifications“: aktualizaci nainstalujte ze stránky vydání, soubor končící na -notifications.apk.</string>
<string name="notification_access">Přístup k oznámením</string>
<string name="notification_access_on">Uděleno. Přepínač Androidu je v systémovém nastavení.</string>
<string name="notification_access_off">Zatím neuděleno. Klepnutím otevřete přepínač Androidu pro LLeMbas.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Zusammenfassungen der Benachrichtigungen</string>
<string name="notification_summaries_switch">Den Assistenten meine Benachrichtigungen lesen lassen, wenn ich frage</string>
<string name="notification_summaries_line">Sag „fasse meine Benachrichtigungen zusammen“ oder tippe auf den Chip im Assistenten.</string>
<string name="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.</string>
<string name="update_notifications_manual">Dies ist der „notifications“-Build: Installiere das Update von der Release-Seite, die Datei, die auf -notifications.apk endet.</string>
<string name="notification_access">Zugriff auf Benachrichtigungen</string>
<string name="notification_access_on">Erteilt. Der Schalter dafür ist in den Android-Einstellungen.</string>
<string name="notification_access_off">Noch nicht erteilt. Tippe, um den Android-Schalter für LLeMbas zu öffnen.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Resúmenes de notificaciones</string>
<string name="notification_summaries_switch">Dejar que el asistente lea mis notificaciones cuando lo pida</string>
<string name="notification_summaries_line">Pide «resume mis notificaciones» o toca el botón en el asistente.</string>
<string name="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.</string>
<string name="update_notifications_manual">Esta es la versión «notifications»: instala la actualización desde su página, el archivo que termina en -notifications.apk.</string>
<string name="notification_access">Acceso a notificaciones</string>
<string name="notification_access_on">Concedido. El interruptor de Android está en los ajustes del sistema.</string>
<string name="notification_access_off">Aún no concedido. Toca para abrir el interruptor de Android para LLeMbas.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Résumés des notifications</string>
<string name="notification_summaries_switch">Laisser l’assistant lire mes notifications quand je le demande</string>
<string name="notification_summaries_line">Demandez « résume mes notifications », ou touchez la puce dans l’assistant.</string>
<string name="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.</string>
<string name="update_notifications_manual">Ceci est la version « notifications » : installez la mise à jour depuis sa page, le fichier se terminant par -notifications.apk.</string>
<string name="notification_access">Accès aux notifications</string>
<string name="notification_access_on">Accordé. L’interrupteur d’Android est dans les paramètres du système.</string>
<string name="notification_access_off">Pas encore accordé. Touchez pour ouvrir l’interrupteur d’Android pour LLeMbas.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Értesítések összefoglalása</string>
<string name="notification_summaries_switch">Az asszisztens kérésemre elolvashatja az értesítéseimet</string>
<string name="notification_summaries_line">Kérd, hogy „foglald össze az értesítéseimet”, vagy koppints a gombra az asszisztensben.</string>
<string name="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á.</string>
<string name="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.</string>
<string name="notification_access">Hozzáférés az értesítésekhez</string>
<string name="notification_access_on">Megadva. Az Android kapcsolója a rendszerbeállításokban van.</string>
<string name="notification_access_off">Még nincs megadva. Koppints az Android LLeMbas-kapcsolójának megnyitásához.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Riepiloghi delle notifiche</string>
<string name="notification_summaries_switch">Lascia che l’assistente legga le mie notifiche quando lo chiedo</string>
<string name="notification_summaries_line">Chiedi «riassumi le mie notifiche» o tocca il pulsante nell’assistente.</string>
<string name="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.</string>
<string name="update_notifications_manual">Questa è la build «notifications»: installa l’aggiornamento dalla pagina della release, il file che termina in -notifications.apk.</string>
<string name="notification_access">Accesso alle notifiche</string>
<string name="notification_access_on">Concesso. L’interruttore di Android è nelle impostazioni di sistema.</string>
<string name="notification_access_off">Non ancora concesso. Tocca per aprire l’interruttore di Android per LLeMbas.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Podsumowania powiadomień</string>
<string name="notification_summaries_switch">Pozwól asystentowi czytać moje powiadomienia, gdy poproszę</string>
<string name="notification_summaries_line">Poproś „podsumuj moje powiadomienia” albo dotknij przycisku w asystencie.</string>
<string name="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ę.</string>
<string name="update_notifications_manual">To jest wersja „notifications”: zainstaluj aktualizację ze strony wydania, plik kończący się na -notifications.apk.</string>
<string name="notification_access">Dostęp do powiadomień</string>
<string name="notification_access_on">Przyznany. Przełącznik Androida jest w ustawieniach systemu.</string>
<string name="notification_access_off">Jeszcze nie przyznany. Dotknij, aby otworzyć przełącznik Androida dla LLeMbas.</string>
+2
View File
@@ -449,6 +449,8 @@
<string name="notification_summaries">Zhrnutia oznámení</string>
<string name="notification_summaries_switch">Dovoliť asistentovi čítať moje oznámenia, keď o to požiadam</string>
<string name="notification_summaries_line">Povedzte „zhrň moje oznámenia“, alebo ťuknite na tlačidlo v asistentovi.</string>
<string name="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.</string>
<string name="update_notifications_manual">Toto je zostavenie „notifications“: aktualizáciu nainštalujte zo stránky vydania, súbor končiaci na -notifications.apk.</string>
<string name="notification_access">Prístup k oznámeniam</string>
<string name="notification_access_on">Udelený. Prepínač Androidu je v systémových nastaveniach.</string>
<string name="notification_access_off">Zatiaľ neudelený. Ťuknutím otvoríte prepínač Androidu pre LLeMbas.</string>
+2
View File
@@ -451,6 +451,8 @@
<string name="notification_summaries">Notification summaries</string>
<string name="notification_summaries_switch">Let the assistant read my notifications when I ask</string>
<string name="notification_summaries_line">Ask “summarise my notifications”, or tap the chip in the assistant.</string>
<string name="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.</string>
<string name="update_notifications_manual">This is the “notifications” build: install the update from its release page, the file ending in -notifications.apk.</string>
<string name="notification_access">Notification access</string>
<string name="notification_access_on">Given. Android\'s switch for it is in the system\'s settings.</string>
<string name="notification_access_off">Not given yet. Tap to open Android\'s switch for LLeMbas.</string>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The `notifications` build: the full build plus the notification listener (notification
summaries, opt-in). Only this build declares it; the standard builds do not, because
Google Play Protect blocks installing an app from outside the Play Store that does. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<!-- Read only when a question asks for them (notify/NotificationAccess.kt). -->
<service
android:name="eu.llembas.android.notify.LembasNotificationListener"
android:exported="true"
android:label="@string/notification_summaries"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>
</manifest>
@@ -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<Notice> {
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
}
@@ -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<Notice> = emptyList()
}
@@ -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).")
@@ -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(
@@ -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