googlesamples / googlesamples/mlkit

Document that AICore blocks inference for backgrounded apps (GenAiException BACKGROUND_USE_BLOCKED / error code 30)

Offen
#1,069 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Kotlin
Sterne
4.3k
Forks
3.1k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### Description

AICore refuses inference requests from apps that are not in the foreground. The Prompt API surfaces this as a `GenAiException` with error code 30 (`ErrorCode.BACKGROUND_USE_BLOCKED`):

```
AiCoreInferenceHelper: runInference onFailure
bmj: null (statusCode = 30)
```

Availability checks (`checkStatus()`) succeed from the background; only inference is blocked. None of this is currently documented in the Prompt API guides or the AICore documentation.

### Why this matters

The natural architecture for many on-device GenAI features is background generation – e.g. a WorkManager job that prepares a daily summary before the user wakes up, precisely the kind of privacy-friendly use case on-device models are marketed for. Developers will design and build such architectures and only discover at runtime, on device, that they cannot work. In our case (a production weather app), a WorkManager-based morning brief had to be redesigned around foreground-only generation after the failure was discovered on hardware.

### Concrete reproduction

Run any `generateContent()` call from an instrumentation test without a resumed activity (or from a WorkManager worker): error code 30. Launch an activity first (e.g. `ActivityScenario.launch`) and the same call succeeds. Observed on Pixel 10 Pro XL, Android 17, genai-prompt 1.0.0-beta4.

### Requested

1. Document the foreground requirement prominently in the Prompt API and
GenAI API guides – ideally under a "Constraints" heading alongside device eligibility.
2. Document `ErrorCode.BACKGROUND_USE_BLOCKED` and the recommended handling.
3. Ideally: expose the policy programmatically (e.g. a queryable capability
or a documented contract for what counts as "foreground") so apps can route to a server fallback proactively instead of reactively.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginnen Sie mit den Leitfäden zu Prompt API und GenAI API. Überprüfen Sie anschließend das im Issue beschriebene Verhalten von generateContent() und checkStatus() sowie die Referenz zu ErrorCode.BACKGROUND_USE_BLOCKED. Bestätigen Sie das nur im Vordergrund mögliche Inferenzverhalten mithilfe der Instrumentierung oder der WorkManager-Reproduktion und dokumentieren Sie die Einschränkung, die Fehlerbehandlung und alle Hinweise zu unterstützten Funktionen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, kotlin
Bereich
documentation, mobile
Issue-Typ
Dokumentation
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.