Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan095 committed Dec 29, 2024
2 parents 7bd3233 + 8672ffd commit 5ad1a1b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@
*/
public class QuickBack extends BaseHC {
private static final HashMap<String, Integer> mResMap = new HashMap<>();
private static int[] values = null;

@Override
protected void init() {
try {
Class<?> mReadyStateClass = findClass("com.miui.home.recents.GestureBackArrowView$ReadyState").get();
Enum<?> READY_STATE_BACK = (Enum<?>) getStaticField(mReadyStateClass, "READY_STATE_BACK");
Enum<?> READY_STATE_RECENT = (Enum<?>) getStaticField(mReadyStateClass, "READY_STATE_RECENT");
Enum<?> READY_STATE_NONE = (Enum<?>) getStaticField(mReadyStateClass, "READY_STATE_NONE");
values = new int[((Object[]) callStaticMethod(mReadyStateClass, "values")).length];
values[READY_STATE_BACK.ordinal()] = 1;
values[READY_STATE_RECENT.ordinal()] = 2;
values[READY_STATE_NONE.ordinal()] = 3;
} catch (Throwable e) {
logE(TAG, e);
}

hookMethod("com.miui.home.recents.GestureStubView",
"isDisableQuickSwitch",
returnResult(false)
Expand All @@ -60,8 +74,16 @@ public void before() {
Object getCurrentState = callMethod(mGestureBackArrowView, "getCurrentState");

int ordinal = (int) callMethod(getCurrentState, "ordinal");
int[] mState = (int[]) getStaticField("com.miui.home.recents.GestureStubView$4", "$SwitchMap$com$miui$home$recents$GestureBackArrowView$ReadyState");
ordinal = mState[ordinal];
if (values == null) {
Class<?> mGestureStubView$X = existsClass("com.miui.home.recents.GestureStubView$4") ?
findClass("com.miui.home.recents.GestureStubView$4").get()
: findClass("com.miui.home.recents.GestureStubView$5").get();
int[] mState = (int[]) getStaticField(mGestureStubView$X, "$SwitchMap$com$miui$home$recents$GestureBackArrowView$ReadyState");
ordinal = mState[ordinal];

} else
ordinal = values[ordinal];

if (ordinal == 2) {
callMethod(mGestureStubView, "onBackCancelled");
logI(TAG, "call onBackCancelled");
Expand All @@ -84,69 +106,65 @@ public void before() {
Object createLoadPlan = callMethod(taskLoader, "createLoadPlan", context);
callMethod(taskLoader, "preloadTasks", createLoadPlan, -1);
Object taskStack = callMethod(createLoadPlan, "getTaskStack");
ActivityOptions activityOptions = null;

if (taskStack == null || (int) callMethod(taskStack, "getTaskCount") == 0 ||
(runningTask = (ActivityManager.RunningTaskInfo) callMethod(recentsModel, "getRunningTask")) == null) {
setResult(null);
setResult(null); // 后台无其他任务
return;
}

ArrayList<?> stackTasks = (ArrayList<?>) callMethod(taskStack, "getStackTasks");
int size = stackTasks.size();
Object task = null;
int i2 = 0;
while (true) {
if (i2 >= size - 1) {
for (int i = 0; i < stackTasks.size() - 1; i++) {
Object t = stackTasks.get(i);
if ((int) getField(getField(t, "key"), "id") == runningTask.id) {
task = stackTasks.get(i + 1);
break;
} else if ((int) getField(getField(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())) {
if (task == null && !stackTasks.isEmpty() && "com.miui.home".equals(runningTask.baseActivity.getPackageName())) {
task = stackTasks.get(0);
}

if (task != null && getField(task, "icon") == null) {
setField(task, "icon", callMethod(taskLoader, "getAndUpdateActivityIcon",
getField(task, "key"),
getField(task, "taskDescription"),
context.getResources(), true
));
setField(task, "icon",
callMethod(taskLoader, "getAndUpdateActivityIcon",
getField(task, "key"),
getField(task, "taskDescription"),
context.getResources(),
true
)
);
}
if (!(boolean) getArgs(1) || task == null) {
setResult(task);
return;
}
int i = (int) getArgs(2);
if (i == 0) {

ActivityOptions activityOptions = null;
int mGestureStubPos = (int) getArgs(2);
if (mGestureStubPos == 0) {
activityOptions = ActivityOptions.makeCustomAnimation(context,
getAnimId(context, "recents_quick_switch_left_enter"),
getAnimId(context, "recents_quick_switch_left_exit"));
} else if (i == 1) {
} else if (mGestureStubPos == 1) {
activityOptions = ActivityOptions.makeCustomAnimation(context,
getAnimId(context, "recents_quick_switch_right_enter"),
getAnimId(context, "recents_quick_switch_right_exit"));
}
Object iActivityManager = callStaticMethod("android.app.ActivityManagerNative", "getDefault");
if (iActivityManager != null) {
try {
if ((int) getField(getField(task, "key"), "windowingMode") == 3) {
if (activityOptions == null) {
activityOptions = ActivityOptions.makeBasic();
}
activityOptions.getClass().getMethod("setLaunchWindowingMode", Integer.class).invoke(activityOptions, 4);
if ((int) getField(getField(task, "key"), "windowingMode") == 3) {
if (activityOptions == null) {
activityOptions = ActivityOptions.makeBasic();
}
callMethod(iActivityManager, "startActivityFromRecents",
getField(getField(task, "key"), "id"),
activityOptions == null ? null : activityOptions.toBundle());
setResult(task);
return;
} catch (Exception e) {
logE(TAG, "Error: " + e);
setResult(task);
return;
callMethod(activityOptions, "setLaunchWindowingMode", 4);
}
callMethod(iActivityManager, "startActivityFromRecents",
getField(getField(task, "key"), "id"),
activityOptions == null ? null : activityOptions.toBundle());
setResult(task);
return;
}
setResult(task);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void init() {
@Override
protected void after(MethodHookParam param) {
// logE(TAG, "get class: " + param.args[0]);
filePath = "/data/user/0/" + lpparam.packageName + "/files/clipboard_data.dat";
lastFilePath = "/data/user/0/" + lpparam.packageName + "/files/last_clipboard_data_list.dat";
filePath = lpparam.appInfo.dataDir + "/files/clipboard_data.dat";
lastFilePath = lpparam.appInfo.dataDir + "/files/last_clipboard_data_list.dat";
// logE(TAG, "run: " + param.args[0]);
getNoExpiredData((ClassLoader) param.args[0]);
getView((ClassLoader) param.args[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@

package com.sevtinge.hyperceiler.module.hook.various.clipboard;

import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logD;
import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;
import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logI;
import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logW;

import android.content.ClipData;
import android.content.Context;
import android.net.Uri;
Expand All @@ -38,10 +33,16 @@
import com.hchen.hooktool.tool.ParamTool;
import com.sevtinge.hyperceiler.utils.ContentModel;
import com.sevtinge.hyperceiler.utils.FileHelper;
import com.sevtinge.hyperceiler.utils.log.XposedLogUtils;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.stream.Collectors;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;

/**
* 解除常用语剪贴板时间限制,条数限制和字数限制。
* from <a href="https://github.com/HChenX/ClipboardList">ClipboardList</a>
Expand All @@ -60,11 +61,11 @@ public class NewClipboardList extends BaseHC implements LoadInputMethodDex.OnInp
public void load(ClassLoader classLoader) {
mGson = new GsonBuilder().setPrettyPrinting().create();
mDataPath = lpparam.appInfo.dataDir + "/files/clipboard_data.dat";
logI(TAG, "class loader: " + classLoader);
XposedLogUtils.logI(TAG, "class loader: " + classLoader);

FileHelper.TAG = TAG;
if (!FileHelper.exists(mDataPath)) {
logE(TAG, "file create failed!");
XposedLogUtils.logE(TAG, "file create failed!");
return;
}

Expand Down Expand Up @@ -193,6 +194,23 @@ public void before() {
}
})
);
XposedHelpers.findAndHookMethod("com.miui.inputmethod.MiuiClipboardManager", classLoader, "buildClipboardModelDataType", "com.miui.inputmethod.ClipboardContentModel", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
final boolean[] isSkip = {false};
XposedHelpers.findAndHookConstructor(JSONArray.class, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String json = (String) param.args[0];
if (TextUtils.isEmpty(json) || json == null) {
isSkip[0] = true;
XposedLogUtils.logW(TAG, lpparam.packageName, "Got null string, skip run. String = " + param.args[0]);
}
}
});
if (isSkip[0]) param.setResult(null);
}
});

}

Expand Down Expand Up @@ -222,7 +240,7 @@ private void addClipboard(String add, int type, Context context) {
}
ArrayList<ContentModel> readData = toContentModelList(FileHelper.read(mDataPath));
if (readData.isEmpty()) {
logW(TAG, "can't read any data!");
XposedLogUtils.logW(TAG, "can't read any data!");
} else {
if (readData.stream().anyMatch(contentModel -> contentModel.content.equals(add))) {
readData.removeIf(contentModel -> contentModel.content.equals(add));
Expand Down

0 comments on commit 5ad1a1b

Please sign in to comment.