From 80d6d412f379ef9796b7274c13c1c03883c800d3 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Dec 2023 22:53:35 -0500 Subject: [PATCH] Avoid crashing if loading non-read-only private extension Fixes #10252 --- .../tachiyomi/extension/util/ExtensionLoader.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index c43af2fdc..c40d78157 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -141,6 +141,11 @@ internal object ExtensionLoader { ?.asSequence() ?.filter { it.isFile && it.extension == PRIVATE_EXTENSION_EXTENSION } ?.mapNotNull { + // Just in case, since Android 14+ requires them to be read-only + if (it.canWrite()) { + it.setReadOnly() + } + val path = it.absolutePath pkgManager.getPackageArchiveInfo(path, PACKAGE_FLAGS) ?.apply { applicationInfo.fixBasePaths(path) } @@ -277,7 +282,12 @@ internal object ExtensionLoader { val hasReadme = appInfo.metaData.getInt(METADATA_HAS_README, 0) == 1 val hasChangelog = appInfo.metaData.getInt(METADATA_HAS_CHANGELOG, 0) == 1 - val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader) + val classLoader = try { + PathClassLoader(appInfo.sourceDir, null, context.classLoader) + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($pkgName)" } + return LoadResult.Error + } val sources = appInfo.metaData.getString(METADATA_SOURCE_CLASS)!! .split(";")