Skip to content

Commit

Permalink
fix: the icon pack icon will be treated the same way as others
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLuo0 committed Dec 2, 2024
1 parent 24be9a8 commit 41b957a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ private operator fun XmlPullParser.get(key: String): String? = this.getAttribute

@Volatile private var cip: CustomIconPack? = null

fun isCipInitialized() = cip != null

fun getCip(): CustomIconPack? {
if (cip == null) {
synchronized(CustomIconPack::class) {
Expand Down
32 changes: 12 additions & 20 deletions app/src/main/kotlin/com/richardluo/globalIconPack/ReplaceIcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XC_MethodReplacement
import de.robv.android.xposed.callbacks.XC_LoadPackage

private const val IS_ICON_PACK = 0xff000000.toInt()
private const val IN_CIP = 0xfe000000.toInt()
private const val NOT_IN_CIP = 0xfd000000.toInt()
private const val IN_CIP = 0xff000000.toInt()
private const val NOT_IN_CIP = 0xfe000000.toInt()
private const val ANDROID_DEFAULT = 0x7f000000
private const val CIP_DEFAULT = 0x00000000

Expand All @@ -34,19 +33,16 @@ class ReplaceIcon : Hook {
object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
val info = param.thisObject as PackageItemInfo
if (info.icon != 0)
if (info.packageName rEqual packPackageName) {
// Avoid recursively call getCip()
info.icon = withHighByteSet(info.icon, IS_ICON_PACK)
} else
getCip()?.let { cip ->
val id =
cip.getId(getComponentName(info))
?: if (iconPackAsFallback) cip.getId(getComponentName(info.packageName))
else null
info.icon =
id?.let { withHighByteSet(it, IN_CIP) } ?: withHighByteSet(info.icon, NOT_IN_CIP)
}
if (info.icon == 0) return
// Avoid recursively call getCip()
if (isCipInitialized() || info.packageName rNEqual packPackageName)
getCip()?.let { cip ->
val id =
cip.getId(getComponentName(info))
?: if (iconPackAsFallback) cip.getId(getComponentName(info.packageName)) else null
info.icon =
id?.let { withHighByteSet(it, IN_CIP) } ?: withHighByteSet(info.icon, NOT_IN_CIP)
}
}
}
ReflectHelper.hookAllConstructors(ApplicationInfo::class.java, replaceIconResId)
Expand All @@ -58,10 +54,6 @@ class ReplaceIcon : Hook {
val resId = param.args[0] as Int
val density = param.args[1] as Int
return when {
isHighTwoByte(resId, IS_ICON_PACK) -> {
param.args[0] = withHighByteSet(resId, ANDROID_DEFAULT)
getCip()?.getPackIcon(param.args[0] as Int, density) ?: callOriginalMethod(param)
}
isHighTwoByte(resId, IN_CIP) -> {
val id = withHighByteSet(resId, CIP_DEFAULT)
// Original id has been lost
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/com/richardluo/globalIconPack/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ infix fun String.rEqual(other: String): Boolean {
return true
}

infix fun String.nREqual(other: String) = !rEqual(other)
infix fun String.rNEqual(other: String) = !rEqual(other)

fun <T> Array<T>.rGet(i: Int) = this[if (i >= 0) i else size + i]

Expand Down

0 comments on commit 41b957a

Please sign in to comment.