From c48028f3cd23b0696703dea3ed843fe175b4bcef Mon Sep 17 00:00:00 2001 From: rebel onion <87634197+rebelonion@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:36:31 -0600 Subject: [PATCH] fix: extensions not triggering update in app --- .../parsers/novel/NovelExtensionManager.kt | 2 +- .../source/service/SourcePreferences.kt | 2 - .../extension/anime/AnimeExtensionManager.kt | 41 +-------------- .../extension/manga/MangaExtensionManager.kt | 40 +-------------- .../extension/util/ExtensionLoader.kt | 50 ++----------------- 5 files changed, 6 insertions(+), 129 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/parsers/novel/NovelExtensionManager.kt b/app/src/main/java/ani/dantotsu/parsers/novel/NovelExtensionManager.kt index 5ef1aa7d35..145fd3b2f1 100644 --- a/app/src/main/java/ani/dantotsu/parsers/novel/NovelExtensionManager.kt +++ b/app/src/main/java/ani/dantotsu/parsers/novel/NovelExtensionManager.kt @@ -234,7 +234,7 @@ class NovelExtensionManager(private val context: Context) { private fun NovelExtension.Installed.updateExists(availableNovelExtension: NovelExtension.Available? = null): Boolean { val availableExt = availableNovelExtension ?: _availableNovelExtensionsFlow.value.find { it.pkgName == pkgName } - if (isUnofficial || availableExt == null) return false + if (availableExt == null) return false return (availableExt.versionCode > versionCode) } diff --git a/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt index a22ee27b64..e1017beceb 100644 --- a/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt +++ b/app/src/main/java/eu/kanade/domain/source/service/SourcePreferences.kt @@ -29,8 +29,6 @@ class SourcePreferences( fun migrationSortingDirection() = preferenceStore.getEnum("pref_migration_direction", SetMigrateSorting.Direction.ASCENDING) - fun trustedSignatures() = preferenceStore.getStringSet("trusted_signatures", emptySet()) - // Mixture Sources fun disabledAnimeSources() = preferenceStore.getStringSet("hidden_anime_catalogues", emptySet()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt index 07809c601c..04303abae5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/anime/AnimeExtensionManager.kt @@ -253,45 +253,6 @@ class AnimeExtensionManager( installer.uninstallApk(pkgName) } - /** - * Adds the given signature to the list of trusted signatures. It also loads in background the - * anime extensions that match this signature. - * - * @param signature The signature to whitelist. - */ - @OptIn(DelicateCoroutinesApi::class) - fun trustSignature(signature: String) { - val untrustedSignatures = - _untrustedAnimeExtensionsFlow.value.map { it.signatureHash }.toSet() - if (signature !in untrustedSignatures) return - - ExtensionLoader.trustedSignaturesAnime += signature - preferences.trustedSignatures() += signature - - val nowTrustedAnimeExtensions = - _untrustedAnimeExtensionsFlow.value.filter { it.signatureHash == signature } - _untrustedAnimeExtensionsFlow.value -= nowTrustedAnimeExtensions - - val ctx = context - launchNow { - nowTrustedAnimeExtensions - .map { animeextension -> - async { - ExtensionLoader.loadAnimeExtensionFromPkgName( - ctx, - animeextension.pkgName - ) - } - } - .map { it.await() } - .forEach { result -> - if (result is AnimeLoadResult.Success) { - registerNewExtension(result.extension) - } - } - } - } - /** * Registers the given anime extension in this and the source managers. * @@ -375,7 +336,7 @@ class AnimeExtensionManager( private fun AnimeExtension.Installed.updateExists(availableAnimeExtension: AnimeExtension.Available? = null): Boolean { val availableExt = availableAnimeExtension ?: _availableAnimeExtensionsFlow.value.find { it.pkgName == pkgName } - if (isUnofficial || availableExt == null) return false + if (availableExt == null) return false return (availableExt.versionCode > versionCode || availableExt.libVersion > libVersion) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt index 1ae3972485..f18667ec97 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/manga/MangaExtensionManager.kt @@ -249,44 +249,6 @@ class MangaExtensionManager( installer.uninstallApk(pkgName) } - /** - * Adds the given signature to the list of trusted signatures. It also loads in background the - * extensions that match this signature. - * - * @param signature The signature to whitelist. - */ - @OptIn(DelicateCoroutinesApi::class) - fun trustSignature(signature: String) { - val untrustedSignatures = _untrustedExtensionsFlow.value.map { it.signatureHash }.toSet() - if (signature !in untrustedSignatures) return - - ExtensionLoader.trustedSignaturesManga += signature - preferences.trustedSignatures() += signature - - val nowTrustedExtensions = - _untrustedExtensionsFlow.value.filter { it.signatureHash == signature } - _untrustedExtensionsFlow.value -= nowTrustedExtensions - - val ctx = context - launchNow { - nowTrustedExtensions - .map { extension -> - async { - ExtensionLoader.loadMangaExtensionFromPkgName( - ctx, - extension.pkgName - ) - } - } - .map { it.await() } - .forEach { result -> - if (result is MangaLoadResult.Success) { - registerNewExtension(result.extension) - } - } - } - } - /** * Registers the given extension in this and the source managers. * @@ -368,7 +330,7 @@ class MangaExtensionManager( private fun MangaExtension.Installed.updateExists(availableExtension: MangaExtension.Available? = null): Boolean { val availableExt = availableExtension ?: _availableExtensionsFlow.value.find { it.pkgName == pkgName } - if (isUnofficial || availableExt == null) return false + if (availableExt == null) return false return (availableExt.versionCode > versionCode || availableExt.libVersion > libVersion) } 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 fdaa245a84..e8c41d1593 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 @@ -73,27 +73,6 @@ internal object ExtensionLoader { (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) PackageManager.GET_SIGNING_CERTIFICATES else 0) - // jmir1's key - private const val officialSignatureAnime = - "50ab1d1e3a20d204d0ad6d334c7691c632e41b98dfa132bf385695fdfa63839c" - - var trustedSignaturesAnime = - mutableSetOf() + preferences.trustedSignatures().get() + officialSignatureAnime - - // inorichi's key - private const val officialSignatureManga = - "7ce04da7773d41b489f4693a366c36bcd0a11fc39b547168553c285bd7348e23" - - //dan's key - private const val officialSignature = - "a3061edb369278749b8e8de810d440d38e96417bbd67bbdfc5d9d9ed475ce4a5" - - /** - * List of the trusted signatures. - */ - var trustedSignaturesManga = - mutableSetOf() + preferences.trustedSignatures().get() + officialSignatureManga - /** * Return a list of all the installed extensions initialized concurrently. * @@ -256,8 +235,6 @@ internal object ExtensionLoader { return AnimeLoadResult.Error } - val signatureHash = getSignatureHash(pkgInfo) - val isNsfw = appInfo.metaData.getInt("$ANIME_PACKAGE$XX_METADATA_NSFW") == 1 if (!loadNsfwSource && isNsfw) { Logger.log("NSFW extension $pkgName not allowed") @@ -321,7 +298,7 @@ internal object ExtensionLoader { hasChangelog = hasChangelog, sources = sources, pkgFactory = appInfo.metaData.getString("$ANIME_PACKAGE$XX_METADATA_SOURCE_FACTORY"), - isUnofficial = signatureHash != officialSignatureAnime, + isUnofficial = true, icon = context.getApplicationIcon(pkgName), ) return AnimeLoadResult.Success(extension) @@ -362,8 +339,6 @@ internal object ExtensionLoader { return MangaLoadResult.Error } - val signatureHash = getSignatureHash(pkgInfo) - val isNsfw = appInfo.metaData.getInt("$MANGA_PACKAGE$XX_METADATA_NSFW") == 1 if (!loadNsfwSource && isNsfw) { Logger.log("NSFW extension $pkgName not allowed") @@ -427,7 +402,7 @@ internal object ExtensionLoader { hasChangelog = hasChangelog, sources = sources, pkgFactory = appInfo.metaData.getString("$MANGA_PACKAGE$XX_METADATA_SOURCE_FACTORY"), - isUnofficial = signatureHash != officialSignatureManga, + isUnofficial = true, icon = context.getApplicationIcon(pkgName), ) return MangaLoadResult.Success(extension) @@ -458,8 +433,6 @@ internal object ExtensionLoader { return NovelLoadResult.Error(Exception("Missing versionName for extension $extName")) } - val signatureHash = getSignatureHash(pkgInfo) - val classLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader) val novelInterfaceInstance = try { val className = appInfo.loadLabel(context.packageManager).toString() @@ -479,7 +452,7 @@ internal object ExtensionLoader { versionName = versionName, versionCode = versionCode, sources = listOfNotNull(novelInterfaceInstance), - isUnofficial = signatureHash != officialSignatureManga, + isUnofficial = true, icon = context.getApplicationIcon(pkgName), ) return NovelLoadResult.Success(extension) @@ -505,21 +478,4 @@ internal object ExtensionLoader { } } } - - /** - * Returns the signature hash of the package or null if it's not signed. - * - * @param pkgInfo The package info of the application. - */ - private fun getSignatureHash(pkgInfo: PackageInfo): String? { - val signatures = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) - pkgInfo.signingInfo?.signingCertificateHistory - else - @Suppress("DEPRECATION") pkgInfo.signatures - return if (signatures != null && signatures.isNotEmpty()) { - Hash.sha256(signatures.first().toByteArray()) - } else { - null - } - } }