Skip to content

Commit

Permalink
fix: extensions not triggering update in app
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 3, 2025
1 parent e41ab2d commit c48028f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>() + 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<String>() + preferences.trustedSignatures().get() + officialSignatureManga

/**
* Return a list of all the installed extensions initialized concurrently.
*
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
}
}
}

0 comments on commit c48028f

Please sign in to comment.