Skip to content

Commit

Permalink
修复崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
Justwen committed Oct 7, 2021
1 parent 2e31a1d commit 13bc5da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
import com.alibaba.android.arouter.launcher.ARouter;
import com.justwen.androidnga.cloud.CloudServerManager;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

import gov.anzong.androidnga.base.util.ContextUtils;
import gov.anzong.androidnga.base.util.PreferenceUtils;
import gov.anzong.androidnga.base.util.ThreadUtils;
import gov.anzong.androidnga.common.PreferenceKey;
import gov.anzong.androidnga.common.util.ReflectUtils;
import sp.phone.common.FilterKeywordsManagerImpl;
Expand Down Expand Up @@ -38,10 +44,31 @@ public void onCreate() {
}

private void fixWebViewMultiProcessException() {
int index = PreferenceUtils.getData(PreferenceKey.KEY_WEBVIEW_DATA_INDEX, 0);
if (index > 0) {
WebView.setDataDirectorySuffix(String.valueOf(index));
File dataDir = getDataDir();
File[] dirs = dataDir.listFiles();

Object ppidObj = ReflectUtils.invokeMethod(Process.class, "myPpid");

int ppid = ppidObj != null ? (int) ppidObj : Process.myPid();

if (dirs != null) {
for (File dir : dirs) {
if (dir.getName().contains("webview")) {
if (!dir.getName().contains("webview_" + ppid)){
ThreadUtils.postOnSubThread(() -> {
try {
FileUtils.deleteDirectory(dir);
} catch (IOException e) {
e.printStackTrace();
}
});

}
}
}
}

WebView.setDataDirectorySuffix(String.valueOf(ppid));
}

private void initRouter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void appendData(List<E> dataList) {
if (mDataList == null) {
mDataList = new ArrayList<>();
}

for (E e : dataList) {
List<E> newDataList = new ArrayList<>(dataList);
for (E e : newDataList) {
if (!mDataList.contains(e)) {
mDataList.add(e);
}
Expand Down

0 comments on commit 13bc5da

Please sign in to comment.