Skip to content

Commit

Permalink
opt: clear dexkit cache when pkg update.
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Dec 12, 2024
1 parent 6d98560 commit 913ab68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.sevtinge.hyperceiler.module.base.dexkit;

import static com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionCode;
import static com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionName;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;

import android.content.Context;
Expand Down Expand Up @@ -47,6 +49,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -91,12 +94,21 @@ public static DexKitBridge initDexkitBridge() {
// 启动 MMKV
MMKV.initialize(mmkvPath, System::loadLibrary);
mMMKV = MMKV.defaultMMKV();

// 检查阶段
int version = mMMKV.getInt("version", 0);
if (version != 0 && version != mVersion) {
mMMKV.clearAll();
}
mMMKV.putInt("version", mVersion);

String pkgVersion = getPackageVersionName(mParam) + "(" + getPackageVersionCode(mParam) + ")";
String oldPkgVersion = mMMKV.getString("pkgVersion", "null");
if (!Objects.equals(pkgVersion, oldPkgVersion)) {
mMMKV.clearAll();
}
mMMKV.putString("pkgVersion", pkgVersion);

// 启动 DexKit
System.loadLibrary("dexkit");
mDexKitBridge = DexKitBridge.create(hostDir);
Expand Down
34 changes: 17 additions & 17 deletions app/src/main/java/com/sevtinge/hyperceiler/utils/Helpers.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
* This file is part of HyperCeiler.
* This file is part of HyperCeiler.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* HyperCeiler is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
* Copyright (C) 2023-2024 HyperCeiler Contributions
*/
package com.sevtinge.hyperceiler.utils;

import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;
Expand Down Expand Up @@ -252,10 +252,10 @@ public static String getPackageVersionName(XC_LoadPackage.LoadPackageParam lppar
Object parser = parserCls.newInstance();
File apkPath = new File(lpparam.appInfo.sourceDir);
Object pkg = XposedHelpers.callMethod(parser, "parsePackage", apkPath, 0);
//XposedLogUtils.logI("getPackageVersionName", lpparam.packageName + " versionName is " + versionName);
// XposedLogUtils.logI("getPackageVersionName", lpparam.packageName + " versionName is " + versionName);
return (String) XposedHelpers.getObjectField(pkg, "mVersionName");
} catch (Throwable e) {
//XposedLogUtils.logW("getPackageVersionName", e);
// XposedLogUtils.logW("getPackageVersionName", e);
return "null";
}
}
Expand All @@ -266,10 +266,10 @@ public static int getPackageVersionCode(XC_LoadPackage.LoadPackageParam lpparam)
Object parser = parserCls.newInstance();
File apkPath = new File(lpparam.appInfo.sourceDir);
Object pkg = XposedHelpers.callMethod(parser, "parsePackage", apkPath, 0);
//XposedLogUtils.logI("getPackageVersionCode", lpparam.packageName + " versionCode is " + versionCode);
// XposedLogUtils.logI("getPackageVersionCode", lpparam.packageName + " versionCode is " + versionCode);
return XposedHelpers.getIntField(pkg, "mVersionCode");
} catch (Throwable e) {
//XposedLogUtils.logW("getPackageVersionCode", e);
// XposedLogUtils.logW("getPackageVersionCode", e);
return -1;
}
}
Expand Down

0 comments on commit 913ab68

Please sign in to comment.