Skip to content

Commit

Permalink
Fix RestoreNearbyTile for HyperOS
Browse files Browse the repository at this point in the history
  • Loading branch information
YifePlayte committed Oct 30, 2023
1 parent 6bca96c commit e0fbfe8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ android {

dependencies {
compileOnly("de.robv.android.xposed:api:82")
implementation("com.github.kyuubiran:EzXHelper:2.0.7")
implementation("com.github.kyuubiran:EzXHelper:2.0.8")
implementation("org.luckypray:DexKit:1.1.8")
implementation(project(":blockmiui"))
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.yifeplayte.wommo.hook.hooks.singlepackage.systemui

import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.ClassUtils.setStaticObject
import com.github.kyuubiran.ezxhelper.HookFactory
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.yifeplayte.wommo.hook.hooks.BaseHook
import com.yifeplayte.wommo.utils.Build.IS_INTERNATIONAL_BUILD
import java.lang.reflect.Method

object RestoreNearbyTile : BaseHook() {
override val key = "restore_near_by_tile"
Expand All @@ -22,12 +24,14 @@ object RestoreNearbyTile : BaseHook() {
}
}

loadClass("com.android.systemui.qs.MiuiQSTileHostInjector").methodFinder().first {
name == "createMiuiTile"
}.createHook(isInternationalHook)
val hookSet = mutableSetOf<Method>()

loadClass("com.android.systemui.controlcenter.utils.ControlCenterUtils").methodFinder().first {
name == "filterCustomTile"
}.createHook(isInternationalHook)
loadClassOrNull("com.android.systemui.qs.MiuiQSTileHostInjector")?.methodFinder()
?.filterByName("createMiuiTile")?.toList()?.let { hookSet.addAll(it) }

loadClassOrNull("com.android.systemui.controlcenter.utils.ControlCenterUtils")?.methodFinder()
?.filterByName("filterCustomTile")?.toList()?.let { hookSet.addAll(it) }

hookSet.createHooks(isInternationalHook)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.yifeplayte.wommo.hook.hooks.subpackage
import android.content.pm.ApplicationInfo
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.ObjectHelper.Companion.objectHelper
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.yifeplayte.wommo.hook.hooks.BaseSubPackage
import com.yifeplayte.wommo.hook.hooks.subpackage.systemuiplugin.RestoreNearbyTile
import com.yifeplayte.wommo.utils.Build.IS_HYPER_OS
import de.robv.android.xposed.XC_MethodHook.Unhook

object SystemUIPlugin : BaseSubPackage() {
Expand All @@ -16,15 +18,34 @@ object SystemUIPlugin : BaseSubPackage() {
)
var hook: Unhook? = null
override fun initClassLoader() {
hook = loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory").methodFinder()
.filterByName("getClassLoader")
.filterByAssignableParamTypes(ApplicationInfo::class.java, ClassLoader::class.java)
.first().createHook {
after { param ->
if ((param.args[0] as ApplicationInfo).packageName != subPackageName) return@after
safeSubClassLoader = param.result as? ClassLoader ?: return@after
hook?.unhook()
}
}
if (IS_HYPER_OS) {
hook =
loadClass("com.android.systemui.shared.plugins.PluginInstance\$PluginFactory").declaredConstructors.first()
.createHook {
before { param ->
val appInfo = param.args[2] as ApplicationInfo
if (appInfo.packageName != subPackageName) return@before
val pathClassLoader =
param.args[6].objectHelper().invokeMethodBestMatch("get")
safeSubClassLoader = pathClassLoader as? ClassLoader ?: return@before
hook?.unhook()
}
}
} else {
hook =
loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory").methodFinder()
.filterByName("getClassLoader")
.filterByAssignableParamTypes(
ApplicationInfo::class.java,
ClassLoader::class.java
)
.first().createHook {
after { param ->
if ((param.args[0] as ApplicationInfo).packageName != subPackageName) return@after
safeSubClassLoader = param.result as? ClassLoader ?: return@after
hook?.unhook()
}
}
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/yifeplayte/wommo/utils/Build.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yifeplayte.wommo.utils

import com.github.kyuubiran.ezxhelper.ClassHelper.Companion.classHelper
import com.github.kyuubiran.ezxhelper.ClassUtils.getStaticObjectOrNullAs
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass

Expand All @@ -11,6 +12,10 @@ object Build {
loadClass("miui.os.Build")
}

private val clazzSystemProperties by lazy {
loadClass("android.os.SystemProperties")
}

/**
* 设备是否为平板
*/
Expand All @@ -24,4 +29,12 @@ object Build {
val IS_INTERNATIONAL_BUILD by lazy {
getStaticObjectOrNullAs<Boolean>(clazzMiuiBuild, "IS_INTERNATIONAL_BUILD") ?: false
}

/**
* 是否为HyperOS
*/
val IS_HYPER_OS by lazy {
clazzSystemProperties.classHelper()
.invokeStaticMethodBestMatch("get", null, "ro.mi.os.version.code", null) != null
}
}

0 comments on commit e0fbfe8

Please sign in to comment.