Skip to content

Commit

Permalink
Merge from dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cundong committed Feb 24, 2018
1 parent 341d68b commit 23d1e5d
Show file tree
Hide file tree
Showing 38 changed files with 822 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.qihoo360.replugin.gradle.host
class AppConstant {

/** 版本号 */
def static final VER = "2.2.2"
def static final VER = "2.2.4"

/** 打印信息时候的前缀 */
def static final TAG = "< replugin-host-v${VER} >"
Expand Down
2 changes: 1 addition & 1 deletion replugin-host-library/replugin-host-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
apply plugin: 'com.android.library'

version = "2.2.2"
version = "2.2.4"
group = 'com.qihoo360.replugin' // 组名

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.qihoo360.loader2;

import android.content.Context;
import android.os.Build;

import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.model.PluginInfo;
Expand Down Expand Up @@ -221,16 +222,48 @@ static final void builder(Context context, PxAll all) {
// 构建数据
}

private static File getDexDir(Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
return new File(context.getDir(Constant.LOCAL_PLUGIN_SUB_DIR, 0) + File.separator + "oat" + File.separator + VMRuntimeCompat.getArtOatCpuType());
} else {
return context.getDir(Constant.LOCAL_PLUGIN_ODEX_SUB_DIR, 0);
}
}

private static void deleteUnknownDexs(Context context, PxAll all) {
HashSet<String> names = new HashSet<>();
for (PluginInfo p : all.getPlugins()) {
names.add(p.getDexFile().getName());

if (LOG) {
LogDebug.d(PLUGIN_TAG, "dexFile:" + p.getDexFile().getName());
}

// add vdex for Android O
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
String fileNameWithoutExt = FileUtils.getFileNameWithoutExt(p.getDexFile().getAbsolutePath());

if (LOG) {
LogDebug.d(PLUGIN_TAG, "vdexFile:" + (fileNameWithoutExt + ".vdex"));
}

names.add(fileNameWithoutExt + ".vdex");
}
}
File dir = context.getDir(Constant.LOCAL_PLUGIN_ODEX_SUB_DIR, 0);
File files[] = dir.listFiles();

File dexDir = getDexDir(context);

if (LOG) {
LogDebug.d(PLUGIN_TAG, "to delete dex dir:" + dexDir);
}

