Skip to content

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

1.0.7: fix crash on Android 9 OEM devices (Keystore / EncryptedSharedPreferences)

David Nashashcd6f6fa1639d
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index b7e0b883..2a2198ba 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -48,8 +48,8 @@ android {
applicationId = "com.streamvault.app"
minSdk = 28
targetSdk = 36
- versionCode = 7
- versionName = "1.0.6"
+ versionCode = 8
+ versionName = "1.0.7"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "OFFICIAL_APPLICATION_ID", "\"com.streamvault.app\"")
buildConfigField("String", "OFFICIAL_SIGNING_CERT_SHA256", "\"$officialSigningCertSha256\"")
diff --git a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
index d5a76eea..f74934f5 100644
--- a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
+++ b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
@@ -2,6 +2,8 @@ package com.streamvault.data.preferences
import android.content.Context
import android.content.SharedPreferences
+import android.os.Build
+import android.util.Log
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import androidx.datastore.core.DataStore
@@ -165,16 +167,34 @@ class PreferencesRepository @Inject constructor(
}
private val parentalSessionPreferences: SharedPreferences by lazy {
- val masterKey = MasterKey.Builder(context)
- .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
- .build()
- EncryptedSharedPreferences.create(
- context,
- ParentalSessionKeys.FILE_NAME,
- masterKey,
- EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
- EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
- )
+ runCatching {
+ val masterKey = MasterKey.Builder(context)
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
+ .build()
+ EncryptedSharedPreferences.create(
+ context,
+ ParentalSessionKeys.FILE_NAME,
+ masterKey,
+ EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
+ EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
+ )
+ }.getOrElse { e ->
+ // Android 9 (API 28) on certain OEM devices (MediaTek, some Samsung/Huawei) has
+ // buggy Keystore HAL implementations that throw GeneralSecurityException or
+ // KeyStoreException during MasterKey generation. Fall back to unencrypted prefs
+ // so the app stays functional. Only PIN lockout timestamps are affected — the PIN
+ // hash/salt itself is stored in DataStore and is unaffected by this fallback.
+ Log.w(
+ "PreferencesRepository",
+ "EncryptedSharedPreferences unavailable on API ${Build.VERSION.SDK_INT} " +
+ "(Keystore error). Parental PIN lockout persistence uses unencrypted fallback.",
+ e
+ )
+ context.getSharedPreferences(
+ "${ParentalSessionKeys.FILE_NAME}_fallback",
+ Context.MODE_PRIVATE
+ )
+ }
}
val lastActiveProviderId: Flow<Long?> = context.dataStore.data.map { preferences ->
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 2f348a46..d79383f0 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -1,6 +1,22 @@
# Changelog
All notable product changes are recorded in this document.
+## [1.0.7] - 2026-04-19
+
+### Fixed
+
+- Fixed crash on launch affecting some Android 9 (API 28) devices. On certain OEM builds
+ (MediaTek-based chipsets, some Samsung and Huawei devices), the Android Keystore HAL
+ throws a `GeneralSecurityException` or `KeyStoreException` when `EncryptedSharedPreferences`
+ is first initialised. This preference store holds the parental PIN lockout state and is
+ accessed during `ParentalControlManager` initialisation, which runs synchronously on the
+ first ViewModelScope creation at app startup — causing an immediate cold-start crash. The
+ fix wraps the encrypted store creation in a `runCatching` block and falls back to a
+ standard (unencrypted) `SharedPreferences` file if the Keystore is unavailable. The PIN
+ hash and salt themselves are stored in DataStore and are unaffected.
+
+---
+
## [1.0.6] - 2026-04-19
### Fixed