Skip to content

feat(models): Add Custom URL & Local Path Fulfillment for Allowlist Models#598

Open
Mazafard wants to merge 1 commit intogoogle-ai-edge:mainfrom
Mazafard:feature/model-fulfillment-overrides
Open

feat(models): Add Custom URL & Local Path Fulfillment for Allowlist Models#598
Mazafard wants to merge 1 commit intogoogle-ai-edge:mainfrom
Mazafard:feature/model-fulfillment-overrides

Conversation

@Mazafard
Copy link
Copy Markdown

@Mazafard Mazafard commented Apr 6, 2026

Closes #576

Description

This PR introduces a flexible override mechanism to the existing model downloading framework. It allows users to bypass the default Hugging Face download link and supply their own custom URL or local device path to fulfill any pre-defined model_allowlist.json model mapping natively.

This enables seamless integration for users operating in air-gapped environments, heavily constrained networks, or local testing scenarios, specifically optimizing the developer experience without requiring a hardcoded manifest edit or creating new unstructured "global" import objects.

Implementation Details

  • UI Hook: Dynamically rendered a new [Icon] Import Custom button strictly visible if the model download status evaluates to NOT_DOWNLOADED. This safely accompanies the existing download component directly on the model's panel.
  • Component Architecture: Introduced an encapsulated Compose ModelFulfillmentDialog inside the DownloadModelPanel logic. It uses modern state-hoisting and standard Android ActivityResultContracts.OpenDocument() for picking internal device files efficiently.
  • ViewModel & Repository Bypass: Altered DownloadRepository.kt to securely propagate the customUrl payload override, preserving the worker execution context while explicitly sidestepping the default URL.
  • Local I/O Fulfillment: Created fulfillModelWithLocalUri using Dispatchers.IO to read standard ContentResolver streams and seamlessly flush bytes directly into the prescribed storage partitions.

Security & Validation

This implementation enforces rigid validation rules ensuring structural integrity isn't broken. If a model expects to be compiled as model.task, it cannot be fulfilled via a stray .bin or mismatched target.

  • URL Parsing Heuristics: Employs precise .lastPathSegment extraction directly from Android's Uri.parse() library instead of manual string truncation. This implicitly drops noisy tracking markers (?download=true, #anchor) ensuring validation fires strictly on physical path nomenclature.
  • Local Path Assertions: Validates OS-provided OpenableColumns.DISPLAY_NAME against the literal allowlist properties before triggering File streams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support downloading models from custom local or web URLs

2 participants