Skip to content

Commit

Permalink
Merge pull request #708 from Tencent/dev
Browse files Browse the repository at this point in the history
sync dev to master.
  • Loading branch information
tys282000 authored Dec 6, 2017
2 parents 1e462d9 + 335b32d commit dd54a70
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 108 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME_PREFIX=1.9.1
VERSION_NAME_PREFIX=1.9.2
VERSION_NAME_SUFFIX=
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static boolean extract(ZipFile zipFile, ZipEntry entryFile, File extractT
TinkerLog.i(TAG, "isExtractionSuccessful: %b", isExtractionSuccessful);

if (!isExtractionSuccessful) {
extractTo.delete();
if (extractTo.exists()) {
final boolean succ = extractTo.delete();
if (!succ || extractTo.exists()) {
TinkerLog.e(TAG, "Failed to delete corrupted dex " + extractTo.getPath());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,17 @@ private static boolean mergeClassNDexFiles(final Context context, final File pat
File dexFile = classNDexInfo.get(info);

if (info.isJarMode) {
TinkerZipFile dexZipFile = new TinkerZipFile(dexFile);
TinkerZipEntry rawDexZipEntry = dexZipFile.getEntry(ShareConstants.DEX_IN_JAR);
TinkerZipEntry newDexZipEntry = new TinkerZipEntry(rawDexZipEntry, info.rawName);
TinkerZipFile dexZipFile = null;
InputStream inputStream = null;
try {
dexZipFile = new TinkerZipFile(dexFile);
TinkerZipEntry rawDexZipEntry = dexZipFile.getEntry(ShareConstants.DEX_IN_JAR);
TinkerZipEntry newDexZipEntry = new TinkerZipEntry(rawDexZipEntry, info.rawName);
inputStream = dexZipFile.getInputStream(rawDexZipEntry);
TinkerZipUtil.extractTinkerEntry(newDexZipEntry, inputStream, out);
} finally {
StreamUtil.closeQuietly(inputStream);
StreamUtil.closeQuietly(dexZipFile);
}
} else {
TinkerZipEntry dexZipEntry = new TinkerZipEntry(info.rawName);
Expand Down Expand Up @@ -597,8 +599,8 @@ private static boolean extractDexToJar(ZipFile zipFile, ZipEntry entryFile, File
TinkerLog.i(TAG, "isExtractionSuccessful: %b", isExtractionSuccessful);

if (!isExtractionSuccessful) {
extractTo.delete();
if (extractTo.exists()) {
final boolean succ = extractTo.delete();
if (!succ || extractTo.exists()) {
TinkerLog.e(TAG, "Failed to delete corrupted dex " + extractTo.getPath());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
* sometimes, you may want to install tinker later, or never install tinker in some process.
Expand Down Expand Up @@ -317,7 +318,8 @@ public static boolean loadLibraryFromTinker(ApplicationLike applicationLike, Str
File patchVersionDirectory = new File(patchDirectory.getAbsolutePath() + "/" + SharePatchFileUtil.getPatchVersionDirectory(currentVersion));
String libPrePath = patchVersionDirectory.getAbsolutePath() + "/" + ShareConstants.SO_PATH;

for (String name : loadLibraries.keySet()) {
for (Map.Entry<String, String> libEntry : loadLibraries.entrySet()) {
final String name = libEntry.getKey();
if (name.equals(relativeLibPath)) {
String patchLibraryPath = libPrePath + "/" + name;
File library = new File(patchLibraryPath);
Expand Down
2 changes: 1 addition & 1 deletion tinker-android/tinker-android-loader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}"
}

task buildTinkerSdk(type: Copy, dependsOn: [build]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private void tryLoadPatchFilesInternal(TinkerApplication app, Intent resultInten
}

//tinker/patch.info/patch-641e634c/patch-641e634c.apk
File patchVersionFile = new File(patchVersionDirectoryFile.getAbsolutePath(), SharePatchFileUtil.getPatchVersionFile(version));
final String patchVersionFileRelPath = SharePatchFileUtil.getPatchVersionFile(version);
File patchVersionFile = (patchVersionFileRelPath != null ? new File(patchVersionDirectoryFile.getAbsolutePath(), patchVersionFileRelPath) : null);

if (!SharePatchFileUtil.isLegalFile(patchVersionFile)) {
Log.w(TAG, "tryLoadPatchFiles:onPatchVersionFileNotFound");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import android.util.Log;

import com.tencent.tinker.loader.shareutil.ShareConstants;
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil;
import com.tencent.tinker.loader.shareutil.ShareReflectUtil;

import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -271,11 +273,14 @@ private static void clearPreloadTypedArrayIssue(Resources resources) {
}

private static boolean checkResUpdate(Context context) {
InputStream is = null;
try {
context.getAssets().open(TEST_ASSETS_VALUE);
is = context.getAssets().open(TEST_ASSETS_VALUE);
} catch (Throwable e) {
Log.e(TAG, "checkResUpdate failed, can't find test resource assets file " + TEST_ASSETS_VALUE + " e:" + e.getMessage());
return false;
} finally {
SharePatchFileUtil.closeQuietly(is);
}
Log.i(TAG, "checkResUpdate success, found test resource assets file " + TEST_ASSETS_VALUE);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,51 +121,82 @@ void onTranslate(Context context, int tagType, String attrName, String attrValue
} else if ("multiprocess".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_MULTIPROCESS;
} else {
result.flags &= ~ActivityInfo.FLAG_MULTIPROCESS;
}
} else if ("finishOnTaskLaunch".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
} else {
result.flags &= ~ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
}
} else if ("clearTaskOnLaunch".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
} else {
result.flags &= ~ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
}
} else if ("noHistory".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_NO_HISTORY;
} else {
result.flags &= ~ActivityInfo.FLAG_NO_HISTORY;
}
} else if ("alwaysRetainTaskState".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
} else {
result.flags &= ~ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
}
} else if ("stateNotNeeded".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
} else {
result.flags &= ~ActivityInfo.FLAG_STATE_NOT_NEEDED;
}
} else if ("excludeFromRecents".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
} else {
result.flags &= ~ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
}
} else if ("allowTaskReparenting".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
} else {
result.flags &= ~ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
}
} else if ("finishOnCloseSystemDialogs".equals(attrName)) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
} else {
result.flags &= ~ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
}
} else if ("showOnLockScreen".equals(attrName) || "showForAllUsers".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 23 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ShareReflectUtil.getValueOfStaticIntField(ActivityInfo.class,
"FLAG_SHOW_FOR_ALL_USERS", 0);
if (Build.VERSION.SDK_INT >= 23) {
final int flag = ShareReflectUtil
.getValueOfStaticIntField(ActivityInfo.class, "FLAG_SHOW_FOR_ALL_USERS", 0);
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= flag;
} else {
result.flags &= ~flag;
}
}
} else if ("immersive".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 18 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_IMMERSIVE;
if (Build.VERSION.SDK_INT >= 18) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_IMMERSIVE;
} else {
result.flags &= ~ActivityInfo.FLAG_IMMERSIVE;
}
}
} else if ("hardwareAccelerated".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 11 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
if (Build.VERSION.SDK_INT >= 11) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
} else {
result.flags &= ~ActivityInfo.FLAG_HARDWARE_ACCELERATED;
}
}
} else if ("documentLaunchMode".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 21) {
Expand All @@ -184,20 +215,36 @@ void onTranslate(Context context, int tagType, String attrName, String attrValue
result.persistableMode = Integer.decode(attrValue);
}
} else if ("allowEmbedded".equals(attrName)) {
final int flag = ShareReflectUtil
.getValueOfStaticIntField(ActivityInfo.class, "FLAG_ALLOW_EMBEDDED", 0);
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ShareReflectUtil.getValueOfStaticIntField(ActivityInfo.class, "FLAG_ALLOW_EMBEDDED", 0);
result.flags |= flag;
} else {
result.flags &= ~flag;
}
} else if ("autoRemoveFromRecents".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 21 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS;
if (Build.VERSION.SDK_INT >= 21) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS;
} else {
result.flags &= ~ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS;
}
}
} else if ("relinquishTaskIdentity".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 21 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
if (Build.VERSION.SDK_INT >= 21) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
} else {
result.flags &= ~ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
}
}
} else if ("resumeWhilePausing".equals(attrName)) {
if (Build.VERSION.SDK_INT >= 21 && "true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
if (Build.VERSION.SDK_INT >= 21) {
if ("true".equalsIgnoreCase(attrValue)) {
result.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
} else {
result.flags &= ~ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
}
}
} else if ("screenOrientation".equals(attrName)) {
result.screenOrientation = parseScreenOrientation(attrValue);
Expand Down Expand Up @@ -307,8 +354,9 @@ public static synchronized boolean init(Context context, ShareSecurityCheck chec
sPackageName = context.getPackageName();
final String xmlMeta = checker.getMetaContentMap().get(EnvConsts.INCCOMPONENT_META_FILE);
StringReader sr = new StringReader(xmlMeta);
XmlPullParser parser = null;
try {
final XmlPullParser parser = Xml.newPullParser();
parser = Xml.newPullParser();
parser.setInput(sr);
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
Expand Down Expand Up @@ -336,6 +384,13 @@ public static synchronized boolean init(Context context, ShareSecurityCheck chec
} catch (XmlPullParserException e) {
throw new IOException(e);
} finally {
if (parser != null) {
try {
parser.setInput(null);
} catch (Throwable ignored) {
// Ignored.
}
}
SharePatchFileUtil.closeQuietly(sr);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public class ServiceBinderInterceptor extends Interceptor<IBinder> {
private static final String TAG = "Tinker.SvcBndrIntrcptr";
private static final ClassLoader MY_CLASSLOADER = ServiceBinderInterceptor.class.getClassLoader();

private final Context mBaseContext;
private final String mServiceName;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected IBinder decorate(@Nullable IBinder target) throws Throwable {
// Already intercepted, just return the target.
return target;
} else {
return createProxy(target.getClass().getClassLoader(), getAllInterfacesThroughDeriveChain(target.getClass()),
return createProxy(getAllInterfacesThroughDeriveChain(target.getClass()),
new FakeClientBinderHandler(target, mBinderInvocationHandler));
}
}
Expand Down Expand Up @@ -145,20 +144,39 @@ private static void fixPMSBinderCache(Context context, IBinder fakeBinder) throw
}

@SuppressWarnings("unchecked")
private static <T> T createProxy(ClassLoader cl, Class<?>[] itfs, InvocationHandler handler) {
private static <T> T createProxy(Class<?>[] itfs, InvocationHandler handler) {
final Class<?>[] mergedItfs = new Class<?>[itfs.length + 1];
System.arraycopy(itfs, 0, mergedItfs, 0, itfs.length);
mergedItfs[itfs.length] = ITinkerHotplugProxy.class;
ClassLoader cl = null;
try {
return (T) Proxy.newProxyInstance(MY_CLASSLOADER, mergedItfs, handler);
cl = Thread.currentThread().getContextClassLoader();
return (T) Proxy.newProxyInstance(cl, mergedItfs, handler);
} catch (Throwable thr) {
if (cl != null && cl != MY_CLASSLOADER) {
try {
return (T) Proxy.newProxyInstance(cl, mergedItfs, handler);
} catch (Throwable thr2) {
throw new RuntimeException("cl: " + cl, thr);
}
final Set<ClassLoader> uniqueCls = new HashSet<>(4);
for (Class<?> itf : mergedItfs) {
uniqueCls.add(itf.getClassLoader());
}
if (uniqueCls.size() == 1) {
cl = uniqueCls.iterator().next();
} else {
cl = new ClassLoader() {
@Override
protected Class<?> loadClass(String className, boolean resolve)
throws ClassNotFoundException {
for (ClassLoader cl : uniqueCls) {
final Class<?> res = cl.loadClass(className);
if (res != null) {
return res;
}
}
throw new ClassNotFoundException("cannot find class: " + className);
}
};
}
try {
return (T) Proxy.newProxyInstance(cl, mergedItfs, handler);
} catch (Throwable thr2) {
throw new RuntimeException("cl: " + cl, thr);
}
}
Expand Down Expand Up @@ -209,8 +227,7 @@ public Object invoke(Object fakeClientBinder, Method method, Object[] args) thro
final InvocationHandler fakeInterfaceHandler
= new FakeInterfaceHandler(originalInterface, (IBinder) fakeClientBinder, mBinderInvocationHandler);

return createProxy(originalInterface.getClass().getClassLoader(),
getAllInterfacesThroughDeriveChain(originalInterface.getClass()), fakeInterfaceHandler);
return createProxy(getAllInterfacesThroughDeriveChain(originalInterface.getClass()), fakeInterfaceHandler);
} else {
return method.invoke(mOriginalClientBinder, args);
}
Expand Down
Loading

0 comments on commit dd54a70

Please sign in to comment.