fix: preset import compatibility
This commit is contained in:
1 parent
9adb6616d8
commit
3e92c084c1
5 files changed
+60
-38
No files matched your search
@@ -2863,7 +2863,7 @@ class Camera2Controller(private val context: Context) {
|
||||
}
|
||||
handlePreviewSessionFailure("create session illegal state", openGeneration, e)
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to create preview session", e)
|
||||
PLog.w(TAG, "Failed to create preview session", e)
|
||||
if (vendorSessionParametersApplied &&
|
||||
retryPreviewSessionWithoutVendorSessionParameters(
|
||||
reason = "create session exception: ${e.message}",
|
||||
|
||||
@@ -232,46 +232,66 @@ class PresetPackageManager(
|
||||
}
|
||||
}
|
||||
|
||||
val dcpResources = resources.getAsJsonArray("dcps") ?: JsonArray()
|
||||
val expectedDcpKeys = packagedPreset.referencedDcpIds().toSet()
|
||||
val declaredDcpKeys = dcpResources.map { it.asJsonObject.requiredString("key") }
|
||||
require(declaredDcpKeys.size == declaredDcpKeys.distinct().size) {
|
||||
"Preset package contains duplicate DCP keys"
|
||||
}
|
||||
require(declaredDcpKeys.toSet() == expectedDcpKeys) {
|
||||
"Preset package DCP references do not match the preset"
|
||||
}
|
||||
|
||||
val resolvedDcpIds = linkedMapOf<String, String>()
|
||||
dcpResources.forEach { element ->
|
||||
val resource = element.asJsonObject
|
||||
val sourceKey = resource.requiredString("key")
|
||||
when (resource.requiredString("storage")) {
|
||||
STORAGE_REFERENCE -> {
|
||||
val builtIn = contentRepository.dcpManager.getAvailableDcps()
|
||||
.firstOrNull { it.id == sourceKey }
|
||||
require(builtIn?.isBuiltIn == true) {
|
||||
"Built-in DCP is unavailable: $sourceKey"
|
||||
}
|
||||
resolvedDcpIds[sourceKey] = sourceKey
|
||||
}
|
||||
if (version == 1) {
|
||||
val availableDcpIds = contentRepository.dcpManager.getAvailableDcps()
|
||||
.mapTo(mutableSetOf()) { it.id }
|
||||
val unavailableDcpKeys = expectedDcpKeys - availableDcpIds
|
||||
require(unavailableDcpKeys.isEmpty()) {
|
||||
"Legacy preset package references unavailable DCPs: " +
|
||||
unavailableDcpKeys.sorted().joinToString()
|
||||
}
|
||||
expectedDcpKeys.forEach { sourceKey ->
|
||||
resolvedDcpIds[sourceKey] = sourceKey
|
||||
}
|
||||
} else {
|
||||
val dcpResources = resources.getAsJsonArray("dcps") ?: JsonArray()
|
||||
val declaredDcpKeys = dcpResources.map {
|
||||
it.asJsonObject.requiredString("key")
|
||||
}
|
||||
require(declaredDcpKeys.size == declaredDcpKeys.distinct().size) {
|
||||
"Preset package contains duplicate DCP keys"
|
||||
}
|
||||
require(declaredDcpKeys.toSet() == expectedDcpKeys) {
|
||||
"Preset package DCP references do not match the preset"
|
||||
}
|
||||
|
||||
STORAGE_BUNDLED -> {
|
||||
val entryName = resource.requiredSafeEntry("entry")
|
||||
require(entryName.startsWith("resources/dcps/") && entryName.endsWith(".dcp")) {
|
||||
"Invalid bundled DCP entry"
|
||||
dcpResources.forEach { element ->
|
||||
val resource = element.asJsonObject
|
||||
val sourceKey = resource.requiredString("key")
|
||||
when (resource.requiredString("storage")) {
|
||||
STORAGE_REFERENCE -> {
|
||||
val builtIn = contentRepository.dcpManager.getAvailableDcps()
|
||||
.firstOrNull { it.id == sourceKey }
|
||||
require(builtIn?.isBuiltIn == true) {
|
||||
"Built-in DCP is unavailable: $sourceKey"
|
||||
}
|
||||
resolvedDcpIds[sourceKey] = sourceKey
|
||||
}
|
||||
val bytes = requireNotNull(archiveEntries[entryName]) {
|
||||
"Bundled DCP entry is missing: $entryName"
|
||||
}
|
||||
val nameMap = resource.getAsJsonObject("name")?.toStringMap().orEmpty()
|
||||
val importedId = customImportManager.importPresetDcp(bytes, nameMap)
|
||||
?: error("Failed to import bundled DCP: $sourceKey")
|
||||
importedDcpIds += importedId
|
||||
resolvedDcpIds[sourceKey] = importedId
|
||||
}
|
||||
|
||||
else -> error("Unsupported DCP storage mode")
|
||||
STORAGE_BUNDLED -> {
|
||||
val entryName = resource.requiredSafeEntry("entry")
|
||||
require(
|
||||
entryName.startsWith("resources/dcps/") &&
|
||||
entryName.endsWith(".dcp")
|
||||
) {
|
||||
"Invalid bundled DCP entry"
|
||||
}
|
||||
val bytes = requireNotNull(archiveEntries[entryName]) {
|
||||
"Bundled DCP entry is missing: $entryName"
|
||||
}
|
||||
val nameMap = resource.getAsJsonObject("name")
|
||||
?.toStringMap()
|
||||
.orEmpty()
|
||||
val importedId = customImportManager.importPresetDcp(bytes, nameMap)
|
||||
?: error("Failed to import bundled DCP: $sourceKey")
|
||||
importedDcpIds += importedId
|
||||
resolvedDcpIds[sourceKey] = importedId
|
||||
}
|
||||
|
||||
else -> error("Unsupported DCP storage mode")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5252,6 +5252,8 @@ object GalleryManager {
|
||||
originalBitmap.recycle()
|
||||
}
|
||||
PLog.d(TAG, "Thumbnail updated for photo: $photoId")
|
||||
} catch (e: CancellationException) {
|
||||
PLog.w(TAG, "Failed to update thumbnail for photo: $photoId", e)
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to update thumbnail for photo: $photoId", e)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ object DepthModelManager {
|
||||
downloadAndInstall(appContext)
|
||||
_state.value = DepthModelDownloadState.Ready
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to download or install the default depth model", e)
|
||||
PLog.w(TAG, "Failed to download or install the default depth model", e)
|
||||
_state.value = DepthModelDownloadState.Failed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2151,7 +2151,7 @@ private fun VideoDetailPlayer(
|
||||
PLog.d("VideoDetailPlayer", "ExoPlayer state changed: $state")
|
||||
}
|
||||
override fun onPlayerError(error: androidx.media3.common.PlaybackException) {
|
||||
PLog.e("VideoDetailPlayer", "ExoPlayer encountered error!", error)
|
||||
PLog.w("VideoDetailPlayer", "ExoPlayer encountered error!", error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user