Skip to content

Commit 64efc2b

Browse files
feat: Add Hide app icon patch
1 parent fbef1d9 commit 64efc2b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
public final class HideAppIconKt {
2+
public static final fun getHideAppIconPatch ()Lapp/revanced/patcher/patch/ResourcePatch;
3+
}
4+
15
public final class app/revanced/patches/all/misc/activity/exportall/ExportAllActivitiesPatchKt {
26
public static final fun getExportAllActivitiesPatch ()Lapp/revanced/patcher/patch/ResourcePatch;
37
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package app.revanced.patches.all.misc.appicon
2+
3+
import app.revanced.patcher.patch.resourcePatch
4+
import org.w3c.dom.Element
5+
import java.util.logging.Level
6+
import java.util.logging.Logger
7+
8+
private const val ANDROID_NS = "http://schemas.android.com/apk/res/android"
9+
10+
@Suppress("unused")
11+
val hideAppIconPatch = resourcePatch(
12+
name = "Hide app icon",
13+
description = "Hides the app icon from the launcher by changing the intent filter category.",
14+
use = false,
15+
) {
16+
execute {
17+
document("AndroidManifest.xml").use { document ->
18+
val logger = Logger.getLogger("hideAppIconPatch")
19+
20+
try {
21+
val categoryNodes = document.getElementsByTagName("category")
22+
if (categoryNodes.length == 0) {
23+
logger.warning("No <category> elements found in AndroidManifest.xml. Skipping modification.")
24+
return@execute
25+
}
26+
27+
val validCategoryNodes = (0 until categoryNodes.length)
28+
.mapNotNull { categoryNodes.item(it) as? Element }
29+
.filter { (it.parentNode as? Element)?.nodeName == "intent-filter" }
30+
31+
if (validCategoryNodes.isEmpty()) {
32+
logger.warning("No valid 'android.intent.category.LAUNCHER' found in intent-filter blocks. Skipping modification.")
33+
return@execute
34+
}
35+
36+
var modified = false
37+
for (category in validCategoryNodes) {
38+
val categoryName = category.getAttributeNS(ANDROID_NS, "name")
39+
40+
if (category.hasAttributeNS(ANDROID_NS, "name") && categoryName == "android.intent.category.LAUNCHER") {
41+
category.setAttributeNS(ANDROID_NS, "name", "android.intent.category.DEFAULT")
42+
modified = true
43+
}
44+
}
45+
46+
if (!modified) {
47+
logger.warning("No 'android.intent.category.LAUNCHER' found or already set to DEFAULT—no modifications made.")
48+
}
49+
} catch (e: Exception) {
50+
logger.log(Level.SEVERE, "Error while modifying AndroidManifest.xml", e)
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)