Skip to content

Commit 314ab53

Browse files
committed
1. prepare for release 1.7.7
2. fix xposed judgment
1 parent 853bb9e commit 314ab53

File tree

7 files changed

+59
-45
lines changed

7 files changed

+59
-45
lines changed

README.md

Lines changed: 5 additions & 5 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.7.6-red.svg)](https://github.com/Tencent/tinker/releases)
3+
[![Release Version](https://img.shields.io/badge/release-1.7.7-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.7.6-red.svg)](https://github.com/Tencent/tinker/wiki)
5+
[![WeChat Approved](https://img.shields.io/badge/Wechat_Approved-1.7.7-red.svg)](https://github.com/Tencent/tinker/wiki)
66

77
Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk.
88

@@ -14,7 +14,7 @@ Add tinker-gradle-plugin as a dependency in your main `build.gradle` in the root
1414
```gradle
1515
buildscript {
1616
dependencies {
17-
classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.7.6')
17+
classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.7.7')
1818
}
1919
}
2020
```
@@ -24,9 +24,9 @@ Then you need to "apply" the plugin and add dependencies by adding the following
2424
```gradle
2525
dependencies {
2626
//optional, help to generate the final application
27-
provided('com.tencent.tinker:tinker-android-anno:1.7.6')
27+
provided('com.tencent.tinker:tinker-android-anno:1.7.7')
2828
//tinker's main Android lib
29-
compile('com.tencent.tinker:tinker-android-lib:1.7.6')
29+
compile('com.tencent.tinker:tinker-android-lib:1.7.7')
3030
}
3131
...
3232
...

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
public class DexDiffPatchInternal extends BasePatchInternal {
5454
protected static final String TAG = "Tinker.DexDiffPatchInternal";
5555

56-
protected static final int WAIT_ASYN_OAT_TIME = 6 * 1000;
56+
protected static final int WAIT_ASYN_OAT_TIME = 8 * 1000;
5757
protected static final int MAX_WAIT_COUNT = 30;
5858

5959
private static ArrayList<File> optFiles = new ArrayList<>();

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@
4343
class TinkerResourcePatcher {
4444
private static final String TAG = "Tinker.ResourcePatcher";
4545
private static final String TEST_ASSETS_VALUE = "only_use_to_test_tinker_resource.txt";
46-
private static final String MIUI_RESOURCE_CLASSNAME = "android.content.res.MiuiResources";
46+
// private static final String MIUI_RESOURCE_CLASSNAME = "android.content.res.MiuiResources";
4747

4848
// original object
4949
private static Collection<WeakReference<Resources>> references = null;
5050
private static Object currentActivityThread = null;
5151
private static AssetManager newAssetManager = null;
52-
private static ArrayMap<?, WeakReference<Resources>> activeResources19 = null;
5352
// private static ArrayMap<?, WeakReference<?>> resourceImpls = null;
54-
private static HashMap<?, WeakReference<Resources>> activeResources7 = null;
53+
5554
// method
5655
private static Method addAssetPathMethod = null;
5756
private static Method ensureStringBlocksMethod = null;
@@ -64,7 +63,7 @@ class TinkerResourcePatcher {
6463
private static Field resourcePackagesFiled = null;
6564
// private static Field publicSourceDirField = null;
6665

67-
private static boolean isMiuiSystem = false;
66+
// private static boolean isMiuiSystem = false;
6867

6968
public static void isResourceCanPatch(Context context) throws Throwable {
7069
// - Replace mResDir to point to the external resource file instead of the .apk. This is
@@ -121,7 +120,7 @@ public static void isResourceCanPatch(Context context) throws Throwable {
121120
try {
122121
Field fMActiveResources = resourcesManagerClass.getDeclaredField("mActiveResources");
123122
fMActiveResources.setAccessible(true);
124-
activeResources19 =
123+
ArrayMap<?, WeakReference<Resources>> activeResources19 =
125124
(ArrayMap<?, WeakReference<Resources>>) fMActiveResources.get(resourcesManager);
126125
references = activeResources19.values();
127126
} catch (NoSuchFieldException ignore) {
@@ -135,7 +134,7 @@ public static void isResourceCanPatch(Context context) throws Throwable {
135134
} else {
136135
Field fMActiveResources = activityThread.getDeclaredField("mActiveResources");
137136
fMActiveResources.setAccessible(true);
138-
activeResources7 =
137+
HashMap<?, WeakReference<Resources>> activeResources7 =
139138
(HashMap<?, WeakReference<Resources>>) fMActiveResources.get(currentActivityThread);
140139
references = activeResources7.values();
141140
}
@@ -152,8 +151,8 @@ public static void isResourceCanPatch(Context context) throws Throwable {
152151
resourcesImplFiled.setAccessible(true);
153152
}
154153

155-
final Resources resources = context.getResources();
156-
isMiuiSystem = resources != null && MIUI_RESOURCE_CLASSNAME.equals(resources.getClass().getName());
154+
// final Resources resources = context.getResources();
155+
// isMiuiSystem = resources != null && MIUI_RESOURCE_CLASSNAME.equals(resources.getClass().getName());
157156

158157
// try {
159158
// publicSourceDirField = ShareReflectUtil.findField(ApplicationInfo.class, "publicSourceDir");
@@ -211,7 +210,7 @@ public static void monkeyPatchExistingResources(Context context, String external
211210
implAssets.set(resourceImpl, newAssetManager);
212211
}
213212

214-
fixMiuiTypedArrayIssue(resources);
213+
clearPreloadTypedArrayIssue(resources);
215214

216215
resources.updateConfiguration(resources.getConfiguration(), resources.getDisplayMetrics());
217216
}
@@ -232,13 +231,14 @@ public static void monkeyPatchExistingResources(Context context, String external
232231
* Resource has mTypedArrayPool field, which just like Message Poll to reduce gc
233232
* MiuiResource change TypedArray to MiuiTypedArray, but it get string block from offset instead of assetManager
234233
*/
235-
private static void fixMiuiTypedArrayIssue(Resources resources) {
234+
private static void clearPreloadTypedArrayIssue(Resources resources) {
236235
// Perform this trick not only in Miui system since we can't predict if any other
237236
// manufacturer would do the same modification to Android.
238237
// if (!isMiuiSystem) {
239238
// return;
240239
// }
241-
Log.w(TAG, "Miui system found, try to clear MiuiTypedArray cache!");
240+
241+
Log.w(TAG, "try to clear typedArray cache!");
242242
// Clear typedArray cache.
243243
try {
244244
Field typedArrayPoolField = ShareReflectUtil.findField(Resources.class, "mTypedArrayPool");
@@ -253,6 +253,7 @@ private static void fixMiuiTypedArrayIssue(Resources resources) {
253253
final Object newTypedArrayPool = typedArrayConstructor.newInstance(poolSize);
254254
typedArrayPoolField.set(resources, newTypedArrayPool);
255255
} catch (Throwable ignored) {
256+
Log.e(TAG, "clearPreloadTypedArrayIssue failed, ignore error: " + ignored);
256257
}
257258
}
258259

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
/**
2020
* Created by zhangshaowen on 17/1/12.
21+
*
22+
* TODO:
2123
* Thanks for Android Fragmentation
2224
* hold the issue https://github.com/Tencent/tinker/issues/302
2325
*/
24-
2526
public class TinkerResourcesKey {
2627

2728
private static final class V24 {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ public class TinkerUncaughtHandler implements Thread.UncaughtExceptionHandler {
3737

3838
private final File crashFile;
3939
private final Context context;
40+
private final Thread.UncaughtExceptionHandler ueh;
4041

4142
public TinkerUncaughtHandler(Context context) {
4243
this.context = context;
44+
ueh = Thread.getDefaultUncaughtExceptionHandler();
4345
crashFile = SharePatchFileUtil.getPatchLastCrashFile(context);
4446
}
4547

4648
@Override
4749
public void uncaughtException(Thread thread, Throwable ex) {
4850
Log.e(TAG, "catch exception when loading tinker:" + Log.getStackTraceString(ex));
51+
ueh.uncaughtException(thread, ex);
52+
4953
if (crashFile != null) {
5054
Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
5155

@@ -67,8 +71,8 @@ public void uncaughtException(Thread thread, Throwable ex) {
6771
} finally {
6872
SharePatchFileUtil.closeQuietly(pw);
6973
}
74+
android.os.Process.killProcess(android.os.Process.myPid());
7075
}
7176
}
72-
android.os.Process.killProcess(android.os.Process.myPid());
7377
}
7478
}

tinker-sample-android/app/src/main/java/tinker/sample/android/app/MainActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.tencent.tinker.lib.library.TinkerLoadLibrary;
3434
import com.tencent.tinker.lib.tinker.Tinker;
3535
import com.tencent.tinker.lib.tinker.TinkerInstaller;
36-
import com.tencent.tinker.lib.util.TinkerLog;
3736
import com.tencent.tinker.loader.shareutil.ShareConstants;
3837
import com.tencent.tinker.loader.shareutil.ShareTinkerInternals;
3938

tinker-sample-android/app/src/main/java/tinker/sample/android/crash/SampleUncaughtExceptionHandler.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,42 @@ public void uncaughtException(Thread thread, Throwable ex) {
6565
* If it use Xposed, we can just clean patch or mention user to uninstall it.
6666
*/
6767
private void tinkerPreVerifiedCrashHandler(Throwable ex) {
68-
if (Utils.isXposedExists(ex)) {
69-
//method 1
70-
ApplicationLike applicationLike = TinkerManager.getTinkerApplicationLike();
71-
if (applicationLike == null || applicationLike.getApplication() == null) {
72-
return;
68+
Throwable throwable = ex;
69+
boolean isXposed = false;
70+
while (throwable != null) {
71+
if (!isXposed) {
72+
isXposed = Utils.isXposedExists(throwable);
7373
}
74-
75-
if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
76-
return;
77-
}
78-
boolean isCausedByXposed = false;
79-
//for art, we can't know the actually crash type
80-
//just ignore art
81-
if (ex instanceof IllegalAccessError && ex.getMessage().contains(DALVIK_XPOSED_CRASH)) {
82-
//for dalvik, we know the actual crash type
83-
isCausedByXposed = true;
84-
}
85-
86-
if (isCausedByXposed) {
87-
SampleTinkerReport.onXposedCrash();
88-
TinkerLog.e(TAG, "have xposed: just clean tinker");
89-
//kill all other process to ensure that all process's code is the same.
90-
ShareTinkerInternals.killAllOtherProcess(applicationLike.getApplication());
91-
92-
TinkerApplicationHelper.cleanPatch(applicationLike);
93-
ShareTinkerInternals.setTinkerDisableWithSharedPreferences(applicationLike.getApplication());
74+
if (isXposed) {
75+
//method 1
76+
ApplicationLike applicationLike = TinkerManager.getTinkerApplicationLike();
77+
if (applicationLike == null || applicationLike.getApplication() == null) {
78+
return;
79+
}
80+
81+
if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
82+
return;
83+
}
84+
boolean isCausedByXposed = false;
85+
//for art, we can't know the actually crash type
86+
//just ignore art
87+
if (throwable instanceof IllegalAccessError && throwable.getMessage().contains(DALVIK_XPOSED_CRASH)) {
88+
//for dalvik, we know the actual crash type
89+
isCausedByXposed = true;
90+
}
91+
92+
if (isCausedByXposed) {
93+
SampleTinkerReport.onXposedCrash();
94+
TinkerLog.e(TAG, "have xposed: just clean tinker");
95+
//kill all other process to ensure that all process's code is the same.
96+
ShareTinkerInternals.killAllOtherProcess(applicationLike.getApplication());
97+
98+
TinkerApplicationHelper.cleanPatch(applicationLike);
99+
ShareTinkerInternals.setTinkerDisableWithSharedPreferences(applicationLike.getApplication());
100+
return;
101+
}
94102
}
103+
throwable = throwable.getCause();
95104
}
96105
}
97106

0 commit comments

Comments
 (0)