Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

fix(series): tolerate unreadable provider credentials

David Nashashf5277b8a814f
diff --git a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
index ffc0145d..91d20581 100644
--- a/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/SeriesRepositoryImpl.kt
@@ -16,6 +16,7 @@ import com.streamvault.data.remote.stalker.StalkerSeriesDetailDialect
import com.streamvault.data.remote.stalker.StalkerUrlFactory
import com.streamvault.data.remote.stalker.StalkerVodPlaybackDialect
import com.streamvault.data.remote.xtream.XtreamStreamUrlResolver
+import com.streamvault.data.security.CredentialDecryptionException
import com.streamvault.data.sync.ContentCachePolicy
import com.streamvault.data.sync.CatalogHydrationCommands
import com.streamvault.data.util.SeriesPresentationSettings
@@ -235,10 +236,14 @@ class SeriesRepositoryImpl @Inject constructor(
val provider = loadCompatibilityProvider(providerId)
val previewCategories = if (provider?.type == ProviderType.STALKER_PORTAL) {
val stalkerProvider = createStalkerProvider(providerId)
- val nonWildcard = filteredCategories.filterNot { category ->
- stalkerProvider.isWildcardCategory(ContentType.SERIES, category.categoryId)
+ if (stalkerProvider == null) {
+ filteredCategories
+ } else {
+ val nonWildcard = filteredCategories.filterNot { category ->
+ stalkerProvider.isWildcardCategory(ContentType.SERIES, category.categoryId)
+ }
+ if (nonWildcard.isNotEmpty()) nonWildcard else filteredCategories
}
- if (nonWildcard.isNotEmpty()) nonWildcard else filteredCategories
} else {
filteredCategories
}
@@ -426,7 +431,11 @@ class SeriesRepositoryImpl @Inject constructor(
mode == VodCategoryLoadMode.PAGED
) {
repositoryScope.launch {
- requestCategoryHydration(providerId, categoryId, VodCategoryHydrationRequest.NEXT_PAGE)
+ try {
+ requestCategoryHydration(providerId, categoryId, VodCategoryHydrationRequest.NEXT_PAGE)
+ } catch (_: CredentialDecryptionException) {
+ logUnreadableProviderCredentials(providerId)
+ }
}
}
return derivedResult
@@ -1676,6 +1685,8 @@ class SeriesRepositoryImpl @Inject constructor(
allowWildcard = allowStalkerWildcard
)
}
+ } catch (_: CredentialDecryptionException) {
+ logUnreadableProviderCredentials(providerId)
} finally {
backgroundRefreshes.remove(key)
}
@@ -1715,7 +1726,7 @@ class SeriesRepositoryImpl @Inject constructor(
xtreamCategoryLoadLocks.withLock(key) {
val persistedHydration = seriesCategoryHydrationDao.get(providerId, categoryId)
if (requestedPage != null && (persistedHydration?.lastSuccessfulPage ?: 0) >= requestedPage) return@withLock
- val stalkerProvider = createStalkerProvider(providerId)
+ val stalkerProvider = createStalkerProvider(providerId) ?: return@withLock
if (!allowWildcard && stalkerProvider.isWildcardCategory(ContentType.SERIES, categoryId)) return@withLock
var currentCount = localCount ?: seriesDao.getCountByCategory(providerId, categoryId).first()
var currentHydration = persistedHydration ?: hydration
@@ -1935,8 +1946,13 @@ class SeriesRepositoryImpl @Inject constructor(
private fun seriesUpdatedScore(series: Series): Long =
series.lastModified.takeIf { it > 0L } ?: 0L
- private suspend fun createStalkerProvider(providerId: Long): StalkerProvider {
- val snapshot = providerCapabilityResolver.snapshot(providerId)
+ private suspend fun createStalkerProvider(providerId: Long): StalkerProvider? {
+ val snapshot = try {
+ providerCapabilityResolver.snapshot(providerId)
+ } catch (_: CredentialDecryptionException) {
+ logUnreadableProviderCredentials(providerId)
+ return null
+ }
?: throw IllegalStateException("Provider $providerId has no typed configuration")
return when (val resolution = typedProviderClientFactory.stalker(snapshot)) {
is CapabilityResolution.Available -> resolution.capability
@@ -1964,6 +1980,14 @@ class SeriesRepositoryImpl @Inject constructor(
catalogLayoutDetectionVersion.toString()
).joinToString("\u0000").hashCode()
- private suspend fun loadCompatibilityProvider(providerId: Long): Provider? =
+ private suspend fun loadCompatibilityProvider(providerId: Long): Provider? = try {
providerCapabilityResolver.snapshot(providerId)?.toLegacyProvider()
+ } catch (_: CredentialDecryptionException) {
+ logUnreadableProviderCredentials(providerId)
+ null
+ }
+
+ private fun logUnreadableProviderCredentials(providerId: Long) {
+ Log.w(TAG, "Skipping series provider work because stored credentials are unreadable (providerId=$providerId)")
+ }
}
diff --git a/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt b/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
index c50f1eff..1a168971 100644
--- a/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
+++ b/data/src/test/java/com/streamvault/data/repository/SeriesRepositoryImplTest.kt
@@ -46,6 +46,7 @@ import com.streamvault.data.remote.xtream.XtreamParsingException
import com.streamvault.data.remote.xtream.XtreamApiService
import com.streamvault.data.remote.xtream.XtreamStreamUrlResolver
import com.streamvault.data.security.CredentialCrypto
+import com.streamvault.data.security.CredentialDecryptionException
import com.streamvault.data.sync.SyncManager
import com.streamvault.domain.model.ContentType
import com.streamvault.domain.model.LibraryBrowseQuery
@@ -77,6 +78,8 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.runBlocking
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.timeout
@@ -168,6 +171,61 @@ class SeriesRepositoryImplTest {
verify(episodeDao, never()).deleteOrphans()
}
+ @Test
+ fun `series preview keeps local catalog when provider credentials are unreadable`() = runTest {
+ whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
+ whenever(categoryDao.getByProviderAndType(7L, ContentType.SERIES.name)).thenReturn(
+ flowOf(listOf(CategoryEntity(providerId = 7L, categoryId = 77L, name = "Drama", type = ContentType.SERIES)))
+ )
+ whenever(seriesDao.getByCategoryPreview(7L, 77L, 18)).thenReturn(flowOf(emptyList()))
+ whenever(providerCapabilityResolver.snapshot(7L)).thenThrow(CredentialDecryptionException())
+
+ val result = createRepository().getCategoryPreviewRows(7L, listOf(77L), 18).first()
+
+ assertThat(result).containsKey(77L)
+ assertThat(result.getValue(77L)).isEmpty()
+ verifyNoInteractions(stalkerApiService, xtreamApiService)
+ }
+
+ @Test
+ fun `series preview contains background provider credential decryption failure`() = runTest {
+ val uncaughtExceptionLatch = CountDownLatch(1)
+ var uncaughtException: Throwable? = null
+ val previousUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
+ Thread.setDefaultUncaughtExceptionHandler { _, error ->
+ uncaughtException = error
+ uncaughtExceptionLatch.countDown()
+ }
+
+ try {
+ whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
+ whenever(categoryDao.getByProviderAndType(7L, ContentType.SERIES.name)).thenReturn(
+ flowOf(listOf(CategoryEntity(providerId = 7L, categoryId = 77L, name = "Drama", type = ContentType.SERIES)))
+ )
+ whenever(seriesDao.getCountByCategory(7L, 77L)).thenReturn(flowOf(0))
+ whenever(seriesDao.getByCategoryPreview(7L, 77L, 18)).thenReturn(flowOf(emptyList()))
+ whenever(seriesCategoryHydrationDao.get(7L, 77L)).thenReturn(null)
+ whenever(stalkerRemoteIdentityResolver.reverse(7L, ContentType.SERIES, 77L)).thenReturn("77")
+
+ val provider = stalkerProvider()
+ stubProvider(provider)
+ val snapshot = provider.toProviderSnapshot()
+ whenever(providerCapabilityResolver.snapshot(7L))
+ .thenReturn(snapshot, snapshot)
+ .thenThrow(CredentialDecryptionException())
+
+ val result = createRepository().getCategoryPreviewRows(7L, listOf(77L), 18).first()
+
+ assertThat(result).containsKey(77L)
+ verify(providerCapabilityResolver, timeout(1_000).times(3)).snapshot(7L)
+ assertThat(uncaughtExceptionLatch.await(300, TimeUnit.MILLISECONDS)).isFalse()
+ assertThat(uncaughtException).isNull()
+ verifyNoInteractions(stalkerApiService)
+ } finally {
+ Thread.setDefaultUncaughtExceptionHandler(previousUncaughtExceptionHandler)
+ }
+ }
+
@Test
fun `getSeriesByCategory directly hydrates stalker category even when background fetch is running`() = runTest {
whenever(preferencesRepository.parentalControlLevel).thenReturn(flowOf(0))
diff --git a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
index 31b20cda..34ed775c 100644
--- a/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
+++ b/data/src/test/java/com/streamvault/data/sync/SyncManagerTest.kt
@@ -513,6 +513,8 @@ class SyncManagerTest {
xtreamIndexJobDao = xtreamIndexJobDao,
stalkerLiveCategoryRetryDao = stalkerLiveCategoryRetryDao,
stalkerIndexJobStore = StalkerIndexJobStore(object : StalkerIndexJobDao {
+ override fun observeAll(): Flow<List<StalkerIndexJobEntity>> = flowOf(emptyList())
+
override fun observeForProvider(providerId: Long): Flow<List<StalkerIndexJobEntity>> = flowOf(emptyList())
override suspend fun get(providerId: Long, section: String): StalkerIndexJobEntity? =
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index c8637ad1..afb72667 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -33,6 +33,7 @@ All notable product changes are recorded in this document.
- Fixed Xtream series losing some or all of their episodes after another series was opened (#166). Episode ids are now unique per series instead of per provider, and series cached before the fix are re-fetched the next time they are opened.
- Fixed M3U channels sharing a `tvg-id` but using different stream URLs or Acestream hashes from being incorrectly treated as the same channel (#231).
- Fixed background movie refresh crashes when saved provider credentials cannot be decrypted.
+- Fixed Series browsing and background hydration continuing from cached catalog data when saved provider credentials cannot be decrypted.
- Fixed cropped video during adaptive resolution changes on affected Android TV emulators.
- Fixed backup imports rejecting internal restore checkpoints and episode conflict previews matching episodes without their parent-series identity.
- Fixed backup export sharing to remove failed temporary files and share only completed exports.