From 2d9f9adfee84769ba9b4e83e75f99dcf85ffb6b2 Mon Sep 17 00:00:00 2001 From: Ax333l Date: Sat, 17 Jun 2023 13:59:37 +0200 Subject: [PATCH] refactor: better PatchBundle docs and naming --- .../manager/patcher/patch/PatchBundle.kt | 21 +++++++++++-------- .../manager/patcher/worker/PatcherWorker.kt | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/app/revanced/manager/patcher/patch/PatchBundle.kt b/app/src/main/java/app/revanced/manager/patcher/patch/PatchBundle.kt index 8f2c4c9c..baa3bd46 100644 --- a/app/src/main/java/app/revanced/manager/patcher/patch/PatchBundle.kt +++ b/app/src/main/java/app/revanced/manager/patcher/patch/PatchBundle.kt @@ -12,10 +12,12 @@ import java.io.File class PatchBundle(private val loader: Iterable, val integrations: File?) { constructor(bundleJar: File, integrations: File?) : this( object : Iterable { - private val bundle = PatchBundle.Dex( - bundleJar.absolutePath, - PathClassLoader(bundleJar.absolutePath, Patcher::class.java.classLoader) - ) + private val bundle = bundleJar.absolutePath.let { + PatchBundle.Dex( + it, + PathClassLoader(it, Patcher::class.java.classLoader) + ) + } override fun iterator() = bundle.loadPatches().iterator() }, @@ -24,12 +26,15 @@ class PatchBundle(private val loader: Iterable, val integrations: Fi Log.d(tag, "Loaded patch bundle: $bundleJar") } - val patches = loadAllPatches().map(::PatchInfo) + /** + * A list containing the metadata of every patch inside this bundle. + */ + val patches = loader.map(::PatchInfo) /** - * @return A list of patches that are compatible with this Apk. + * Load all patches compatible with the specified package. */ - fun loadPatchesFiltered(packageName: String) = loader.filter { patch -> + fun patchClasses(packageName: String) = loader.filter { patch -> val compatiblePackages = patch.compatiblePackages ?: // The patch has no compatibility constraints, which means it is universal. return@filter true @@ -41,6 +46,4 @@ class PatchBundle(private val loader: Iterable, val integrations: Fi true } - - private fun loadAllPatches() = loader.toList() } \ No newline at end of file diff --git a/app/src/main/java/app/revanced/manager/patcher/worker/PatcherWorker.kt b/app/src/main/java/app/revanced/manager/patcher/worker/PatcherWorker.kt index a279e9c8..18802c62 100644 --- a/app/src/main/java/app/revanced/manager/patcher/worker/PatcherWorker.kt +++ b/app/src/main/java/app/revanced/manager/patcher/worker/PatcherWorker.kt @@ -120,7 +120,7 @@ class PatcherWorker(context: Context, parameters: WorkerParameters) : return try { val patchList = args.selectedPatches.flatMap { (bundleName, selected) -> - bundles[bundleName]?.loadPatchesFiltered(args.packageName) + bundles[bundleName]?.patchClasses(args.packageName) ?.filter { selected.contains(it.patchName) } ?: throw IllegalArgumentException("Patch bundle $bundleName does not exist") }