shouldConfigureForegroundNotification function
Whether _ensureConfigured should register a running TaskNotification
for the given foreground setting (#356). Extracted as a pure function so
the decision is unit-testable without a FileDownloader seam: on Android,
background_downloader only calls WorkManager.setForeground() — the
thing that actually activates the foreground service — when a running
notification is configured. Setting Config.runInForeground alone is a
no-op without it.
Scoped to the EXPLICIT foreground: true flag only (#357 review). The
notification, once configured, is global: background_downloader's
Notifications.kt shows it for every task in the running state,
including ones that are NOT running in foreground
(displayNotification's else branch calls notify() unconditionally
when runInForeground is false for that task). Returning true for the
auto-detect branch (foreground == null) would therefore show a
"Downloading model" notification on EVERY download — including small
ones, where none showed before.
The consequence is that the auto-detect branch has NO foreground service at
all: canRunInForeground requires both a size threshold AND a running
notification, so declining the notification declines the service with it.
The size threshold on its own does nothing, and has not since #357 — the
docs that promised otherwise were wrong. foreground: true is the only way
to get one.
Implementation
@visibleForTesting
bool shouldConfigureForegroundNotification(bool? foreground) =>
foreground == true;