Modern Apps git

← Modern-Apps.git

library: remove network-to-image edge via Builder.remote hook (#884)

Commit
07388aa7af9ab76ac808f95ed035462cc4d3aee4
Author
Vayun Mathur <[email protected]>
When
2026-10-31 19:04 UTC (1 month ago)
Parents
e5bb1aa
The previous pass moved HTTP image fetching out of :library:image (which
lost its INTERNET permission, unblocking the pdf offline claim) but parked
the replacement HttpImageFetcher in :library:network with a
:library:network -> :library:image edge. A library depending on another
library is exactly what issue #884 forbids, and the guard allowlist cannot
bless it: network declares ACCESS_NETWORK_STATE, so any consumer of network
transitively inherits image's API surface and vice versa.

Root cause: ImageLoader.Builder baked every fetcher into its defaults, so
the only way to share the HTTP transport was a module edge. The fix is
inversion: :library:image gains a Builder.remote(fetch) hook taking a
suspend (Any?, Context) -> FetchResult? lambda, wrapped as the first
fetcher in the chain (null falls through to the local fetchers). Each
networked app that shows remote artwork (appstore iconUrl, web thumbnails
+ PWA icons, uniflix catalog, travel stays, shop products, taxi driver
photos, youpipe thumbnails, fooddelivery merchants) now owns a 40-line
RemoteImageFetchers object built from NetworkClient with its own
TrustBundle, and registers it via ImageLoader.setDefault (widened from
internal to public) next to its NetworkClient.init call. The HTTP
transport thus lives in the app, with no project edge either way.

Offline apps (pdf, music, notes, files, flashcards, photos, openassistant)
keep the local-only default: remote URLs resolve to Unable to fetch data
instead of silently hitting the network, and gain no permission.

Also fixes a compile break the move left behind: ConnectivityCompose's
OfflineWarningGlyph read MaterialTheme inside a Canvas DrawScope, which
is not a @Composable context; the color is now hoisted.

User-visible effect: remote artwork loads again in the eight wired apps
(it silently stopped when HttpFetcher left the defaults); offline apps
are unchanged.

Verification: :library:image + :library:network compileDebugKotlin green;
:appstore excluded (unrelated concurrent appstore-agent breakage in
UpdateLists.kt); :web :uniflix :travel :shop :taxi :youpipe
:fooddelivery compileDevKotlin green in one invocation.

Diff

AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 0243a1b561..657f9380f8 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -29,11 +29,11 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. | :--- | :--- | :--- | | base | `library/` | nav keys, `AssistantIntent`, IPC DTOs (`library.intents.<app>`), `RoomRepository` base | | ui | `library/ui/` | `Icons.kt` (ONLY `Icon()`/`painterResource()` allowed), `AppScaffold` family, `DynamicTheme`, messenger/`AppMessages`, motion helpers |-| network | `library/network/` | `NetworkClient`, pinned CAs in `assets/ca/`, `TrustBundle` (FIRST_PARTY/STANDARD/EXTENDED/SYSTEM/ESIM) |+| network | `library/network/` | `NetworkClient`, pinned CAs in `assets/ca/`, `TrustBundle` (FIRST_PARTY/STANDARD/EXTENDED/SYSTEM/ESIM), `OfflineAware` banner | | room | `library/room/` | Room 3 + SQLCipher (`implementRoom(libs)`) | | map / ml / ocr | `library/map/`, `library/ml/`, `library/ocr/` | vector maps (INTERNET itself) / inference / OCR |-| image/media | `library/image/`, `library/media/` | image loading / AV playback |-| e2ee-p2p | `library/e2ee-p2p/` | E2EE, p2p |+| image/media | `library/image/`, `library/media/` | image loading (offline-local; network apps opt into HTTP via `Builder.remote()` with a `NetworkClient` fetch fn) / AV playback |+| e2ee-p2p | `library/e2ee-p2p/` | E2EE, p2p, `Hkdf` | | widgets/work | `library/widgets/`, `library/work/` | Glance widgets / WorkManager | | biometric/ink | `library/biometric/`, `library/ink/` | biometric / stylus ink | | downloadservice | `library/downloadservice/` | foreground downloads (INTERNET itself) |
appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.ktindex 3f2af26558..c28846b5b2 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt@@ -28,10 +28,12 @@ import com.vayunmathur.appstore.ui.UpdatesPage import com.vayunmathur.appstore.util.AppSection import com.vayunmathur.appstore.util.AppStoreViewModel import com.vayunmathur.appstore.util.AppStoreViewModelFactory+import com.vayunmathur.appstore.util.RemoteImageFetchers import com.vayunmathur.appstore.util.clearSelection import com.vayunmathur.appstore.util.openBrowse import com.vayunmathur.appstore.util.selectApp import com.vayunmathur.appstore.util.selectPackage+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity@@ -65,6 +67,12 @@ class MainActivity : MaActivity() {         // + ISRG X1/X2 (F-Droid) + DigiCert G2/G3 (GitHub). Covers all appstore hosts without full system ~140 roots.         NetworkClient.init(this, TrustBundle.STANDARD)         UpdateCheckWorker.schedule(this)+        // Listing artwork (iconUrl) loads over HTTP(S) through the shared image+        // pipeline; the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )          val repository = AppStoreDatabaseRepository.get(this)         factoryState = AppStoreViewModelFactory(applicationContext, repository.database)
appstore/src/main/java/com/vayunmathur/appstore/util/RemoteImageFetchers.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/RemoteImageFetchers.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/RemoteImageFetchers.ktnew file mode 100644index 0000000000..61106f76d8--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.appstore.util++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: the store declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient` with the `STANDARD` bundle), and registers this on its+ * `ImageLoader` for remote artwork (`iconUrl`). Returns null for non-HTTP data+ * so it composes with the pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..dd567ab6e3--- /dev/null+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.fooddelivery.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: fooddelivery declares INTERNET itself, depends+ * on both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient` with the `STANDARD` bundle), and registers this on its+ * `ImageLoader` for merchant/restaurant photos. Returns null for non-HTTP data+ * so it composes with the pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt
diff --git a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.ktindex 11a5f10676..efdd128750 100644--- a/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt+++ b/fooddelivery/src/main/java/com/vayunmathur/fooddelivery/platform/AppInit.kt@@ -1,6 +1,8 @@ package com.vayunmathur.fooddelivery.platform  import android.content.Context+import com.vayunmathur.fooddelivery.data.RemoteImageFetchers+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.log.Log import androidx.core.content.edit import com.vayunmathur.fooddelivery.api.BitesAuth@@ -36,6 +38,12 @@ object AppInit {     fun start(context: Context) {         if (!started.compareAndSet(false, true)) return         val appCtx = context.applicationContext+        // Merchant photos load over HTTP(S) through the shared image pipeline;+        // the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(appCtx).remote(RemoteImageFetchers::network).build(),+        )         scope.launch {             // Kept in separate try blocks: a trust-bundle failure must not also skip the token             // restore, or one bad DER root would silently sign the user out and — because
library/image/AGENTS.md
diff --git a/library/image/AGENTS.md b/library/image/AGENTS.mdindex ada0beb575..3046006ea8 100644--- a/library/image/AGENTS.md+++ b/library/image/AGENTS.md@@ -6,7 +6,10 @@ - Gradle: :library:image / dir: library/image/ - Package roots present: (image loading pipeline — `image/` + `compose/`/`decoders/`/`fetchers/`/`util/` subpackages) - Entry files: ImageLoader.kt + compose/AsyncImage.kt (no MainActivity/Route — library)-- Deps: :library, :library:network+- Deps: (none — permission-free by design, #884)+- Network: this module loads local data only; network apps opt into HTTP(S) by+  handing `ImageLoader.Builder.remote()` a fetch function they build from+  `NetworkClient` — no library-to-library edge either way - Metadata: metadata_data/library-image.md (absent — libraries have none by design) - Rust: no / screenshotTest: no @@ -32,7 +35,6 @@ - com/vayunmathur/library/image/decoders/SvgDecoder.kt - com/vayunmathur/library/image/decoders/VideoFrameDecoder.kt - com/vayunmathur/library/image/fetchers/Fetcher.kt-- com/vayunmathur/library/image/fetchers/HttpFetcher.kt - com/vayunmathur/library/image/fetchers/AssetFetcher.kt - com/vayunmathur/library/image/fetchers/FileFetcher.kt - com/vayunmathur/library/image/fetchers/ContentResolverFetcher.kt
library/image/build.gradle.kts
diff --git a/library/image/build.gradle.kts b/library/image/build.gradle.ktsindex 41d28d94ea..f19073db06 100644--- a/library/image/build.gradle.kts+++ b/library/image/build.gradle.kts@@ -3,8 +3,11 @@ plugins { }  dependencies {-    implementation(project(":library"))-    implementation(project(":library:network"))+    // Permission-free by design: no project deps. HTTP(S) image fetching is+    // opted into per call site via ImageLoader.Builder.remote(), with the fetch+    // function built from NetworkClient in the consuming app — so this module+    // declares no INTERNET and offline consumers gain no network permission+    // from it (#884).      // Coroutines     implementation(libs.kotlinx.coroutines.android)
library/image/src/main/AndroidManifest.xml
diff --git a/library/image/src/main/AndroidManifest.xml b/library/image/src/main/AndroidManifest.xmlindex 19d2638ebe..3ea2ad3c5d 100644--- a/library/image/src/main/AndroidManifest.xml+++ b/library/image/src/main/AndroidManifest.xml@@ -1,4 +1,7 @@ <?xml version="1.0" encoding="utf-8"?>+<!-- No permissions by design: this module loads local data only. Network apps+     opt into HTTP(S) via ImageLoader.Builder.remote(), so offline apps can+     consume this pipeline without gaining INTERNET. Network apps declare+     INTERNET themselves and pass a NetworkClient-backed fetch function. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android">-    <uses-permission android:name="android.permission.INTERNET" /> </manifest>
library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt
diff --git a/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt b/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.ktindex 8934888db5..b3d8606c90 100644--- a/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt+++ b/library/image/src/main/java/com/vayunmathur/library/image/ImageLoader.kt@@ -11,9 +11,8 @@ import com.vayunmathur.library.image.fetchers.BitmapFetcher import com.vayunmathur.library.image.fetchers.ByteArrayFetcher import com.vayunmathur.library.image.fetchers.ContentResolverFetcher import com.vayunmathur.library.image.fetchers.FetchResult-import com.vayunmathur.library.image.fetchers.FileFetcher import com.vayunmathur.library.image.fetchers.Fetcher-import com.vayunmathur.library.image.fetchers.HttpFetcher+import com.vayunmathur.library.image.fetchers.FileFetcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Deferred@@ -62,7 +61,13 @@ class ImageLoader private constructor(             }         } -        internal fun setDefault(loader: ImageLoader) {+        /**+         * Replaces the process-wide default, e.g. with a loader that has a+         * remote source registered (see [Builder.remote]). Public so network+         * apps can opt into HTTP(S) image loading; offline apps never call it+         * and keep the local-only default (#884).+         */+        fun setDefault(loader: ImageLoader) {             singleton = loader         }     }@@ -351,11 +356,19 @@ class ImageLoader private constructor(         data object PendingBytes : FetchOutcome     } +    /**+     * HTTP(S) is deliberately NOT in the defaults: this module is permission-free+     * and offline apps (pdf, music, notes, …) must gain no network permission+     * from it. Network apps opt in per call site via [remote], handing the+     * loader a fetch function they build from `NetworkClient` — so the HTTP+     * transport lives in the app, not in a library-to-library edge (#884).+     */     class Builder(private val context: Context) {         private var memoryCacheInstance: MemoryCache? = null         private var diskCacheInstance: DiskCache? = null         private var respectCacheHeaders: Boolean = true         private val extraFetchers: MutableList<Fetcher> = mutableListOf()+        private var remoteFetch: (suspend (data: Any?, context: Context) -> FetchResult?)? = null          inner class ComponentsBuilder {             fun add(factory: Any): ComponentsBuilder {@@ -400,6 +413,29 @@ class ImageLoader private constructor(             return this         } +        /**+         * Opt-in remote (HTTP/S) source for network apps.+         *+         * The function runs inside the fetcher chain like any [Fetcher]: return+         * null for data it does not handle so the local fetchers still apply.+         * The app builds it from `NetworkClient` (it already depends on+         * `:library:network` and declares INTERNET itself), e.g.:+         *+         * ```+         * ImageLoader.Builder(context)+         *     .remote { data, _ -> RemoteImageFetchers.network(data) }+         *     .build()+         * ```+         *+         * Without it, remote URLs resolve to "Unable to fetch data" instead of+         * silently hitting the network — which is what keeps offline consumers+         * of this module permission-free (#884).+         */+        fun remote(fetch: suspend (data: Any?, context: Context) -> FetchResult?): Builder {+            remoteFetch = fetch+            return this+        }+         fun build(): ImageLoader {             val mem = memoryCacheInstance ?: MemoryCache.Builder().build()             val disk = diskCacheInstance ?: try {@@ -413,9 +449,19 @@ class ImageLoader private constructor(                 FileFetcher(),                 AssetFetcher(),                 ContentResolverFetcher(),-                HttpFetcher(),             )-            val allFetchers = extraFetchers + defaultFetchers+            val remote = remoteFetch?.let {+                object : Fetcher {+                    override suspend fun fetch(data: Any?, context: Context): FetchResult? =+                        it(data, context)+                }+            }+            // Remote first: a remote fetcher returns null for local data, and a+            // local fetcher never claims an http(s) URL, so order between the two+            // groups does not change what resolves — but trying the explicit+            // opt-in before the defaults keeps a network failure (throw) from+            // being masked by a later fetcher's null.+            val allFetchers = listOfNotNull(remote) + extraFetchers + defaultFetchers              return ImageLoader(                 appContext = context.applicationContext,
library/network/AGENTS.md
diff --git a/library/network/AGENTS.md b/library/network/AGENTS.mdindex ea2a5e680b..cd8b9904e4 100644--- a/library/network/AGENTS.md+++ b/library/network/AGENTS.md@@ -4,9 +4,12 @@  <!-- last-reviewed: 2026-10-16 --> - Gradle: :library:network / dir: library/network/-- Package roots present: network+- Package roots present: network (+ `util` for the connectivity monitor/banner) - Entry files: NetworkClient.kt + TrustBundle.kt (no MainActivity/Route — library)-- Deps: (none — pinned CAs ship in `assets/ca/`)+- Deps: (none — no project dependencies by design, #884)+- Remote images: network apps build their own `Fetcher` from `NetworkClient`+  and hand it to `ImageLoader.Builder.remote()` in `:library:image`; the HTTP+  transport lives in the app, never in a library-to-library edge - Metadata: metadata_data/library-network.md (absent — libraries have none by design) - Rust: no / screenshotTest: no @@ -29,6 +32,7 @@ Relay host: `api.maproj.org`, covered by the `FIRST_PARTY` bundle pins (Cloudfla - com/vayunmathur/library/network/Urls.kt - com/vayunmathur/library/network/WebSocketClient.kt - com/vayunmathur/library/util/ConnectivityMonitor.kt+- com/vayunmathur/library/util/ConnectivityCompose.kt — `OfflineAware` banner (#884)  ## Verify (this module only) ```
library/network/src/main/java/com/vayunmathur/library/util/ConnectivityCompose.kt
diff --git a/library/network/src/main/java/com/vayunmathur/library/util/ConnectivityCompose.kt b/library/network/src/main/java/com/vayunmathur/library/util/ConnectivityCompose.ktnew file mode 100644index 0000000000..ffd222fedf--- /dev/null+++ b/library/network/src/main/java/com/vayunmathur/library/util/ConnectivityCompose.kt@@ -0,0 +1,128 @@+package com.vayunmathur.library.util++import androidx.compose.foundation.Canvas+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.statusBarsPadding+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.State+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.Size+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.Path+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.unit.dp++/**+ * Live "are we online?" state for Compose. Starts [ConnectivityMonitor] on first use.+ *+ * Requires `<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>`.+ */+@Composable+fun rememberIsOnline(): State<Boolean> {+    val context = LocalContext.current+    remember(context) { ConnectivityMonitor.start(context); true }+    return ConnectivityMonitor.isOnline.collectAsState()+}++/**+ * Drop-in banner shown while offline. Adopting an offline indicator is then ~2 lines:+ * `val online by rememberIsOnline(); OfflineBanner(online)`.+ *+ * The warning glyph is drawn with Canvas (not `Icon()`) so this file can live+ * in `:library:network` next to [ConnectivityMonitor] instead of dragging a+ * `:library:network` dependency (and its `ACCESS_NETWORK_STATE`) into+ * `:library:ui`, which every app consumes (#884). Icons stay centralized in+ * `:library:ui` `Icons.kt`; this one glyph is the documented exception.+ */+@Composable+fun OfflineBanner(online: Boolean, modifier: Modifier = Modifier) {+    if (online) return+    Row(+        modifier = modifier+            .fillMaxWidth()+            .background(MaterialTheme.colorScheme.errorContainer)+            .padding(horizontal = 16.dp, vertical = 8.dp),+        horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally),+        verticalAlignment = Alignment.CenterVertically,+    ) {+        OfflineWarningGlyph(tint = MaterialTheme.colorScheme.onErrorContainer)+        Text(+            text = "No internet connection",+            color = MaterialTheme.colorScheme.onErrorContainer,+            style = MaterialTheme.typography.bodyMedium,+        )+    }+}++/**+ * Wraps a screen so a full-width offline banner slides in above it whenever validated internet is+ * lost, and the wrapped content fills the rest. Adopting the offline indicator in an app is then a+ * one-line wrap around the existing top-level navigation:+ *+ * ```+ * DynamicTheme {+ *     OfflineAware {+ *         Navigation(viewModel)+ *     }+ * }+ * ```+ *+ * The banner carries [statusBarsPadding] so it clears the status bar under edge-to-edge; the content+ * keeps drawing edge-to-edge and manages its own insets exactly as before.+ */+@Composable+fun OfflineAware(content: @Composable () -> Unit) {+    val online by rememberIsOnline()+    Column(Modifier.fillMaxSize()) {+        OfflineBanner(online, Modifier.statusBarsPadding())+        Box(Modifier.weight(1f).fillMaxWidth()) { content() }+    }+}++/** Warning triangle with an exclamation bar, drawn to match the `IconWarning` look. */+@Composable+private fun OfflineWarningGlyph(+    tint: Color,+    modifier: Modifier = Modifier,+) {+    val barColor = MaterialTheme.colorScheme.errorContainer+    Canvas(modifier = modifier.size(20.dp)) {+        val w = size.width+        val h = size.height+        val triangle = Path().apply {+            moveTo(w / 2f, h * 0.08f)+            lineTo(w * 0.94f, h * 0.88f)+            lineTo(w * 0.06f, h * 0.88f)+            close()+        }+        drawPath(triangle, tint)+        val barTop = h * 0.34f+        val barBottom = h * 0.62f+        val barHalfWidth = w * 0.035f+        drawRect(+            color = barColor,+            topLeft = Offset(w / 2f - barHalfWidth, barTop),+            size = Size(barHalfWidth * 2f, barBottom - barTop),+        )+        drawCircle(+            color = barColor,+            radius = barHalfWidth,+            center = Offset(w / 2f, h * 0.72f),+        )+    }+}
shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt b/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..37848cbd8c--- /dev/null+++ b/shop/src/main/java/com/vayunmathur/shop/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.shop.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: shop declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient`), and registers this on its `ImageLoader` for product+ * photos. Returns null for non-HTTP data so it composes with the pipeline's+ * local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt b/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.ktindex 062a3bef85..cef245c87e 100644--- a/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt+++ b/shop/src/main/java/com/vayunmathur/shop/platform/AppInit.kt@@ -1,9 +1,11 @@ package com.vayunmathur.shop.platform  import android.content.Context+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.log.Log import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle+import com.vayunmathur.shop.data.RemoteImageFetchers import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -29,6 +31,12 @@ object AppInit {     fun start(context: Context) {         if (!started.compareAndSet(false, true)) return         val appCtx = context.applicationContext+        // Product photos load over HTTP(S) through the shared image pipeline;+        // the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(appCtx).remote(RemoteImageFetchers::network).build(),+        )         scope.launch {             try {                 // Shopify endpoints (myshopify.com, catalog.shopify.com, cdn.shopify.com)
taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt b/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.ktindex 5d184f11df..4f7866ff5f 100644--- a/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt+++ b/taxi/src/main/java/com/vayunmathur/taxi/MainActivity.kt@@ -8,11 +8,13 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.core.content.ContextCompat+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.IntentLauncher import com.vayunmathur.taxi.data.BookingTrip+import com.vayunmathur.taxi.data.RemoteImageFetchers import com.vayunmathur.taxi.ipc.RideHandoffContract import com.vayunmathur.taxi.notifications.RideLiveUpdate @@ -38,6 +40,12 @@ class MainActivity : MaActivity() {      override fun onCreateBeforeContent() {         NetworkClient.init(this, TrustBundle.STANDARD)+        // Driver photos load over HTTP(S) through the shared image pipeline;+        // the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )         intentLauncher = IntentLauncher(this)          trackRideId.value = intent.trackRideIdOrNull()
taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt
diff --git a/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt b/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..ebb6e7df82--- /dev/null+++ b/taxi/src/main/java/com/vayunmathur/taxi/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.taxi.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: taxi declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient` with the `STANDARD` bundle), and registers this on its+ * `ImageLoader` for driver photos. Returns null for non-HTTP data so it+ * composes with the pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
travel/src/main/java/com/vayunmathur/travel/MainActivity.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt b/travel/src/main/java/com/vayunmathur/travel/MainActivity.ktindex 42ab612d60..0767f6144b 100644--- a/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt+++ b/travel/src/main/java/com/vayunmathur/travel/MainActivity.kt@@ -39,6 +39,7 @@ import com.vayunmathur.travel.ui.StayDetailPage import com.vayunmathur.travel.ui.StayGuestsPage import com.vayunmathur.travel.ui.StayResultsPage import com.vayunmathur.travel.ui.TripsPage+import com.vayunmathur.travel.data.RemoteImageFetchers import com.vayunmathur.travel.util.TravelViewModel import com.vayunmathur.travel.util.TravelViewModelFactory import com.vayunmathur.travel.util.pendingTripIds@@ -46,6 +47,7 @@ import com.vayunmathur.travel.util.pollTrip import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import kotlinx.serialization.Serializable@@ -62,6 +64,12 @@ class MainActivity : MaActivity() {         // Hardened trust: api.maproj.org + data.maproj.org are Cloudflare         // fronted, covered by ISRG X1/X2 + GTS R1-R4 in FIRST_PARTY bundle.         NetworkClient.init(this, TrustBundle.FIRST_PARTY)+        // Destination and stay photos load over HTTP(S) through the shared image+        // pipeline; the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )          lifecycleScope.launch(Dispatchers.IO) {             repository = TravelRepository.get(this@MainActivity)
travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt
diff --git a/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt b/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..0f8ffa3cb3--- /dev/null+++ b/travel/src/main/java/com/vayunmathur/travel/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.travel.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: travel declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient`), and registers this on its `ImageLoader` for destination+ * and stay photos. Returns null for non-HTTP data so it composes with the+ * pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.ktindex 210037a800..014df97564 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/MainActivity.kt@@ -1,15 +1,23 @@ package com.vayunmathur.uniflix  import androidx.compose.runtime.Composable+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity+import com.vayunmathur.uniflix.data.RemoteImageFetchers  class MainActivity : MaActivity() {     override fun onCreateBeforeContent() {         // Catalog + artwork go through the self-hosted proxy; player streams         // user-supplied addon URLs, so trust stays at STANDARD, never SYSTEM.         NetworkClient.init(this, TrustBundle.STANDARD)+        // Catalog artwork loads over HTTP(S) through the shared image pipeline;+        // the fetch function is built here from NetworkClient so no+        // library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )     }      @Composable
uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..4ed749d8af--- /dev/null+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.uniflix.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: uniflix declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient` with the `STANDARD` bundle), and registers this on its+ * `ImageLoader` for catalog/stremio artwork. Returns null for non-HTTP data+ * so it composes with the pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
web/src/main/java/com/vayunmathur/web/MainActivity.kt
diff --git a/web/src/main/java/com/vayunmathur/web/MainActivity.kt b/web/src/main/java/com/vayunmathur/web/MainActivity.ktindex dceff71d62..f6ae15a149 100644--- a/web/src/main/java/com/vayunmathur/web/MainActivity.kt+++ b/web/src/main/java/com/vayunmathur/web/MainActivity.kt@@ -12,11 +12,13 @@ import androidx.compose.ui.Modifier import androidx.lifecycle.lifecycleScope import androidx.lifecycle.viewmodel.compose.viewModel import com.vayunmathur.library.log.Log+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.util.OfflineAware import com.vayunmathur.web.data.FaviconStore+import com.vayunmathur.web.data.RemoteImageFetchers import com.vayunmathur.web.data.TabThumbnailStore import com.vayunmathur.web.data.WebRepository import com.vayunmathur.web.platform.BrowserTab@@ -39,6 +41,12 @@ class MainActivity : MaActivity() {     override fun onCreateBeforeContent() {         // SYSTEM permissive browser: any host + user CAs for MITM debug/corp proxies (per user exception)         NetworkClient.init(this, TrustBundle.SYSTEM)+        // Search-result thumbnails and PWA icons load over HTTP(S) through the+        // shared image pipeline; the fetch function is built here from+        // NetworkClient so no library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )         // Parses ~8 MB of filter lists off the main thread. Shields fail open until it lands.         lifecycleScope.launch { ShieldsEngine.load(applicationContext) }         // Before any WebView exists: service-worker fetches bypass the WebViewClient entirely.
web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt
diff --git a/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt b/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..0d32d53b30--- /dev/null+++ b/web/src/main/java/com/vayunmathur/web/data/RemoteImageFetchers.kt@@ -0,0 +1,40 @@+package com.vayunmathur.web.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: the browser declares INTERNET itself, depends+ * on both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient` with the `SYSTEM` bundle for user-entered hosts), and+ * registers this on its `ImageLoader` for search-result thumbnails and PWA+ * icon fetches. Returns null for non-HTTP data so it composes with the+ * pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}
youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.ktindex 2ef052c3b3..59cd66cc2f 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/YouPipeApplication.kt@@ -1,10 +1,12 @@ package com.vayunmathur.youpipe  import android.app.Application+import com.vayunmathur.library.image.ImageLoader import com.vayunmathur.library.log.Log import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.youpipe.data.RemoteImageFetchers import com.vayunmathur.youpipe.util.MyDownloader import com.vayunmathur.youpipe.util.sabr.LocalDomPoTokenProvider import com.vayunmathur.youpipe.util.youtubeLocalization@@ -22,6 +24,12 @@ class YouPipeApplication : Application() {         Log.init(BuildConfig.DEV_BUILD)         // Reduced CA set: FIRST_PARTY = ISRG X1/X2 + GTS R1-R4 covers api.maproj.org + YouTube (GTS)         NetworkClient.init(this, TrustBundle.FIRST_PARTY)+        // Video thumbnails and channel avatars load over HTTP(S) through the+        // shared image pipeline; the fetch function is built here from+        // NetworkClient so no library-to-library edge is needed (#884).+        ImageLoader.setDefault(+            ImageLoader.Builder(this).remote(RemoteImageFetchers::network).build(),+        )         appContext = applicationContext         val language = DataStoreUtils.getInstance(this).getString("youtube_language").orEmpty()         NewPipe.init(MyDownloader(), youtubeLocalization(language))
youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.ktnew file mode 100644index 0000000000..07cfd0d6c1--- /dev/null+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/data/RemoteImageFetchers.kt@@ -0,0 +1,39 @@+package com.vayunmathur.youpipe.data++import android.content.Context+import android.net.Uri+import com.vayunmathur.library.image.fetchers.FetchResult+import com.vayunmathur.library.network.NetworkClient+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext++/**+ * HTTP(S) source for the shared `:library:image` pipeline, owned by this app.+ *+ * Lives here rather than in a library so no library-to-library edge (and no+ * leaked permission) is needed: youpipe declares INTERNET itself, depends on+ * both `:library:image` (the `Fetcher` SPI) and `:library:network`+ * (`NetworkClient`), and registers this on its `ImageLoader` for video+ * thumbnails and channel avatars. Returns null for non-HTTP data so it+ * composes with the pipeline's local fetchers (#884).+ */+object RemoteImageFetchers {+    suspend fun network(data: Any?, @Suppress("UNUSED_PARAMETER") context: Context): FetchResult? {+        val url: String = when (data) {+            is String -> data+            is Uri -> {+                val s = data.scheme+                if (s == "http" || s == "https") data.toString() else return null+            }+            else -> return null+        }+        if (!url.startsWith("http://") && !url.startsWith("https://")) return null+        return withContext(Dispatchers.IO) {+            val resp = NetworkClient.execute(url)+            if (!resp.isSuccess) {+                throw java.io.IOException("HTTP ${resp.status} for $url")+            }+            FetchResult.Bytes(resp.bytes)+        }+    }+}