-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from HChenX/main
[新增] 快速切换上一个应用
- Loading branch information
Showing
6 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/gesture/QuickBack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.sevtinge.hyperceiler.module.hook.home.gesture; | ||
|
||
import android.app.ActivityManager; | ||
import android.app.ActivityOptions; | ||
import android.content.Context; | ||
|
||
import com.sevtinge.hyperceiler.module.base.BaseHook; | ||
|
||
import java.util.ArrayList; | ||
|
||
import de.robv.android.xposed.XposedHelpers; | ||
|
||
public class QuickBack extends BaseHook { | ||
@Override | ||
public void init() { | ||
findAndHookMethod("com.miui.home.recents.GestureStubView", | ||
"isDisableQuickSwitch", new MethodHook() { | ||
@Override | ||
protected void before(MethodHookParam param) { | ||
param.setResult(false); | ||
} | ||
} | ||
); | ||
|
||
findAndHookMethod("com.miui.home.recents.GestureStubView", | ||
"getNextTask", Context.class, boolean.class, int.class, | ||
new MethodHook() { | ||
@Override | ||
protected void before(MethodHookParam param) { | ||
Context context = (Context) param.args[0]; | ||
ActivityManager.RunningTaskInfo runningTask; | ||
Object recentsModel = XposedHelpers.callStaticMethod(findClass("com.miui.home.recents.RecentsModel"), "getInstance", context); | ||
Object taskLoader = XposedHelpers.callMethod(recentsModel, "getTaskLoader"); | ||
Object createLoadPlan = XposedHelpers.callMethod(taskLoader, "createLoadPlan", context); | ||
XposedHelpers.callMethod(taskLoader, "preloadTasks", createLoadPlan, -1); | ||
Object taskStack = XposedHelpers.callMethod(createLoadPlan, "getTaskStack"); | ||
ActivityOptions activityOptions = null; | ||
if (taskStack == null || (int) XposedHelpers.callMethod(taskStack, "getTaskCount") == 0 || (runningTask = (ActivityManager.RunningTaskInfo) XposedHelpers.callMethod(recentsModel, "getRunningTask")) == null) { | ||
param.setResult(null); | ||
return; | ||
} | ||
ArrayList<?> stackTasks = (ArrayList<?>) XposedHelpers.callMethod(taskStack, "getStackTasks"); | ||
int size = stackTasks.size(); | ||
Object task = null; | ||
int i2 = 0; | ||
while (true) { | ||
if (i2 >= size - 1) { | ||
break; | ||
} else if ((int) XposedHelpers.getObjectField(XposedHelpers.getObjectField(stackTasks.get(i2), "key"), "id") == runningTask.id) { | ||
task = stackTasks.get(i2 + 1); | ||
break; | ||
} else { | ||
i2++; | ||
} | ||
} | ||
if (task == null && size >= 1 && "com.miui.home".equals(runningTask.baseActivity.getPackageName())) { | ||
task = stackTasks.get(0); | ||
} | ||
if (task != null && XposedHelpers.getObjectField(task, "icon") == null) { | ||
XposedHelpers.setObjectField(task, "icon", XposedHelpers.callMethod(taskLoader, "getAndUpdateActivityIcon", | ||
XposedHelpers.getObjectField(task, "key"), | ||
XposedHelpers.getObjectField(task, "taskDescription"), | ||
context.getResources(), true | ||
)); | ||
} | ||
if (!(boolean) param.args[1] || task == null) { | ||
param.setResult(task); | ||
return; | ||
} | ||
int i = (int) param.args[2]; | ||
if (i == 0) { | ||
activityOptions = ActivityOptions.makeCustomAnimation(context, | ||
(int) XposedHelpers.callStaticMethod( | ||
findClass("com.miui.home.recents.GestureStubView"), | ||
"getAnimId", context, "recents_quick_switch_left_enter"), | ||
(int) XposedHelpers.callStaticMethod( | ||
findClass("com.miui.home.recents.GestureStubView"), | ||
"getAnimId", context, "recents_quick_switch_left_exit")); | ||
} else if (i == 1) { | ||
activityOptions = ActivityOptions.makeCustomAnimation(context, | ||
(int) XposedHelpers.callStaticMethod( | ||
findClass("com.miui.home.recents.GestureStubView"), | ||
"getAnimId", context, "recents_quick_switch_right_enter"), | ||
(int) XposedHelpers.callStaticMethod( | ||
findClass("com.miui.home.recents.GestureStubView"), | ||
"getAnimId", context, "recents_quick_switch_right_exit")); | ||
} | ||
Object iActivityManager = XposedHelpers.callStaticMethod(findClass("android.app.ActivityManagerNative"), "getDefault"); | ||
if (iActivityManager != null) { | ||
try { | ||
if ((int) XposedHelpers.getObjectField(XposedHelpers.getObjectField(task, "key"), "windowingMode") == 3) { | ||
if (activityOptions == null) { | ||
activityOptions = ActivityOptions.makeBasic(); | ||
} | ||
activityOptions.getClass().getMethod("setLaunchWindowingMode", Integer.class).invoke(activityOptions, 4); | ||
} | ||
XposedHelpers.callMethod(iActivityManager, "startActivityFromRecents", | ||
XposedHelpers.getObjectField( | ||
XposedHelpers.getObjectField(task, "key"), | ||
"id"), | ||
activityOptions == null ? null : activityOptions.toBundle()); | ||
param.setResult(task); | ||
return; | ||
} catch (Exception e) { | ||
logE(TAG, "Error :" + e); | ||
param.setResult(task); | ||
return; | ||
} | ||
} | ||
param.setResult(task); | ||
} | ||
} | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters