Skip to content

Commit

Permalink
try to fix: clipboard list crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Dec 29, 2024
1 parent b827dd1 commit 8672ffd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
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 8672ffd

Please sign in to comment.