Skip to content

Commit

Permalink
fix && Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
hosizoraru committed Sep 15, 2023
1 parent a8b9253 commit 2f1c2f7
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import star.sky.voyager.utils.key.hasEnable

object BlurWhenOpenFolder : HookRegister() {
override fun init() = hasEnable("home_blur_when_open_folder") {
val folderInfo = loadClass("com.miui.home.launcher.FolderInfo")
val launcherClass = loadClass("com.miui.home.launcher.Launcher")
val blurUtilsClass = loadClass("com.miui.home.launcher.common.BlurUtils")
val navStubViewClass = loadClass("com.miui.home.recents.NavStubView")
val folderInfo =
loadClass("com.miui.home.launcher.FolderInfo")
val launcherClass =
loadClass("com.miui.home.launcher.Launcher")
val blurUtilsClass =
loadClass("com.miui.home.launcher.common.BlurUtils")
val navStubViewClass =
loadClass("com.miui.home.recents.NavStubView")
val applicationClass =
loadClass("com.miui.home.launcher.Application")

Expand All @@ -38,13 +42,12 @@ object BlurWhenOpenFolder : HookRegister() {
var isShouldBlur = false

launcherClass.hookAfterMethod("openFolder", folderInfo, View::class.java) {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val isInNormalEditing = mLauncher.callMethod("isInNormalEditing") as Boolean
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInNormalEditing =
mLauncher.callMethod("isInNormalEditing") as Boolean
if (!isInNormalEditing) blurUtilsClass.callStaticMethod(
"fastBlur",
1.0f,
mLauncher.window,
true
"fastBlur", 1.0f, mLauncher.window, true
)
}

Expand All @@ -54,50 +57,61 @@ object BlurWhenOpenFolder : HookRegister() {

launcherClass.hookAfterMethod("closeFolder", Boolean::class.java) {
isShouldBlur = false
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val isInNormalEditing = mLauncher.callMethod("isInNormalEditing") as Boolean
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInNormalEditing =
mLauncher.callMethod("isInNormalEditing") as Boolean
if (isInNormalEditing) blurUtilsClass.callStaticMethod(
"fastBlur",
1.0f,
mLauncher.window,
true,
0L
"fastBlur", 1.0f, mLauncher.window, true, 0L
) else blurUtilsClass.callStaticMethod(
"fastBlur", 0.0f, mLauncher.window, true
)
else blurUtilsClass.callStaticMethod("fastBlur", 0.0f, mLauncher.window, true)
}

launcherClass.hookBeforeMethod("onGesturePerformAppToHome") {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
if (isShouldBlur) {
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
}
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
if (isShouldBlur) blurUtilsClass.callStaticMethod(
"fastBlur", 1.0f, mLauncher.window, true, 0L
)
}

blurUtilsClass.hookBeforeAllMethods("fastBlurWhenStartOpenOrCloseApp") {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing = mLauncher.callMethod("isInEditing") as Boolean
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing =
mLauncher.callMethod("isInEditing") as Boolean
if (isShouldBlur) it.result =
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
else if (isInEditing) it.result =
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
}

blurUtilsClass.hookBeforeAllMethods("fastBlurWhenFinishOpenOrCloseApp") {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing = mLauncher.callMethod("isInEditing") as Boolean
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing =
mLauncher.callMethod("isInEditing") as Boolean
if (isShouldBlur) it.result =
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
else if (isInEditing) it.result =
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
}

blurUtilsClass.hookAfterAllMethods("fastBlurWhenEnterRecents") {
it.args[0]?.callMethod("hideShortcutMenuWithoutAnim")
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInShortcutMenuState =
mLauncher.callMethod("isInShortcutMenuState") as Boolean
if (isInShortcutMenuState)
mLauncher.callMethod("hideShortcutMenuWithoutAnim")
}

blurUtilsClass.hookAfterAllMethods("fastBlurWhenExitRecents") {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing = mLauncher.callMethod("isInEditing") as Boolean
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val isInEditing =
mLauncher.callMethod("isInEditing") as Boolean
if (isShouldBlur) it.result =
blurUtilsClass.callStaticMethod("fastBlur", 1.0f, mLauncher.window, true, 0L)
else if (isInEditing) it.result =
Expand All @@ -112,9 +126,12 @@ object BlurWhenOpenFolder : HookRegister() {
hasEnable("home_use_complete_blur") {
hasEnable("home_complete_blur_fix") {
navStubViewClass.hookBeforeMethod("onPointerEvent", MotionEvent::class.java) {
val mLauncher = applicationClass.callStaticMethod("getLauncher") as Activity
val motionEvent = it.args[0] as MotionEvent
val action = motionEvent.action
val mLauncher =
applicationClass.callStaticMethod("getLauncher") as Activity
val motionEvent =
it.args[0] as MotionEvent
val action =
motionEvent.action
if (action == 2) Thread.currentThread().priority = 10
if (action == 2 && isShouldBlur) blurUtilsClass.callStaticMethod(
"fastBlurDirectly",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object DisableRecentViewWallpaperDarkening : HookRegister() {
before {
it.args[0] = 0.0f
it.thisObject.setObjectField("mCurrentAlpha", 0.0f)
// it.thisObject.objectHelper().setObject("mCurrentAlpha", 0.0f)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,103 @@ import android.view.MotionEvent
import android.view.View
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.EzXHelper.classLoader
import de.robv.android.xposed.XposedHelpers.newInstance
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 star.sky.voyager.utils.api.callMethod
import star.sky.voyager.utils.api.callStaticMethod
import star.sky.voyager.utils.api.getObjectField
import star.sky.voyager.utils.api.getObjectFieldOrNullAs
import star.sky.voyager.utils.api.hookAfterMethod
import star.sky.voyager.utils.api.new
import star.sky.voyager.utils.api.replaceMethod
import star.sky.voyager.utils.api.setObjectField
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable

object RecentViewRemoveCardAnim : HookRegister() {
override fun init() = hasEnable("home_recent_view_remove_card_animation") {
"com.miui.home.recents.views.SwipeHelperForRecents".hookAfterMethod(
classLoader,
"onTouchEvent",
MotionEvent::class.java
) {
val mCurrView = it.thisObject.getObjectFieldOrNullAs<View>("mCurrView")
mCurrView?.let {
mCurrView.alpha = 1f
mCurrView.scaleX = 1f
mCurrView.scaleY = 1f
val swipeHelperForRecentsCls =
loadClass("com.miui.home.recents.views.SwipeHelperForRecents")
val taskStackViewLayoutStyleHorizontalCls =
loadClass("com.miui.home.recents.TaskStackViewLayoutStyleHorizontal")
val deviceConfigCls =
loadClass("com.miui.home.launcher.DeviceConfig")
val physicBasedInterpolatorCls =
loadClass("com.miui.home.launcher.anim.PhysicBasedInterpolator")
val verticalSwipeCls =
loadClass("com.miui.home.recents.views.VerticalSwipe")

swipeHelperForRecentsCls.methodFinder()
.filterByName("onTouchEvent")
.filterByParamTypes(MotionEvent::class.java)
.first().createHook {
after {
val mCurrView =
it.thisObject.objectHelper()
.getObjectOrNullUntilSuperclassAs<View>("mCurrView")
mCurrView?.let {
mCurrView.alpha *= 0.9f + 0.1f
mCurrView.scaleX = 1f
mCurrView.scaleY = 1f
}
}
}
}

"com.miui.home.recents.TaskStackViewLayoutStyleHorizontal".replaceMethod(
classLoader,
"createScaleDismissAnimation",
View::class.java,
Float::class.java
) {
val view = it.args[0] as View
val getScreenHeight = loadClass("com.miui.home.launcher.DeviceConfig")
.callStaticMethod("getScreenHeight") as Int
val view =
it.args[0] as View
val getScreenHeight =
deviceConfigCls
.callStaticMethod("getScreenHeight") as Int
val ofFloat = ObjectAnimator.ofFloat(
view,
View.TRANSLATION_Y,
view.translationY,
-getScreenHeight * 1.1484375f
)
val physicBasedInterpolator = newInstance(
loadClass("com.miui.home.launcher.anim.PhysicBasedInterpolator"),
0.9f,
0.78f
)
ofFloat.interpolator = physicBasedInterpolator as TimeInterpolator
ofFloat.duration = 400
val physicBasedInterpolator =
physicBasedInterpolatorCls.new(0.72f, 0.72f) as TimeInterpolator
ofFloat.interpolator = physicBasedInterpolator
ofFloat.duration = 450L
return@replaceMethod ofFloat
}
"com.miui.home.recents.views.VerticalSwipe".hookAfterMethod(
classLoader,
"calculate",
Float::class.java
) {
val f = it.args[0] as Float
val asScreenHeightWhenDismiss =
loadClass("com.miui.home.recents.views.VerticalSwipe")
.callStaticMethod("getAsScreenHeightWhenDismiss") as Int
val f2 = f / asScreenHeightWhenDismiss
val mTaskViewHeight = it.thisObject.getObjectField("mTaskViewHeight") as Float
val mCurScale = it.thisObject.getObjectField("mCurScale") as Float
val f3: Float = mTaskViewHeight * mCurScale
val i = if (f2 > 0.0f) 1 else if (f2 == 0.0f) 0 else -1
val afterFrictionValue: Float = it.thisObject.callMethod(
"afterFrictionValue",
f,
asScreenHeightWhenDismiss
) as Float
if (i < 0) it.thisObject.setObjectField(
"mCurTransY",
(mTaskViewHeight / 2.0f + afterFrictionValue * 2) - (f3 / 2.0f)
)
}

verticalSwipeCls.methodFinder()
.filterByName("calculate")
.filterByParamTypes(Float::class.java)
.first().createHook {
after {
val f =
it.args[0] as Float
val asScreenHeightWhenDismiss =
verticalSwipeCls
.callStaticMethod("getAsScreenHeightWhenDismiss") as Int
val f2 =
f / asScreenHeightWhenDismiss
val mTaskViewHeight =
it.thisObject.objectHelper().getObjectOrNullAs<Float>("mTaskViewHeight")
val mCurScale =
it.thisObject.objectHelper().getObjectOrNullAs<Float>("mCurScale")
val f3: Float =
mTaskViewHeight!! * mCurScale!!
val i =
if (f2 > 0.0f) 1 else if (f2 == 0.0f) 0 else -1
val afterFrictionValue: Float =
it.thisObject.callMethod(
"afterFrictionValue", f, asScreenHeightWhenDismiss
) as Float
if (i < 0) it.thisObject.objectHelper().setObject(
"mCurTransY",
(mTaskViewHeight / 2f + afterFrictionValue * 2f) - (f3 / 2f)
)
it.thisObject.objectHelper().setObject(
"mCurAlpha",
it.thisObject.objectHelper()
.getObjectOrNull("mCurAlpha") as Float * 0.9f + 0.1f
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.view.MotionEvent
import com.github.kyuubiran.ezxhelper.ClassUtils.invokeStaticMethodBestMatch
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 star.sky.voyager.utils.api.callStaticMethod
import star.sky.voyager.utils.api.getObjectField
import star.sky.voyager.utils.api.hookBeforeMethod
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable
Expand All @@ -29,7 +29,9 @@ object UseCompleteBlur : HookRegister() {
val motionEvent = it.args[0] as MotionEvent
val action = motionEvent.action
if (action == 2) Thread.currentThread().priority = 10
if (it.thisObject.getObjectField("mWindowMode") == 2 && action == 2) {
if (it.thisObject.objectHelper()
.getObjectOrNull("mWindowMode") == 2 && action == 2
) {
blurUtilsClass.callStaticMethod("fastBlurDirectly", 1.0f, mLauncher.window)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
package star.sky.voyager.hook.hooks.packageinstaller

import android.view.View
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
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 star.sky.voyager.utils.api.setBooleanField
import star.sky.voyager.utils.api.callMethodOrNullAs
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable

object RemovePackageInstallerAds : HookRegister() {
override fun init() = hasEnable("package_installer_remove_ads") {
val miuiSettingsCompatClass =
loadClassOrNull("com.android.packageinstaller.compat.MiuiSettingsCompat")!!
loadClassOrNull("com.android.packageinstaller.compat.MiuiSettingsCompat")
val mSafeModeTipViewObjectCls =
loadClassOrNull("com.miui.packageInstaller.ui.listcomponets.SafeModeTipViewObject")
val mSafeModeTipViewObjectViewHolderCls =
loadClassOrNull("com.miui.packageInstaller.ui.listcomponets.SafeModeTipViewObject\$ViewHolder")

runCatching {
miuiSettingsCompatClass.methodFinder()
miuiSettingsCompatClass!!.methodFinder()
.filterByName("isPersonalizedAdEnabled")
.filterByReturnType(Boolean::class.java)
.toList().createHooks {
before {
it.result = false
}
returnConstant(false)
}
}

var letter = 'a'
for (i in 0..25) {
try {
val classIfExists =
loadClassOrNull("com.miui.packageInstaller.ui.listcomponets.${letter}0")
classIfExists?.let {
it.methodFinder().filterByName("a").first().createHook {
after { hookParam ->
hookParam.thisObject.setBooleanField("l", false)
}
runCatching {
mSafeModeTipViewObjectCls!!.methodFinder()
.filterByParamTypes(mSafeModeTipViewObjectViewHolderCls)
.toList().createHooks {
after {
it.args[0].callMethodOrNullAs<View>("getClContentView")?.visibility =
View.GONE
}
}
} catch (t: Throwable) {
letter++
}
}
}
}
Loading

0 comments on commit 2f1c2f7

Please sign in to comment.