nav: routes carry IDs, not whole payloads
- Commit
201862c460d50aab158b1d0631de23c3e441f2a1- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-20 22:35 UTC (15 days ago)
- Parents
0cb400c
Photos viewer entries carried a whole List<Photo> snapshot per back-stack entry (unbounded, stale on delete/favourite). Route.PhotoPage now carries (id, sourceKey) and the viewer re-derives its paging list from the originating flow (gallery/ search/favourites/album/person/map cluster, order preserved), falling back to the full gallery if the origin is gone. PhotoPage's bypass of pushPhoto is fixed here too. VPN import read any VIEW URI unboundedly into memory: it now rejects non-content/file schemes and caps reads at 1MB through the existing import-failed path. uniflix's PlayerSettings route was registered but unreachable and the screen held no settings - removed. Calculator's duplicate Calculator/Graph/ Units registrations are hoisted into one shared entries block. Email's share-intent composer now creates a draft first and routes by draftId (large shared text no longer sits in the back stack); that half landed with the previous commit's email sweep. Verified: photos and email suites pass (two photos flakes pass in isolation), vpn/uniflix/calculator compile.
Diff
calculator/src/main/java/com/vayunmathur/calculator/Navigation.kt
diff --git a/calculator/src/main/java/com/vayunmathur/calculator/Navigation.kt b/calculator/src/main/java/com/vayunmathur/calculator/Navigation.ktindex 7ca9cdb452..226e9eb527 100644--- a/calculator/src/main/java/com/vayunmathur/calculator/Navigation.kt+++ b/calculator/src/main/java/com/vayunmathur/calculator/Navigation.kt@@ -20,11 +20,19 @@ import com.vayunmathur.library.ui.isCompactHeight import com.vayunmathur.library.ui.isExpandedWidth import com.vayunmathur.library.util.BottomBarItem import com.vayunmathur.library.util.BottomNavBar+import com.vayunmathur.library.util.EntryProviderScope import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.library.util.rememberNavBackStack import androidx.compose.ui.Modifier +/** The three tab destinations, registered once and shared by both layout branches below. */+private fun EntryProviderScope<Route>.calculatorEntries(viewModel: CalculatorViewModel) {+ entry<Route.Calculator>(metadata = SiblingPage()) { CalculatorPage(viewModel) }+ entry<Route.Graph>(metadata = SiblingPage()) { GraphPage(viewModel) }+ entry<Route.Units>(metadata = SiblingPage()) { UnitConverterPage(viewModel) }+}+ @Composable fun Navigation(viewModel: CalculatorViewModel, unitsRequest: Int = 0) { val backStack = rememberNavBackStack<Route>(if (unitsRequest > 0) Route.Units else Route.Calculator)@@ -55,21 +63,13 @@ fun Navigation(viewModel: CalculatorViewModel, unitsRequest: Int = 0) { } } Box(Modifier.weight(1f).fillMaxHeight()) {- MainNavigation(backStack) {- entry<Route.Calculator>(metadata = SiblingPage()) { CalculatorPage(viewModel) }- entry<Route.Graph>(metadata = SiblingPage()) { GraphPage(viewModel) }- entry<Route.Units>(metadata = SiblingPage()) { UnitConverterPage(viewModel) }- }+ MainNavigation(backStack) { calculatorEntries(viewModel) } } } } else { MainNavigation( backStack, bottomBar = { BottomNavBar(backStack, tabs, current) },- ) {- entry<Route.Calculator>(metadata = SiblingPage()) { CalculatorPage(viewModel) }- entry<Route.Graph>(metadata = SiblingPage()) { GraphPage(viewModel) }- entry<Route.Units>(metadata = SiblingPage()) { UnitConverterPage(viewModel) }- }+ ) { calculatorEntries(viewModel) } } }
photos/src/main/java/com/vayunmathur/photos/Navigation.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/Navigation.kt b/photos/src/main/java/com/vayunmathur/photos/Navigation.ktindex d6111f5356..14143fbfc4 100644--- a/photos/src/main/java/com/vayunmathur/photos/Navigation.kt+++ b/photos/src/main/java/com/vayunmathur/photos/Navigation.kt@@ -91,7 +91,7 @@ fun Navigation( } entry<Route.PhotoPage>(metadata = ListDetailPage() + MorphPage()) {- PhotoPage(galleryViewModel, photoMapViewModel, it.id, it.overridePhotosList, it.pendingUri, backStack)+ PhotoPage(galleryViewModel, photoMapViewModel, it.id, it.sourceKey, it.pendingUri, backStack) } entry<Route.Wallpaper>(metadata = ListDetailPage()) {
photos/src/main/java/com/vayunmathur/photos/Route.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/Route.kt b/photos/src/main/java/com/vayunmathur/photos/Route.ktindex ee7bf324cc..bdc28ca48c 100644--- a/photos/src/main/java/com/vayunmathur/photos/Route.kt+++ b/photos/src/main/java/com/vayunmathur/photos/Route.kt@@ -1,9 +1,41 @@ package com.vayunmathur.photos import com.vayunmathur.library.util.NavKey-import com.vayunmathur.photos.data.Photo import kotlinx.serialization.Serializable +/**+ * Identifies the list a viewer was opened from, so [Route.PhotoPage] can+ * re-derive its paging list from the view-model instead of carrying a+ * serialized copy of every [com.vayunmathur.photos.data.Photo] in that list+ * (which was retained in memory and restored stale after process death).+ */+@Serializable+sealed interface PhotoSource {+ /** The full gallery grid (also the ACTION_VIEW viewer, which swipes the library). */+ @Serializable+ data object Gallery : PhotoSource++ /** The current search results in the gallery view-model. */+ @Serializable+ data object Search : PhotoSource++ /** The favorites collection. */+ @Serializable+ data object Favorites : PhotoSource++ /** One album, identified by name (the key the albums flow groups by). */+ @Serializable+ data class Album(val albumName: String) : PhotoSource++ /** One person cluster, identified by cluster id. */+ @Serializable+ data class Person(val clusterId: Long) : PhotoSource++ /** One map cluster, identified by its cover photo id in the map view-model. */+ @Serializable+ data class MapCluster(val coverPhotoId: Long) : PhotoSource+}+ /** Contract for route. */ @Serializable sealed interface Route: NavKey {@@ -11,9 +43,9 @@ sealed interface Route: NavKey { @Serializable data object Gallery: Route - /** Immutable value describing photo page; carries id, overridePhotosList, pendingUri. */+ /** Viewer for [id]; [sourceKey] re-derives the swiping list, [pendingUri] is an unindexed ACTION_VIEW uri. */ @Serializable- data class PhotoPage(val id: Long, val overridePhotosList: List<Photo>?, val pendingUri: String? = null): Route+ data class PhotoPage(val id: Long, val sourceKey: PhotoSource?, val pendingUri: String? = null): Route /** Singleton holding map state and operations. */ @Serializable
photos/src/main/java/com/vayunmathur/photos/platform/NavigationHelpers.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/platform/NavigationHelpers.kt b/photos/src/main/java/com/vayunmathur/photos/platform/NavigationHelpers.ktindex 1ad57aaf6f..b2f6118b72 100644--- a/photos/src/main/java/com/vayunmathur/photos/platform/NavigationHelpers.kt+++ b/photos/src/main/java/com/vayunmathur/photos/platform/NavigationHelpers.kt@@ -33,7 +33,7 @@ internal fun viewerRouteFor(viewUri: Uri?): Route.PhotoPage? { viewUri ?: return null return Route.PhotoPage( runCatching { ContentUris.parseId(viewUri) }.getOrNull() ?: -1L,- null,+ com.vayunmathur.photos.PhotoSource.Gallery, viewUri.toString(), ) }
photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.ktindex d0de39093d..4b5c6501b4 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt@@ -187,7 +187,7 @@ fun AlbumDetailScreen( if (isSelectionMode) { onToggleSelection(photo.id) } else {- backStack.pushPhoto(Route.PhotoPage(photo.id, photos))+ backStack.pushPhoto(Route.PhotoPage(photo.id, com.vayunmathur.photos.PhotoSource.Album(albumName))) } }, thumbnail = thumbnail,
photos/src/main/java/com/vayunmathur/photos/ui/FavoritesScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/FavoritesScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/FavoritesScreen.ktindex f233f0e014..a2701a9ddd 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/FavoritesScreen.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/FavoritesScreen.kt@@ -133,7 +133,7 @@ fun FavoritesScreen( if (isSelectionMode) { actions.toggleSelection(photo.id) } else {- backStack.pushPhoto(Route.PhotoPage(photo.id, photos))+ backStack.pushPhoto(Route.PhotoPage(photo.id, com.vayunmathur.photos.PhotoSource.Favorites)) } }, thumbnail = thumbnail,
photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.ktindex fc562fe6c5..1ca7ece6df 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt@@ -215,7 +215,7 @@ fun GalleryScreen( .aspectRatio(1f) .invisibleClickable { searchActive = false- backStack.pushPhoto(Route.PhotoPage(photo.id, state.searchResults))+ backStack.pushPhoto(Route.PhotoPage(photo.id, com.vayunmathur.photos.PhotoSource.Search)) } .sharedContainer("photo-image-${photo.id}") ) {@@ -298,7 +298,7 @@ fun GalleryScreen( if (isSelectionMode) { actions.toggleSelection(photo.id) } else {- backStack.pushPhoto(Route.PhotoPage(photo.id, null))+ backStack.pushPhoto(Route.PhotoPage(photo.id, com.vayunmathur.photos.PhotoSource.Gallery)) } }, thumbnail = thumbnail,
photos/src/main/java/com/vayunmathur/photos/ui/MapPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/MapPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/MapPage.ktindex 290f9af2b8..9e9d63ad03 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/MapPage.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/MapPage.kt@@ -41,6 +41,7 @@ import com.vayunmathur.photos.data.Photo import com.vayunmathur.photos.platform.GalleryViewModel import com.vayunmathur.photos.platform.ImageLoader import com.vayunmathur.photos.platform.PhotoMapViewModel+import com.vayunmathur.photos.platform.pushPhoto import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.conflate@@ -184,7 +185,7 @@ fun MapPage( } items(selectedCluster.allPhotos, key = { it.id }, contentType = { "photo_thumbnail" }) { ImageLoader.PhotoItem(it, Modifier.fillMaxHeight().aspectRatio(1f)) {- backStack.add(Route.PhotoPage(it.id, selectedCluster.allPhotos))+ backStack.pushPhoto(Route.PhotoPage(it.id, com.vayunmathur.photos.PhotoSource.MapCluster(selectedCluster.coverPhoto.id))) } } item {
photos/src/main/java/com/vayunmathur/photos/ui/PeopleScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/PeopleScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/PeopleScreen.ktindex ed782bea2f..9c1bb49e1d 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/PeopleScreen.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/PeopleScreen.kt@@ -105,7 +105,7 @@ fun PeopleScreen( faceThumbnail = faceThumbnail, onNameClick = onNameClick, ) { person ->- backStack.pushPhoto(Route.PhotoPage(person.coverPhoto.id, person.photos))+ backStack.pushPhoto(Route.PhotoPage(person.coverPhoto.id, com.vayunmathur.photos.PhotoSource.Person(person.id))) } } else { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.ktindex 62046f24d0..a3399652aa 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt@@ -34,31 +34,50 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.ZoomState import com.vayunmathur.library.ui.isExpandedWidth import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.PhotoSource import com.vayunmathur.photos.Route import com.vayunmathur.photos.data.Photo+import com.vayunmathur.photos.platform.pushPhoto import com.vayunmathur.photos.platform.GalleryViewModel import com.vayunmathur.photos.platform.LiveWallpaperLauncher import com.vayunmathur.photos.platform.PhotoMapViewModel import kotlinx.coroutines.launch @Composable-fun PhotoPage(galleryViewModel: GalleryViewModel, photoMapViewModel: PhotoMapViewModel, id: Long, overridePhotosList: List<Photo>?, pendingUri: String? = null, backStack: NavBackStack<Route>? = null) {+fun PhotoPage(galleryViewModel: GalleryViewModel, photoMapViewModel: PhotoMapViewModel, id: Long, sourceKey: PhotoSource?, pendingUri: String? = null, backStack: NavBackStack<Route>? = null) { val photosAll by galleryViewModel.photos.collectAsState()+ val searchResults by galleryViewModel.searchResults.collectAsState()+ val favorites by galleryViewModel.favorites.collectAsState()+ val albums by galleryViewModel.albums.collectAsState()+ val people by galleryViewModel.people.collectAsState()+ val mapClusters by photoMapViewModel.generatedClusters.collectAsState() val context = LocalContext.current val coroutineScope = rememberCoroutineScope() // Photos deleted from within this viewer, hidden immediately so the pager // advances to the next photo without waiting for the MediaStore resync. val locallyDeleted = remember { mutableStateListOf<Long>() }- // One remembered pass instead of an unmemoized filter plus a sort plus two- // index scans in the composable body. The sort is gone: the DAO returns rows- // newest-first (ORDER BY date DESC) and every list handed in via- // overridePhotosList is already date-descending.- val photosSorted = remember(photosAll, overridePhotosList, locallyDeleted.toList()) {- val source = overridePhotosList ?: photosAll.filter { !it.isTrashed }+ // Re-derive the paging list from the view-model by [sourceKey] instead of+ // carrying a serialized copy in the route. Each origin flow is already in+ // the order its grid showed (DAO/search/people/albums are date-descending;+ // map clusters are sorted date-descending when generated), so swiping+ // order is preserved. If the origin has evaporated (e.g. after process+ // death the ephemeral search/map state is gone) or no longer contains+ // [id], fall back to the full gallery list so the opened photo still+ // shows instead of blanking the viewer.+ val photosSorted = remember(photosAll, searchResults, favorites, albums, people, mapClusters, sourceKey, id, locallyDeleted.toList()) {+ val derived = when (sourceKey) {+ null, PhotoSource.Gallery -> photosAll.filter { !it.isTrashed }+ PhotoSource.Search -> searchResults+ PhotoSource.Favorites -> favorites+ is PhotoSource.Album -> albums.firstOrNull { it.name == sourceKey.albumName }?.photos.orEmpty()+ is PhotoSource.Person -> people.firstOrNull { it.id == sourceKey.clusterId }?.photos.orEmpty()+ is PhotoSource.MapCluster -> mapClusters.firstOrNull { it.coverPhoto.id == sourceKey.coverPhotoId }?.allPhotos.orEmpty()+ }+ val source = if (derived.any { it.id == id }) derived else photosAll.filter { !it.isTrashed } source.filter { it.id !in locallyDeleted } }- // Favorite state from the live rows: overridePhotosList (an album, person or- // search snapshot) does not see a heart tapped after it was taken.+ // Favorite state from the live rows: a re-derived list (an album, person or+ // search result) does not see a heart tapped after it was taken. val favoriteIds = remember(photosAll) { photosAll.filter { it.isFavorite }.mapTo(HashSet()) { it.id } } val toggleFavorite = rememberFavoriteToggle(galleryViewModel.favoriteToggler) val matchedCounts by galleryViewModel.faceCountByPhoto.collectAsState()@@ -191,7 +210,7 @@ fun PhotoPage(galleryViewModel: GalleryViewModel, photoMapViewModel: PhotoMapVie coroutineScope.launch { val clusterPhotos = galleryViewModel.photosForCluster(clusterId) clusterPhotos.firstOrNull()?.let { first ->- backStack?.add(Route.PhotoPage(first.id, clusterPhotos))+ backStack?.pushPhoto(Route.PhotoPage(first.id, PhotoSource.Person(clusterId))) } } },
photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesUiTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesUiTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesUiTest.ktindex f425a084fa..aaeb9062bc 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesUiTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosFavoritesUiTest.kt@@ -205,7 +205,7 @@ class PhotosFavoritesUiTest { assertTrue(last is Route.PhotoPage) last as Route.PhotoPage assertEquals(b.id, last.id)- assertEquals(listOf(a.id, b.id), last.overridePhotosList?.map { it.id })+ assertEquals(com.vayunmathur.photos.PhotoSource.Favorites, last.sourceKey) } @Test
photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3PagesTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3PagesTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3PagesTest.ktindex dd49a6af3d..3ebf972907 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3PagesTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice3PagesTest.kt@@ -253,7 +253,7 @@ class PhotosSlice3PagesTest { assertTrue(measured != IntSize.Zero || measured == IntSize.Zero) } - // ---- PhotoPage with an override list (no DB rows needed) ----+ // ---- PhotoPage re-deriving its list from the view-model by sourceKey ---- @Test fun photoPagePagerOpensOnOverridePhoto() {@@ -265,18 +265,20 @@ class PhotosSlice3PagesTest { try { val a = photo("pg-a", 100L) val b = photo("pg-b", 200L)+ kotlinx.coroutines.runBlocking { db.photoDao().upsertAll(listOf(b, a)) } composeRule.setContent { PhotoPage( galleryViewModel = gallery, photoMapViewModel = map, id = b.id,- overridePhotosList = listOf(b, a),+ sourceKey = com.vayunmathur.photos.PhotoSource.Gallery, backStack = NavBackStack(arrayOf(Route.Gallery)), ) } // The pager opens on the requested photo: its metadata card // shows the name. (The neighbour page stays composed but // off-screen, so only the current one is displayed.)+ composeRule.waitUntilExactlyOneExists(hasText("pg-b"), 5_000) composeRule.onNodeWithText("pg-b").assertIsDisplayed() } finally { ocrLayoutOverride = null
uniflix/src/main/java/com/vayunmathur/uniflix/Navigation.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/Navigation.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/Navigation.ktindex 35348ef25f..c41e00db38 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/Navigation.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/Navigation.kt@@ -16,7 +16,6 @@ import com.vayunmathur.uniflix.ui.SearchRoute import com.vayunmathur.uniflix.ui.WatchRoute import com.vayunmathur.uniflix.ui.ContinueWatchingScreen import com.vayunmathur.uniflix.ui.ListsScreen-import com.vayunmathur.uniflix.ui.PlayerSettingsScreen @Composable fun Navigation() {@@ -46,9 +45,6 @@ fun Navigation() { }, ) }- entry<Route.PlayerSettings> {- PlayerSettingsScreen(onBack = { backStack.pop() })- } entry<Route.Addons> { val vm: AddonsViewModel = viewModel() AddonsScreen(
uniflix/src/main/java/com/vayunmathur/uniflix/Route.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/Route.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/Route.ktindex 0130cf9604..b7c7142caf 100644--- a/uniflix/src/main/java/com/vayunmathur/uniflix/Route.kt+++ b/uniflix/src/main/java/com/vayunmathur/uniflix/Route.kt@@ -38,10 +38,6 @@ sealed interface Route : NavKey { @Serializable data object ContinueWatching : Route - /** Singleton holding player settings state and operations. */- @Serializable- data object PlayerSettings : Route- /** Singleton holding addons state and operations. */ @Serializable data object Addons : Route
uniflix/src/main/java/com/vayunmathur/uniflix/ui/PlayerSettingsScreen.kt
diff --git a/uniflix/src/main/java/com/vayunmathur/uniflix/ui/PlayerSettingsScreen.kt b/uniflix/src/main/java/com/vayunmathur/uniflix/ui/PlayerSettingsScreen.ktdeleted file mode 100644index b09c57d95d..0000000000--- a/uniflix/src/main/java/com/vayunmathur/uniflix/ui/PlayerSettingsScreen.kt+++ /dev/null@@ -1,34 +0,0 @@-package com.vayunmathur.uniflix.ui--import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.rememberScrollState-import androidx.compose.foundation.verticalScroll-import androidx.compose.runtime.Composable-import androidx.compose.ui.Modifier-import androidx.compose.ui.unit.dp-import com.vayunmathur.library.ui.AppScaffold-import com.vayunmathur.library.ui.DesktopMaxWidthContainer-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text--/** Player preferences shell. Skip-intro stays local-only and off by default. */-@Composable-fun PlayerSettingsScreen(onBack: () -> Unit) {- AppScaffold(- title = "Player",- onNavigateBack = onBack,- ) { padding ->- DesktopMaxWidthContainer(Modifier.padding(padding)) {- Column(- modifier = Modifier.fillMaxWidth().padding(16.dp).verticalScroll(rememberScrollState()),- verticalArrangement = Arrangement.spacedBy(12.dp),- ) {- Text("Playback", style = MaterialTheme.typography.titleMedium)- Text("Streams play through the configured provider. Subtitle tracks come with the resolved source.")- }- }- }-}
uniflix/src/test/java/com/vayunmathur/uniflix/data/AddonStreamProviderOfflineTest.kt
diff --git a/uniflix/src/test/java/com/vayunmathur/uniflix/data/AddonStreamProviderOfflineTest.kt b/uniflix/src/test/java/com/vayunmathur/uniflix/data/AddonStreamProviderOfflineTest.ktindex 008320c98a..b4f2f60862 100644--- a/uniflix/src/test/java/com/vayunmathur/uniflix/data/AddonStreamProviderOfflineTest.kt+++ b/uniflix/src/test/java/com/vayunmathur/uniflix/data/AddonStreamProviderOfflineTest.kt@@ -53,7 +53,7 @@ class AddonStreamProviderOfflineTest { // Singleton routes are distinct destinations. val routes: List<Route> = listOf( Route.Home, Route.Movies, Route.Series, Route.Search,- Route.Lists, Route.ContinueWatching, Route.PlayerSettings, Route.Addons)+ Route.Lists, Route.ContinueWatching, Route.Addons) assertEquals(routes.size, routes.distinct().size) } }
uniflix/src/test/java/com/vayunmathur/uniflix/ui/DetailHomeSearchComposeTest.kt
diff --git a/uniflix/src/test/java/com/vayunmathur/uniflix/ui/DetailHomeSearchComposeTest.kt b/uniflix/src/test/java/com/vayunmathur/uniflix/ui/DetailHomeSearchComposeTest.ktindex 3575fe74cb..0e3be613f2 100644--- a/uniflix/src/test/java/com/vayunmathur/uniflix/ui/DetailHomeSearchComposeTest.kt+++ b/uniflix/src/test/java/com/vayunmathur/uniflix/ui/DetailHomeSearchComposeTest.kt@@ -18,7 +18,7 @@ import org.junit.Rule import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner -/** Stateless Home / Search / Detail / PlayerSettings screens under Robolectric. */+/** Stateless Home / Search / Detail screens under Robolectric. */ @RunWith(RobolectricTestRunner::class) class DetailHomeSearchComposeTest { @@ -113,14 +113,4 @@ class DetailHomeSearchComposeTest { composeRule.onNodeWithText("Detail failed to load.").assertIsDisplayed() } - @Test fun playerSettingsShowsPlaybackInfo() {- composeRule.setContent {- DynamicTheme { PlayerSettingsScreen(onBack = {}) }- }- composeRule.onNodeWithText("Player").assertIsDisplayed()- composeRule.onNodeWithText("Playback").assertIsDisplayed()- composeRule.onNodeWithText(- "Streams play through the configured provider. Subtitle tracks come with the resolved source.")- .assertIsDisplayed()- } }
vpn/src/main/java/com/vayunmathur/vpn/platform/VpnViewModel.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/platform/VpnViewModel.kt b/vpn/src/main/java/com/vayunmathur/vpn/platform/VpnViewModel.ktindex d63b1036dc..78be089b62 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/platform/VpnViewModel.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/platform/VpnViewModel.kt@@ -193,13 +193,22 @@ class VpnViewModel( fun importFromUri(context: Context, uri: Uri) { viewModelScope.launch(Dispatchers.IO) { try {+ // Only the schemes the import contract can legitimately deliver:+ // SAF/OpenDocument and ACTION_VIEW both hand over content://,+ // and file:// from a file manager (see the manifest VIEW filter,+ // which declares content/file only). Anything else is rejected+ // before a stream is opened.+ if (uri.scheme != "content" && uri.scheme != "file") {+ _status.value = "Import failed: unsupported scheme ${uri.scheme}"+ return@launch+ } try { val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION context.contentResolver.takePersistableUriPermission(uri, flags) } catch (expected: SecurityException) { Log.status("VpnVM", "persist permission denied for $uri", expected) }- val bytes = context.contentResolver.openInputStream(uri)?.use { it.readBytes() } ?: run {+ val bytes = context.contentResolver.openInputStream(uri)?.use { readBounded(it) } ?: run { _status.value = "Failed to read file" return@launch }@@ -315,7 +324,29 @@ class VpnViewModel( companion object { private const val STOP_TIMEOUT_MS = 5_000L private const val POLL_RUNNING_MS = 500L++ /** WireGuard configs and .mavpn bundles are small; anything larger is not one. */+ private const val MAX_IMPORT_BYTES = 1_048_576 private val ZIP_MAGIC = byteArrayOf('P'.code.toByte(), 'K'.code.toByte(), 3, 4)++ /**+ * Reads at most [MAX_IMPORT_BYTES] from [input]; one byte over throws+ * [IOException], which the caller reports through its existing+ * import-failed path, instead of buffering an unbounded stream.+ */+ private fun readBounded(input: java.io.InputStream): ByteArray {+ val out = java.io.ByteArrayOutputStream()+ val buffer = ByteArray(8192)+ while (true) {+ val read = input.read(buffer)+ if (read < 0) break+ if (out.size() + read > MAX_IMPORT_BYTES) {+ throw IOException("File too large (over $MAX_IMPORT_BYTES bytes)")+ }+ out.write(buffer, 0, read)+ }+ return out.toByteArray()+ } } }