11package video.typetype.tv
22
33import android.content.Context
4+ import android.content.pm.ApplicationInfo
5+ import androidx.core.content.pm.PackageInfoCompat
46import androidx.media3.common.util.UnstableApi
7+ import kotlinx.coroutines.CoroutineScope
8+ import kotlinx.coroutines.Dispatchers
9+ import kotlinx.coroutines.SupervisorJob
510import video.typetype.tv.data.ContentRepository
611import video.typetype.tv.data.PresenceReport
712import video.typetype.tv.data.device.PerformanceSettings
813import video.typetype.tv.data.device.PreferencesDeviceStore
14+ import video.typetype.tv.data.device.UpdateSettings
915import video.typetype.tv.data.dto.UserProfileDto
1016import video.typetype.tv.data.net.AndroidConnectivity
1117import video.typetype.tv.data.net.Connectivity
18+ import video.typetype.tv.data.net.HttpClients
1219import video.typetype.tv.data.net.LazySecretStore
1320import video.typetype.tv.data.net.TinkSecretStore
1421import video.typetype.tv.data.remote.AndroidTextProvider
@@ -20,12 +27,18 @@ import video.typetype.tv.data.session.Backend
2027import video.typetype.tv.data.session.DeviceProfileStore
2128import video.typetype.tv.data.session.SessionManager
2229import video.typetype.tv.data.session.StreamAccess
30+ import video.typetype.tv.data.update.ReleaseFeed
31+ import video.typetype.tv.data.update.UpdateDownloader
2332import video.typetype.tv.playback.CodecSupport
2433import video.typetype.tv.playback.DecoderFailures
2534import video.typetype.tv.playback.DeviceCodecSupport
2635import video.typetype.tv.playback.LearnedCodecSupport
2736import video.typetype.tv.playback.PlaybackProvider
2837import video.typetype.tv.playback.RoutingPlaybackProvider
38+ import video.typetype.tv.ui.update.InstalledApp
39+ import video.typetype.tv.ui.update.SessionUpdateInstaller
40+ import video.typetype.tv.ui.update.UpdateController
41+ import java.io.File
2942
3043class AppContainer (context : Context ) {
3144 private val appContext = context.applicationContext
@@ -39,6 +52,7 @@ class AppContainer(context: Context) {
3952
4053 private val deviceProfile by lazy { DeviceProfileStore (appContext, appVersion) }
4154 val performance by lazy { PerformanceSettings (PreferencesDeviceStore (appContext)) }
55+ val updateSettings by lazy { UpdateSettings (PreferencesDeviceStore (appContext, PreferencesDeviceStore .UPDATES )) }
4256
4357 fun warmUp () {
4458 Thread ({ secrets.warmUp() }, " secrets-warmup" ).start()
@@ -77,7 +91,7 @@ class AppContainer(context: Context) {
7791 watch = backend.watch,
7892 userSettings = userSettings,
7993 access = access,
80- performance = performance,
94+ deviceSections = listOf ( performance, updateSettings) ,
8195 )
8296
8397 private val codecs: CodecSupport by lazy { deviceCodecs() }
@@ -91,6 +105,22 @@ class AppContainer(context: Context) {
91105 @androidx.annotation.OptIn (UnstableApi ::class )
92106 private fun deviceCodecs (): CodecSupport = LearnedCodecSupport (DeviceCodecSupport (appContext), decoderFailures)
93107
108+ val updates by lazy {
109+ val info = appContext.packageManager.getPackageInfo(appContext.packageName, 0 )
110+ val http = HttpClients .updates()
111+ val feed = ReleaseFeed (http)
112+ UpdateController (
113+ releases = feed,
114+ download = UpdateDownloader (http),
115+ installer = SessionUpdateInstaller (appContext),
116+ settings = updateSettings,
117+ installed = InstalledApp (appContext.packageName, info.versionName.orEmpty(), PackageInfoCompat .getLongVersionCode(info)),
118+ apkFile = File (appContext.cacheDir, " update/TypeType-TV.apk" ),
119+ scope = CoroutineScope (SupervisorJob () + Dispatchers .Main .immediate),
120+ automatic = appContext.applicationInfo.flags and ApplicationInfo .FLAG_DEBUGGABLE == 0 ,
121+ )
122+ }
123+
94124 val decoderFailures by lazy { DecoderFailures (PreferencesDeviceStore (appContext, PreferencesDeviceStore .DECODERS )) }
95125}
96126
0 commit comments