ModelDownloads

Starts, tracks and cancels model downloads. Each ModelPack is asked for on its own; a single transfer works through the queue (AiState.modelQueue) one pack after another. The transfer runs in a user-initiated data transfer job on Android 14+ (exempt from job quotas, survives leaving the app), and in a WorkManager foreground worker on Android 11–13. Both call run.

Properties

Link copied to clipboard
val state: StateFlow<DownloadState>

Functions

Link copied to clipboard
fun bytes(context: Context, pack: ModelPack): Long

Download size of pack (Search: the chosen tier).

Link copied to clipboard
fun cancel(context: Context)

Stops every download; parts stay on disk to resume from.

fun cancel(context: Context, pack: ModelPack, wifiOnly: Boolean)

Takes pack out of the queue. If it was downloading, the transfer restarts for the rest (Lumen is on screen: the only time this is called).

Link copied to clipboard
fun complete(context: Context, pack: ModelPack): Boolean

Every file of this version of pack is in place (Search: the chosen tier).

Link copied to clipboard
fun delete(context: Context, pack: ModelPack, wifiOnly: Boolean)

Removes pack's files, half-downloaded parts and what was found with them.

Link copied to clipboard
fun first(context: Context): Triple<ModelPack, Long, Long>?

What the transfer's notification starts with: the first queued pack, and its progress.

Link copied to clipboard
fun installed(context: Context): AiModel?

The search tier whose files are on the phone, if any (normally at most one).

Link copied to clipboard
fun model(context: Context): AiModel

The tier chosen in Settings: the one downloads fetch.

Link copied to clipboard
fun paused()

Android paused the job (network lost, heat); it reruns and resumes by itself.

Link copied to clipboard
fun queue(context: Context): List<ModelPack>

Packs asked for and not finished, in order.

Link copied to clipboard
fun remainingBytes(context: Context, pack: ModelPack): Long

Bytes still to fetch for pack, counting partial files already on disk.

Link copied to clipboard
suspend fun run(context: Context, onProgress: (pack: ModelPack, done: Long, total: Long) -> Unit): Boolean?

Downloads the queue, one pack at a time, each taken off once complete. Returns null when done, else whether to retry later (false: a pack failed for good, the rest were fetched). Cancellation propagates, leaving .part files to resume from.

Link copied to clipboard
fun start(context: Context, pack: ModelPack, wifiOnly: Boolean)

Adds pack to the queue and starts the transfer if it isn't going already. Must be called while Lumen is on screen: Android only accepts user-initiated jobs then.

Link copied to clipboard
fun usable(context: Context, pack: ModelPack): Boolean

pack works: its feature can be used, maybe with an older version of its files.