Skip to content

Commit ec6f1f5

Browse files
author
tangyinsheng
committed
[tinker] Do not reset versionToRemove field so that old patch can be removed after new patch is applied.
1 parent dce0257 commit ec6f1f5

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/listener/DefaultPatchListener.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,6 @@ protected int patchCheck(String path, String patchMd5) {
134134
&& loadResult != null && loadResult.useInterpretMode;
135135

136136
if (!repairOptNeeded) {
137-
if (manager.isTinkerLoaded() && loadResult != null) {
138-
String currentVersion = loadResult.currentVersion;
139-
if (patchMd5.equals(currentVersion)) {
140-
return ShareConstants.ERROR_PATCH_ALREADY_APPLY;
141-
}
142-
}
143-
144137
// Hit if we have already applied patch but main process did not restart.
145138
final String patchDirectory = manager.getPatchDirectory().getAbsolutePath();
146139
File patchInfoLockFile = SharePatchFileUtil.getPatchInfoLockFile(patchDirectory);

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/patch/DexDiffPatchInternal.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ private static boolean patchDexExtractViaDexDiff(Context context, String patchVe
198198
}
199199

200200
private static boolean checkClassNDexFiles(final String dexFilePath) {
201-
if (patchList.isEmpty() || !isVmArt) {
201+
classNDexInfo.clear();
202+
if (patchList.isEmpty() || !isVmArt) {
202203
return false;
203204
}
204205
ShareDexDiffPatchInfo testInfo = null;

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/patch/UpgradePatch.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,20 @@ public boolean tryPatch(Context context, String tempPatchPath, PatchResult patch
123123
}
124124
// if it is interpret now, use changing flag to wait main process
125125
final String finalOatDir = usingInterpret ? ShareConstants.CHANING_DEX_OPTIMIZE_PATH : oldInfo.oatDir;
126-
newInfo = new SharePatchInfo(oldInfo.oldVersion, patchMd5, isProtectedApp, "", Build.FINGERPRINT, finalOatDir, false);
126+
if (!patchMd5.equals(oldInfo.newVersion) && !oldInfo.newVersion.equals(oldInfo.oldVersion)) {
127+
// Currently applied patch is not the same as last applied one and the last applied one is not loaded,
128+
// so we can delete the last applied patch to avoid patch artifacts accumulating.
129+
final String patchName = SharePatchFileUtil.getPatchVersionDirectory(oldInfo.newVersion);
130+
SharePatchFileUtil.deleteDir(new File(patchDirectory, patchName));
131+
}
132+
final String versionToRemove;
133+
if (patchMd5.equals(oldInfo.versionToRemove)) {
134+
// If we re-applied a patch that marks to be removed, clear the marker.
135+
versionToRemove = "";
136+
} else {
137+
versionToRemove = oldInfo.versionToRemove;
138+
}
139+
newInfo = new SharePatchInfo(oldInfo.oldVersion, patchMd5, isProtectedApp, versionToRemove, Build.FINGERPRINT, finalOatDir, false);
127140
} else {
128141
newInfo = new SharePatchInfo("", patchMd5, isProtectedApp, "", Build.FINGERPRINT, ShareConstants.DEFAULT_DEX_OPTIMIZE_PATH, false);
129142
}

tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/TinkerLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ private void tryLoadPatchFilesInternal(TinkerApplication app, Intent resultInten
172172
ShareTinkerInternals.killProcessExceptMain(app);
173173
SharePatchFileUtil.deleteDir(patchVersionDirFullPath);
174174
}
175+
} else {
176+
patchInfo.versionToRemove = "";
177+
SharePatchInfo.rewritePatchInfoFileWithLock(patchInfoFile, patchInfo, patchInfoLockFile);
175178
}
176179
}
177180
if (patchInfo.isRemoveInterpretOATDir) {

0 commit comments

Comments
 (0)