From 2f1c2f7f4e603f75f0eb5b32bc934b44a01d50a1 Mon Sep 17 00:00:00 2001 From: hosizoraru Date: Sat, 16 Sep 2023 01:08:36 +0800 Subject: [PATCH] fix && Optimize --- .../hook/hooks/home/BlurWhenOpenFolder.kt | 81 +++++++----- .../DisableRecentViewWallpaperDarkening.kt | 1 + .../hooks/home/RecentViewRemoveCardAnim.kt | 125 +++++++++++------- .../hook/hooks/home/UseCompleteBlur.kt | 6 +- .../RemovePackageInstallerAds.kt | 36 +++-- .../hooks/systemui/LockScreenRemoveCamera.kt | 8 +- .../hook/hooks/systemui/ShowWifiStandard.kt | 27 ++-- 7 files changed, 157 insertions(+), 127 deletions(-) diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/BlurWhenOpenFolder.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/BlurWhenOpenFolder.kt index 403b6921..3b02098d 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/BlurWhenOpenFolder.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/BlurWhenOpenFolder.kt @@ -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") @@ -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 ) } @@ -54,28 +57,30 @@ 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 = @@ -83,8 +88,10 @@ object BlurWhenOpenFolder : HookRegister() { } 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 = @@ -92,12 +99,19 @@ object BlurWhenOpenFolder : HookRegister() { } 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 = @@ -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", diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/DisableRecentViewWallpaperDarkening.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/DisableRecentViewWallpaperDarkening.kt index 99fd0161..dff86fe2 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/DisableRecentViewWallpaperDarkening.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/DisableRecentViewWallpaperDarkening.kt @@ -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) } } } diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/RecentViewRemoveCardAnim.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/RecentViewRemoveCardAnim.kt index 8fa9ca5a..cd687428 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/RecentViewRemoveCardAnim.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/RecentViewRemoveCardAnim.kt @@ -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("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("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("mTaskViewHeight") + val mCurScale = + it.thisObject.objectHelper().getObjectOrNullAs("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 + ) + } + } } } \ No newline at end of file diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/UseCompleteBlur.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/UseCompleteBlur.kt index 7a27277c..636d828b 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/UseCompleteBlur.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/home/UseCompleteBlur.kt @@ -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 @@ -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) } } diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/packageinstaller/RemovePackageInstallerAds.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/packageinstaller/RemovePackageInstallerAds.kt index c6344446..1bcbdf13 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/packageinstaller/RemovePackageInstallerAds.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/packageinstaller/RemovePackageInstallerAds.kt @@ -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("getClContentView")?.visibility = + View.GONE } } - } catch (t: Throwable) { - letter++ - } } } } diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/LockScreenRemoveCamera.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/LockScreenRemoveCamera.kt index 6f0acd02..d633c67a 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/LockScreenRemoveCamera.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/LockScreenRemoveCamera.kt @@ -26,16 +26,12 @@ object LockScreenRemoveCamera : HookRegister() { .filterByName("onTouchMove") .filterByParamCount(2) .first().createHook { - before { - it.result = false - } + returnConstant(false) } loadClass("com.android.keyguard.KeyguardMoveRightController").methodFinder() .filterByName("reset") .first().createHook { - before { - it.result = null - } + returnConstant(null) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/ShowWifiStandard.kt b/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/ShowWifiStandard.kt index 4c230cc7..aef2d3a4 100644 --- a/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/ShowWifiStandard.kt +++ b/app/src/main/kotlin/star/sky/voyager/hook/hooks/systemui/ShowWifiStandard.kt @@ -2,6 +2,7 @@ package star.sky.voyager.hook.hooks.systemui import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass 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.getObjectFieldAs import star.sky.voyager.utils.api.setObjectField @@ -10,27 +11,19 @@ import star.sky.voyager.utils.key.hasEnable object ShowWifiStandard : HookRegister() { override fun init() = hasEnable("show_wifi_standard") { - val statusBarWifiViewClass = + val statusBarWifiViewCls = loadClass("com.android.systemui.statusbar.StatusBarWifiView") - val wifiIconStateClass = + val wifiIconStateCls = loadClass("com.android.systemui.statusbar.phone.StatusBarSignalPolicy\$WifiIconState") - statusBarWifiViewClass.methodFinder() - .filterByName("initViewState") - .filterByParamCount(1) - .first().createHook { - before { - copyTo(wifiIconStateClass) - } - } - statusBarWifiViewClass.methodFinder() - .filterByName("updateState") - .filterByParamCount(1) - .first().createHook { - before { - copyTo(wifiIconStateClass) - } + statusBarWifiViewCls.methodFinder().filter { + parameterCount == 1 && + name in setOf("initViewState", "updateState") + }.toList().createHooks { + before { + copyTo(wifiIconStateCls) } + } } private fun copyTo(wifiIconStateClass: Class<*>) {