Skip to content

Commit 41d0910

Browse files
author
tangyinsheng
committed
Merge branch 'dev' into test/v_1_9_14_24
2 parents d7f4e22 + 1f422df commit 41d0910

File tree

17 files changed

+187
-163
lines changed

17 files changed

+187
-163
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Tinker
22
[![license](http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat)](https://github.com/Tencent/tinker/blob/master/LICENSE)
3-
[![Release Version](https://img.shields.io/badge/release-1.9.14.19-red.svg)](https://github.com/Tencent/tinker/releases)
3+
[![Release Version](https://img.shields.io/badge/release-1.9.14.22-red.svg)](https://github.com/Tencent/tinker/releases)
44
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/tinker/pulls)
5-
[![WeChat Approved](https://img.shields.io/badge/Wechat_Approved-1.9.14.19-red.svg)](https://github.com/Tencent/tinker/wiki)
5+
[![WeChat Approved](https://img.shields.io/badge/Wechat_Approved-1.9.14.22-red.svg)](https://github.com/Tencent/tinker/wiki)
66

77
[中文说明](https://github.com/Tencent/tinker/wiki)
88

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ext {
3636
javaVersion = JavaVersion.VERSION_1_8
3737

3838
GROUP = 'com.tencent.tinker'
39-
VERSION_NAME = '1.9.14.22'
39+
VERSION_NAME = '1.9.14.23'
4040

4141
POM_DESCRIPTION = 'Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk.'
4242
POM_URL = 'https://github.com/Tencent/tinker'

third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dx/instruction/InstructionComparator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ private int getPromotedOpCodeOnDemand(InstructionHolder insn) {
261261
}
262262

263263
public boolean isSameInstruction(int insnAddress1, int insnAddress2) {
264-
InstructionHolder insnHolder1 = this.insnHolders1[insnAddress1];
265-
InstructionHolder insnHolder2 = this.insnHolders2[insnAddress2];
264+
InstructionHolder insnHolder1 = insnAddress1 < this.insnHolders1.length ? this.insnHolders1[insnAddress1] : null;
265+
InstructionHolder insnHolder2 = insnAddress2 < this.insnHolders2.length ? this.insnHolders2[insnAddress2] : null;
266266
return isSameInstruction(insnHolder1, insnHolder2);
267267
}
268268

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/library/TinkerLoadLibrary.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public static boolean installNavitveLibraryABI(Context context, String currentAB
219219
* @return
220220
*/
221221
public static boolean installNativeLibraryABIWithoutTinkerInstalled(ApplicationLike appLike, String currentABI) {
222+
if (!TinkerApplicationHelper.isTinkerLoadSuccess(appLike)) {
223+
ShareTinkerLog.e(TAG, "no loaded patch, skip installation.");
224+
return false;
225+
}
226+
222227
final String currentVersion = TinkerApplicationHelper.getCurrentVersion(appLike);
223228
if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
224229
ShareTinkerLog.e(TAG, "failed to get current patch version.");

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,13 @@ 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);
147140
File patchInfoFile = SharePatchFileUtil.getPatchInfoFile(patchDirectory);
148141
try {
149142
final SharePatchInfo currInfo = SharePatchInfo.readAndCheckPropertyWithLock(patchInfoFile, patchInfoLockFile);
150-
if (currInfo != null && !ShareTinkerInternals.isNullOrNil(currInfo.newVersion) && !currInfo.isRemoveNewVersion) {
143+
if (currInfo != null && !ShareTinkerInternals.isNullOrNil(currInfo.newVersion) && !currInfo.newVersion.equals(currInfo.versionToRemove)) {
151144
if (patchMd5.equals(currInfo.newVersion)) {
152145
return ShareConstants.ERROR_PATCH_ALREADY_APPLY;
153146
}

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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
import com.tencent.tinker.lib.service.PatchResult;
2323
import com.tencent.tinker.lib.tinker.Tinker;
24-
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
2524
import com.tencent.tinker.lib.util.UpgradePatchRetry;
2625
import com.tencent.tinker.loader.shareutil.ShareConstants;
2726
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil;
2827
import com.tencent.tinker.loader.shareutil.SharePatchInfo;
2928
import com.tencent.tinker.loader.shareutil.ShareSecurityCheck;
3029
import com.tencent.tinker.loader.shareutil.ShareTinkerInternals;
30+
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
3131

3232
import java.io.File;
3333
import java.io.IOException;
@@ -112,7 +112,7 @@ public boolean tryPatch(Context context, String tempPatchPath, PatchResult patch
112112

113113
final boolean usingInterpret = oldInfo.oatDir.equals(ShareConstants.INTERPRET_DEX_OPTIMIZE_PATH);
114114

115-
if (!usingInterpret && !ShareTinkerInternals.isNullOrNil(oldInfo.newVersion) && oldInfo.newVersion.equals(patchMd5) && !oldInfo.isRemoveNewVersion) {
115+
if (!usingInterpret && !ShareTinkerInternals.isNullOrNil(oldInfo.newVersion) && oldInfo.newVersion.equals(patchMd5) && !oldInfo.newVersion.equals(oldInfo.versionToRemove)) {
116116
ShareTinkerLog.e(TAG, "patch already applied, md5: %s", patchMd5);
117117

118118
// Reset patch apply retry count to let us be able to reapply without triggering
@@ -123,9 +123,22 @@ 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, false, 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 {
128-
newInfo = new SharePatchInfo("", patchMd5, isProtectedApp, false, Build.FINGERPRINT, ShareConstants.DEFAULT_DEX_OPTIMIZE_PATH, false);
141+
newInfo = new SharePatchInfo("", patchMd5, isProtectedApp, "", Build.FINGERPRINT, ShareConstants.DEFAULT_DEX_OPTIMIZE_PATH, false);
129142
}
130143

131144
// it is a new patch, we first delete if there is any files

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/reporter/DefaultLoadReporter.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import com.tencent.tinker.lib.service.TinkerPatchService;
2323
import com.tencent.tinker.lib.tinker.Tinker;
2424
import com.tencent.tinker.lib.tinker.TinkerInstaller;
25-
import com.tencent.tinker.lib.tinker.TinkerLoadResult;
26-
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
2725
import com.tencent.tinker.lib.util.UpgradePatchRetry;
2826
import com.tencent.tinker.loader.shareutil.ShareConstants;
2927
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil;
30-
import com.tencent.tinker.loader.shareutil.SharePatchInfo;
3128
import com.tencent.tinker.loader.shareutil.ShareTinkerInternals;
29+
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
3230

3331
import java.io.File;
3432

@@ -304,28 +302,9 @@ public void onLoadPackageCheckFail(File patchFile, int errorCode) {
304302
checkAndCleanPatch();
305303
}
306304

307-
/**
308-
* other process may have installed old patch version,
309-
* if we try to clean patch, we should kill other process first
310-
*/
311305
public void checkAndCleanPatch() {
312306
Tinker tinker = Tinker.with(context);
313-
//only main process can load a new patch
314-
if (tinker.isMainProcess()) {
315-
TinkerLoadResult tinkerLoadResult = tinker.getTinkerLoadResultIfPresent();
316-
//if versionChange and the old patch version is not ""
317-
if (tinkerLoadResult.versionChanged) {
318-
SharePatchInfo sharePatchInfo = tinkerLoadResult.patchInfo;
319-
if (sharePatchInfo != null && !ShareTinkerInternals.isNullOrNil(sharePatchInfo.oldVersion)) {
320-
ShareTinkerLog.w(TAG, "checkAndCleanPatch, oldVersion %s is not null, try kill all other process",
321-
sharePatchInfo.oldVersion);
322-
323-
ShareTinkerInternals.killAllOtherProcess(context);
324-
}
325-
}
326-
}
327307
tinker.cleanPatch();
328-
329308
}
330309

331310
public boolean retryPatch() {

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
import com.tencent.tinker.lib.service.AbstractResultService;
3131
import com.tencent.tinker.lib.service.DefaultTinkerResultService;
3232
import com.tencent.tinker.lib.service.TinkerPatchService;
33-
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
3433
import com.tencent.tinker.lib.util.TinkerServiceInternals;
3534
import com.tencent.tinker.loader.TinkerRuntimeException;
3635
import com.tencent.tinker.loader.shareutil.ShareConstants;
3736
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil;
38-
import com.tencent.tinker.loader.shareutil.SharePatchInfo;
3937
import com.tencent.tinker.loader.shareutil.ShareTinkerInternals;
38+
import com.tencent.tinker.loader.shareutil.ShareTinkerLog;
4039

4140
import java.io.File;
4241

@@ -256,20 +255,7 @@ public int getTinkerFlags() {
256255
* clean all patch files
257256
*/
258257
public void cleanPatch() {
259-
if (patchDirectory == null) {
260-
return;
261-
}
262-
final File patchInfoFile = SharePatchFileUtil.getPatchInfoFile(patchDirectory.getAbsolutePath());
263-
if (!patchInfoFile.exists()) {
264-
ShareTinkerLog.printErrStackTrace(TAG, new Throwable(), "try to clean patch while patch info file does not exist.");
265-
return;
266-
}
267-
final File patchInfoLockFile = SharePatchFileUtil.getPatchInfoLockFile(patchDirectory.getAbsolutePath());
268-
final SharePatchInfo patchInfo = SharePatchInfo.readAndCheckPropertyWithLock(patchInfoFile, patchInfoLockFile);
269-
if (patchInfo != null) {
270-
patchInfo.isRemoveNewVersion = true;
271-
SharePatchInfo.rewritePatchInfoFileWithLock(patchInfoFile, patchInfo, patchInfoLockFile);
272-
}
258+
ShareTinkerInternals.cleanPatch(getContext());
273259
}
274260

275261
/**

tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/TinkerLoadResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public boolean parseTinkerResult(Context context, Intent intentResult) {
114114
resourceFile = new File(resourceDirectory, ShareConstants.RES_NAME);
115115
}
116116
final boolean isProtectedApp = ShareIntentUtil.getBooleanExtra(intentResult, ShareIntentUtil.INTENT_IS_PROTECTED_APP, false);
117-
patchInfo = new SharePatchInfo(oldVersion, newVersion, isProtectedApp, false, Build.FINGERPRINT, oatDir, false);
117+
patchInfo = new SharePatchInfo(oldVersion, newVersion, isProtectedApp, "", Build.FINGERPRINT, oatDir, false);
118118
versionChanged = !(oldVersion.equals(newVersion));
119119
}
120120

0 commit comments

Comments
 (0)