File files[] = dexDir.listFiles();
if (files != null) {
for (File f : files) {
if (names.contains(f.getName())) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "no need delete " + f.getAbsolutePath());
}
continue;
}
if (LOG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Map;
import java.util.Set;

import static com.qihoo360.replugin.helper.LogDebug.LOADER_TAG;
import static com.qihoo360.replugin.helper.LogDebug.LOG;
import static com.qihoo360.replugin.helper.LogDebug.PLUGIN_TAG;
import static com.qihoo360.replugin.helper.LogRelease.LOGR;
Expand Down Expand Up @@ -314,6 +315,18 @@ final boolean loadDex(ClassLoader parent, int load) {
parent = getClass().getClassLoader().getParent(); // TODO: 这里直接用父类加载器
}
String soDir = mPackageInfo.applicationInfo.nativeLibraryDir;

long begin = 0;
boolean isDexExist = false;

if (LOG) {
begin = System.currentTimeMillis();
File dexFile = mPluginObj.mInfo.getDexFile();
if (dexFile.exists() && dexFile.length() > 0) {
isDexExist = true;
}
}

mClassLoader = RePlugin.getConfig().getCallbacks().createPluginClassLoader(mPluginObj.mInfo, mPath, out, soDir, parent);
Log.i("dex", "load " + mPath + " = " + mClassLoader);

Expand All @@ -324,6 +337,18 @@ final boolean loadDex(ClassLoader parent, int load) {
return false;
}

if (LOG) {
if (!isDexExist) {
Log.d(LOADER_TAG, " --释放DEX, " + "(plugin=" + mPluginName + ", version=" + mPluginObj.mInfo.getVersion() + ")"
+ ", use:" + (System.currentTimeMillis() - begin)
+ ", process:" + IPC.getCurrentProcessName());
} else {
Log.d(LOADER_TAG, " --无需释放DEX, " + "(plugin=" + mPluginName + ", version=" + mPluginObj.mInfo.getVersion() + ")"
+ ", use:" + (System.currentTimeMillis() - begin)
+ ", process:" + IPC.getCurrentProcessName());
}
}

// 缓存表:ClassLoader
synchronized (Plugin.FILENAME_2_DEX) {
Plugin.FILENAME_2_DEX.put(mPath, new WeakReference<>(mClassLoader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ public File getCacheDir() {
return mCacheDir;
}

/*
为了适配 Android 8.1 及后续版本,该方法不再重写,因此,需要各插件之间约定,防止出现重名数据库。
by cundong
@Override
public File getDatabasePath(String name) {
return validateFilePath(name, false);
}
*/

@Override
public File getFileStreamPath(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ final PluginInfo updateV5FileTo(Context context, File dir, boolean checkOverride
LogDebug.d(PLUGIN_TAG, "update v5 plugin: extract ..." + " name=" + mName);
}
//
File tmpfile = new File(dir, "plugin.tmp");
File tmpfile = new File(dir, String.format("%s_plugin.tmp", mName));
FileUtils.copyInputStreamToFile(dis, tmpfile);

// 检查结果,如果不成功就删除该文件
Expand Down Expand Up @@ -417,6 +417,11 @@ final PluginInfo updateV5FileTo(Context context, File dir, boolean checkOverride
if (LOG) {
LogDebug.d(PLUGIN_TAG, "update v5 plugin: extract success" + " name=" + mName);
}

if (target.exists()) {
FileUtils.forceDelete(target);
}

// 更名
FileUtils.moveFile(tmpfile, target);
return pi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@ private static boolean is64BitImpl() {
}
return false;
}
}

/**
* Art虚拟机,引入AOT编译后,读取oat目录下当前正在使用的目录
* TODO 目前仅支持arm
*
* @return
*/
public static String getArtOatCpuType() {
return VMRuntimeCompat.is64Bit() ? BuildCompat.ARM64 : BuildCompat.ARM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,9 @@ public static int printPluginInfo(PluginInfo pi, int load) {
* @deprecated 为兼容卫士,以后干掉
*/
public static final String MISC_TAG = "ws002";

/**
* createClassLoader TAG
*/
public static final String LOADER_TAG = "createClassLoader";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.qihoo360.loader2.BuildCompat;
import com.qihoo360.loader2.Constant;
import com.qihoo360.loader2.PluginNativeLibsHelper;
import com.qihoo360.loader2.V5FileInfo;
Expand Down Expand Up @@ -450,7 +449,7 @@ public File getDexParentDir() {
Context context = RePluginInternal.getAppContext();

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
return new File(getApkDir() + File.separator + "oat" + File.separator + getArtOatCpuType());
return new File(getApkDir() + File.separator + "oat" + File.separator + VMRuntimeCompat.getArtOatCpuType());
} else {
if (isPnPlugin()) {
return context.getDir(Constant.LOCAL_PLUGIN_ODEX_SUB_DIR, 0);
Expand Down Expand Up @@ -486,16 +485,6 @@ public File getDexFile() {
}
}

/**
* Art虚拟机,引入AOT编译后,读取oat目录下,当前正在使用的目录
* TODO 目前仅支持arm
*
* @return
*/
private String getArtOatCpuType() {
return VMRuntimeCompat.is64Bit() ? BuildCompat.ARM64 : BuildCompat.ARM;
}

/**
* 根据类型来获取SO释放的路径 <p>
* 若为"纯APK"插件,则会位于app_p_n中;若为"p-n"插件,则会位于"app_plugins_v3_libs"中 <p>
Expand Down Expand Up @@ -797,7 +786,7 @@ private void setVersion(int version) {
// Parcelable and Cloneable
// -------------------------

public static final Parcelable.Creator<PluginInfo> CREATOR = new Parcelable.Creator<PluginInfo>() {
public static final Creator<PluginInfo> CREATOR = new Creator<PluginInfo>() {

@Override
public PluginInfo createFromParcel(Parcel source) {
Expand Down Expand Up @@ -846,6 +835,21 @@ public Object clone() {

if (pluginInfo != null && !TextUtils.isEmpty(this.mJsonText)) {
pluginInfo.mJson = new JSONObject(this.mJsonText);

JSONObject ujo = pluginInfo.mJson.optJSONObject("upinfo");
if (ujo != null) {
pluginInfo.mPendingUpdate = new PluginInfo(ujo);
}

JSONObject djo = pluginInfo.mJson.optJSONObject("delinfo");
if (djo != null) {
pluginInfo.mPendingDelete = new PluginInfo(djo);
}

JSONObject cjo = pluginInfo.mJson.optJSONObject("coverinfo");
if (cjo != null) {
pluginInfo.mPendingCover = new PluginInfo(cjo);
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.qihoo360.replugin.gradle.plugin
class AppConstant {

/** 版本号 */
def static final VER = "2.2.2"
def static final VER = "2.2.4"

/** 打印信息时候的前缀 */
def static final TAG = "< replugin-plugin-v${VER} >"
Expand Down
2 changes: 1 addition & 1 deletion replugin-plugin-library/replugin-plugin-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

apply plugin: 'com.android.library'

version = "2.2.2"
version = "2.2.4"
group = 'com.qihoo360.replugin' // 组名

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@
-keep class com.qihoo360.replugin.base.IPC { public *; }
-keep class com.qihoo360.replugin.Entry { *; }
-keep class com.qihoo360.replugin.RePlugin { public *; }
-keep class com.qihoo360.replugin.model.PluginInfo { public *; }

Loading

0 comments on commit 23d1e5d

Please sign in to comment.