diff --git a/src/main/kotlin/app/revanced/patches/microg/layout/hideicon/patch/HideIconPatch.kt b/src/main/kotlin/app/revanced/patches/microg/layout/hideicon/patch/HideIconPatch.kt new file mode 100644 index 000000000..fb98329bc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/microg/layout/hideicon/patch/HideIconPatch.kt @@ -0,0 +1,37 @@ +package app.revanced.patches.microg.layout.hideicon.patch + +import app.revanced.extensions.doRecursively +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.annotation.MicroGCompatibility +import org.w3c.dom.Element + +@Patch(false) +@Name("hide-icon-from-launcher") +@Description("Hide MicroG icon from launcher.") +@MicroGCompatibility +@Version("0.0.1") +class HideIconPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + context.xmlEditor["AndroidManifest.xml"].use { editor -> + editor.file.doRecursively loop@{ + if (it !is Element) return@loop + + it.getAttributeNode("android:name")?.let { attribute -> + if (attribute.textContent == "android.intent.category.LAUNCHER") { + attribute.textContent = "android.intent.category.DEFAULT" + } + } + } + } + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/shared/annotation/MicroGCompatibility.kt b/src/main/kotlin/app/revanced/patches/shared/annotation/MicroGCompatibility.kt new file mode 100644 index 000000000..538d99b60 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/annotation/MicroGCompatibility.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.shared.annotation + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.mgoogle.android.gms")]) +@Target(AnnotationTarget.CLASS) +internal annotation class MicroGCompatibility + diff --git a/src/main/kotlin/app/revanced/util/resources/MicroGResourceUtils.kt b/src/main/kotlin/app/revanced/util/resources/MicroGResourceUtils.kt new file mode 100644 index 000000000..b65fce939 --- /dev/null +++ b/src/main/kotlin/app/revanced/util/resources/MicroGResourceUtils.kt @@ -0,0 +1,63 @@ +package app.revanced.util.resources + +import app.revanced.extensions.doRecursively +import app.revanced.patcher.data.ResourceContext +import app.revanced.util.resources.ResourceUtils.copyResources +import app.revanced.util.resources.ResourceUtils.copyXmlNode +import org.w3c.dom.Element + +internal object MicroGResourceUtils { + + internal fun ResourceContext.copyFiles(path: String) { + fun copyResources(resourceGroups: List) { + resourceGroups.forEach { this.copyResources(path, it) } + } + + val iconResourceFileNames = arrayOf( + "ic_microg_launcher" + ).map { "$it.png" }.toTypedArray() + + fun createGroup(directory: String) = ResourceUtils.ResourceGroup( + directory, *iconResourceFileNames + ) + + // change the app icon + arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi") + .map { "mipmap-$it" } + .map(::createGroup) + .let(::copyResources) + + arrayOf( + ResourceUtils.ResourceGroup( + "drawable", + "ic_app_icons_themed_microg.xml", + "ic_microg_launcher_foreground.xml" + ), + ResourceUtils.ResourceGroup( + "mipmap-anydpi-v26", + "ic_microg_launcher.xml" + ) + ).forEach { this.copyResources(path, it) } + + this.copyXmlNode(path, "values/colors.xml", "resources") + this.setManifestIcon() + } + + private fun ResourceContext.setManifestIcon() { + this.xmlEditor["AndroidManifest.xml"].use { + val attributes = arrayOf("icon", "roundIcon") + + it.file.doRecursively { + attributes.forEach replacement@{ replacement -> + if (it !is Element) return@replacement + + it.getAttributeNode("android:$replacement")?.let { attribute -> + if (attribute.textContent.startsWith("@mipmap/")) + attribute.textContent = "@mipmap/ic_microg_launcher" + } + } + } + } + + } +} \ No newline at end of file