From ec2bfb78a134b3cbf33c7ae0201ced3f64aae775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=84=95=E6=99=A8HChen?= Date: Tue, 23 Jan 2024 23:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=91=B8=E4=B8=AA=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/hook/home/gesture/CornerSlide.java | 97 +++++++++++++++++++ .../module/hook/home/gesture/CornerSlide.kt | 62 ------------ .../hyperceiler/utils/ContextUtils.java | 15 ++- .../hyperceiler/utils/XposedUtils.java | 2 +- app/src/main/res/xml/home_multi_action.xml | 46 ++++----- 5 files changed, 135 insertions(+), 87 deletions(-) create mode 100644 app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.java delete mode 100644 app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.kt diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.java new file mode 100644 index 0000000000..f7cc4211d7 --- /dev/null +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.java @@ -0,0 +1,97 @@ +package com.sevtinge.hyperceiler.module.hook.home.gesture; + +import android.app.AndroidAppHelper; +import android.content.Context; +import android.os.Bundle; +import android.view.MotionEvent; + +import com.sevtinge.hyperceiler.module.app.GlobalActions; +import com.sevtinge.hyperceiler.module.base.BaseHook; + +import de.robv.android.xposed.XposedHelpers; + +public class CornerSlide extends BaseHook { + public int inDirection = 0; + + Context mContext; + + @Override + public void init() throws NoSuchMethodException { + findAndHookMethod("com.android.systemui.shared.recents.system.AssistManager", + "isSupportGoogleAssist", int.class, + MethodHook.returnConstant(true)); + Class FsGestureAssistHelper = findClassIfExists("com.miui.home.recents.FsGestureAssistHelper"); + findAndHookMethod(FsGestureAssistHelper, "canTriggerAssistantAction", + float.class, float.class, int.class, + new MethodHook() { + @Override + protected void before(MethodHookParam param) { + boolean isDisabled = (boolean) XposedHelpers.callStaticMethod(FsGestureAssistHelper, + "isAssistantGestureDisabled", param.args[2]); + if (!isDisabled) { + int mAssistantWidth = (int) XposedHelpers.getObjectField(param.thisObject, "mAssistantWidth"); + float f = (float) param.args[0]; + float f2 = (float) param.args[1]; + if (f < mAssistantWidth || f > f2 - mAssistantWidth) { + param.setResult(true); + return; + } + } + param.setResult(false); + } + } + ); + + // final int[] inDirection = {0}; + hookAllMethods(FsGestureAssistHelper, + "handleTouchEvent", new MethodHook() { + @Override + protected void after(MethodHookParam param) { + MotionEvent motionEvent = (MotionEvent) param.args[0]; + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { + float mDownX = XposedHelpers.getFloatField(param.thisObject, "mDownX"); + int mAssistantWidth = XposedHelpers.getIntField(param.thisObject, "mAssistantWidth"); + inDirection = mDownX < mAssistantWidth ? 0 : 1; + } + } + } + ); + + findAndHookConstructor("com.miui.home.recents.NavStubView", + Context.class, new MethodHook() { + @Override + protected void after(MethodHookParam param) { + mContext = (Context) param.args[0]; + } + } + ); + + findAndHookMethod("com.miui.home.recents.SystemUiProxyWrapper", + "startAssistant", Bundle.class, + new MethodHook() { + @Override + protected void before(MethodHookParam param) { + Bundle bundle = (Bundle) param.args[0]; + if (bundle.getInt("triggered_by", 0) != 83 || bundle.getInt("invocation_type", 0) != 1) { + return; + } + String direction = inDirection == 1 ? "right" : "left"; + GlobalActions.handleAction( + AndroidAppHelper.currentApplication(), + "prefs_key_home_navigation_assist_" + direction + "_slide" + ); + /*logE(TAG, "bundle: " + bundle+" rig: "+direction); + if (mPrefsMap.getInt("home_navigation_assist_" + direction + "_slide_action", 0) == 10) { + + ActivityManager.RunningTaskInfo runningTaskInfo = (ActivityManager.RunningTaskInfo) XposedHelpers.callMethod( + XposedHelpers.callStaticMethod(findClassIfExists("com.miui.home.recents.RecentsModel"), "getInstance", + mContext), "getRunningTaskContainHome"); + LockApp.needLockApp(mContext, runningTaskInfo, lpparam); + } else { + + }*/ + } + } + ); + } +} diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.kt deleted file mode 100644 index c4446c39ca..0000000000 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/CornerSlide.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.sevtinge.hyperceiler.module.hook.home.gesture - -import android.app.AndroidAppHelper -import android.os.Bundle -import android.view.MotionEvent -import android.view.View -import com.sevtinge.hyperceiler.module.app.GlobalActions -import com.sevtinge.hyperceiler.module.base.BaseHook -import com.sevtinge.hyperceiler.utils.callStaticMethod -import com.sevtinge.hyperceiler.utils.getFloatField -import com.sevtinge.hyperceiler.utils.getIntField -import com.sevtinge.hyperceiler.utils.log.XposedLogUtils -import de.robv.android.xposed.XC_MethodReplacement - -class CornerSlide : BaseHook() { - override fun init() { - findAndHookMethod( - "com.android.systemui.shared.recents.system.AssistManager", "isSupportGoogleAssist", Int::class.java, - XC_MethodReplacement.returnConstant(true), - ) - - val FsGestureAssistHelper = findClassIfExists("com.miui.home.recents.FsGestureAssistHelper") - findAndHookMethod(FsGestureAssistHelper, "canTriggerAssistantAction", Float::class.java, Float::class.java, Int::class.java, object : MethodHook() { - override fun before(param: MethodHookParam) { - val isDisabled = FsGestureAssistHelper.callStaticMethod("isAssistantGestureDisabled", param.args[2]) as Boolean - if (!isDisabled) { - val mAssistantWidth: Int = param.thisObject.getIntField("mAssistantWidth") - val f = param.args[0] as Float - val f2 = param.args[1] as Float - if (f < mAssistantWidth || f > f2 - mAssistantWidth) { - param.result = true - return - } - } - param.result = false - } - }) - - var inDirection = 0 - findAndHookMethod(FsGestureAssistHelper, "handleTouchEvent", MotionEvent::class.java, View::class.java, object : MethodHook() { - override fun after(param: MethodHookParam) { - val motionEvent = param.args[0] as MotionEvent - if (motionEvent.action == MotionEvent.ACTION_DOWN) { - val mDownX = param.thisObject.getFloatField("mDownX") - val mAssistantWidth = param.thisObject.getIntField("mAssistantWidth") - inDirection = if (mDownX < mAssistantWidth) 0 else 1 - } - } - }) - - findAndHookMethod("com.miui.home.recents.SystemUiProxyWrapper", "startAssistant", Bundle::class.java, object : MethodHook() { - override fun before(param: MethodHookParam) { - val bundle = param.args[0] as? Bundle - if (bundle?.getInt("triggered_by", 0) != 83 || bundle.getInt("invocation_type", 0) != 1) { - return - } - val direction = if (inDirection == 1) "right" else "left" - GlobalActions.handleAction(AndroidAppHelper.currentApplication(), "prefs_key_home_navigation_assist_${direction}_slide") - } - }) - } -} diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/ContextUtils.java b/app/src/main/java/com/sevtinge/hyperceiler/utils/ContextUtils.java index ef4c1d9f70..148c726e4a 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/utils/ContextUtils.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/ContextUtils.java @@ -4,14 +4,27 @@ import android.app.Application; import android.content.Context; +import androidx.annotation.IntDef; + import com.sevtinge.hyperceiler.utils.log.AndroidLogUtils; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Method; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @SuppressLint({"PrivateApi", "SoonBlockedPrivateApi", "DiscouragedPrivateApi"}) public class ContextUtils { + @IntDef(value = { + FLAG_ALL, + FLAG_CURRENT_APP, + FlAG_ONLY_ANDROID + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Duration { + } + private static final String TAG = "[HyperCeiler]"; // 尝试全部 public static final int FLAG_ALL = 0; @@ -20,7 +33,7 @@ public class ContextUtils { // 获取 Android 系统 public static final int FlAG_ONLY_ANDROID = 2; - public static Context getContext(int flag) { + public static Context getContext(@Duration int flag) { try { return invokeMethod(flag); } catch (Throwable e) { diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/XposedUtils.java b/app/src/main/java/com/sevtinge/hyperceiler/utils/XposedUtils.java index f5aa85b039..a89fbe74fb 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/utils/XposedUtils.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/XposedUtils.java @@ -62,7 +62,7 @@ public static synchronized Resources getModuleRes(Context context) throws Throwa return (config == null ? moduleContext.getResources() : moduleContext.createConfigurationContext(config).getResources()); } - public static Context findContext(int flag) { + public static Context findContext(@ContextUtils.Duration int flag) { Context context = null; try { switch (flag) { diff --git a/app/src/main/res/xml/home_multi_action.xml b/app/src/main/res/xml/home_multi_action.xml index 901eb97bdd..e7ecf50199 100644 --- a/app/src/main/res/xml/home_multi_action.xml +++ b/app/src/main/res/xml/home_multi_action.xml @@ -6,55 +6,55 @@ + android:layout="@layout/preference_radiobutton_two_state" + android:persistent="false" + android:title="@string/array_global_actions_none" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_notif" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_lock" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_sleep" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_screenshot" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_clear_memory" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_invert_colors" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_recents" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_volume" /> + android:layout="@layout/preference_radiobutton_two_state" + android:title="@string/array_global_actions_powermenu" /> @@ -63,9 +63,9 @@ android:title="@string/array_global_actions_launch" /> + android:title="@string/array_global_actions_launch_choose" />