kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Android app: expedited tasks fail on Android 11 and below, so channel import never starts

Open rtibblesbot opened this issue 4 weeks ago • 3 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: release-v0.20.x

Observed behavior

  • On Android 11 (API 30), Device > Channels > IMPORT > Kolibri Studio (online) > CONTINUE > SELECT RESOURCES stays on "Generating channel listing. This could take a few minutes" indefinitely, including after a force-stop and relaunch.
  • Every expedited task that is not longRunning fails as soon as WorkManager starts it. This includes kolibri.core.content.tasks.remotechannelimport and the startup jobs kolibri:job:1000 and kolibri:job:1001.
  • Task.java L50-71 calls setExpedited on BackgroundWorker, and BackgroundWorker does not override getForegroundInfo(). On API < 31, WorkManager runs expedited work as a foreground service and calls that method.

Errors and logs

D Kolibri.Task: Enqueued unique task d974e6ab89bb483e823eafcea39ba9dd (func=kolibri.core.content.tasks.remotechannelimport, delay=0.0s, expedite=true, longRunning=false)
E WM-WorkerWrapper: Work [ id=8c4dd841-..., tags={ kolibri:job:d974e6ab89bb483e823eafcea39ba9dd,org.learningequality.Kolibri.workers.BackgroundWorker } ] failed because it threw an exception/error
E WM-WorkerWrapper: java.lang.IllegalStateException: Expedited WorkRequests require a Worker to provide an implementation for `getForegroundInfo()`
E WM-WorkerWrapper: 	at androidx.work.Worker.getForegroundInfo(Worker.kt:86)

User-facing consequences

  • Admins on Android 7–11 devices (minSdk is 24) cannot import channels from Studio or a peer Kolibri server (both run remotechannelimport), so learners have no content.

Steps to reproduce

  1. Install the Android app on an API 30 emulator and complete setup.
  2. Open Device > Channels > IMPORT, choose Kolibri Studio (online), tap CONTINUE.
  3. Tap SELECT RESOURCES on any channel.
  4. Run adb logcat | grep WM-WorkerWrapper.

Context

  • Kolibri 0.20.0a2.dev1733+g730552a93, Android app debug build, androidx.work:work-runtime:2.11.0.
  • Emulator: Android 11 (API 30), x86_64.

Acceptance Criteria

  • [ ] On API 30, SELECT RESOURCES on a Studio channel finishes generating the listing and shows the channel's topics.
  • [ ] On API 30, importing a channel from Studio completes, and its resources open in Learn.
  • [ ] logcat on API 30 shows no Expedited WorkRequests require a Worker to provide an implementation error for any Kolibri task, startup jobs included.
  • [ ] Expedited tasks still run expedited on API 31+.
  • [ ] A test fails without the fix on API < 31.

AI usage

Claude Code found this during manual QA of the Android API 36 branch on an API 30 emulator, read the logcat, traced the failure to Task.java/BackgroundWorker, and drafted this issue.

rtibblesbot avatar Nov 05 '26 07:11 rtibblesbot

Cause: regression from the Chaquopy migration.

  • Before: the p4a Builder.getWorkerClass() sent longRunning || expedite tasks to ForegroundWorker, which implements getForegroundInfo().
  • After: Task.java picks the worker from longRunning alone, so expedited short tasks land on BackgroundWorker.
  • API 31+ runs expedited work as JobScheduler expedited jobs and never calls getForegroundInfo(), so only API 24–30 breaks.
  • work-runtime was 2.11.0 before and after.

Fix: restore longRunning || expedite in the worker class selection in Task.java.

rtibbles avatar Nov 05 '26 14:11 rtibbles

Plan: Expedited Kolibri tasks run on API 24–30 instead of failing with Expedited WorkRequests require a Worker to provide an implementation for getForegroundInfo().

  • [ ] Select ForegroundWorker for expedited tasks, with a regression test
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • expedite=true with delay>0 still routes to ForegroundWorker (p4a parity); if that is wrong, delayed high-priority tasks show a needless notification and the rule should be longRunning || (expedite && delay <= 0).
  • Test reaches the request via a new package-private Task.buildWorkRequest; if refactoring enqueueOnce is unwanted, the test must mock RemoteWorkManager to capture the request.
  • Adds test-only dep androidx.work:work-testing:2.11.0 on a release branch; if unwanted, the test asserts the WorkSpec's worker class name instead of getForegroundInfoAsync().
  • API 30 channel-import ACs are verified by human QA on the CI-built APK; if an agent must show them, it needs an emulator the sandbox can't provide.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 05 '26 14:11 rtibblesbot

Fixed in #15766

rtibbles avatar Nov 06 '26 02:11 rtibbles