Skip to content

Commit

Permalink
The version was upgraded to v2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cundong committed Jan 22, 2018
2 parents b9c3480 + a21eed6 commit 811dfda
Show file tree
Hide file tree
Showing 147 changed files with 6,917 additions and 83 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ If you **have any question, please [click here to read FAQ(Chinese Version)](htt
<td><b><a href="http://www.jielem.com/">JieLeMa</a></b></td>
</tr>
<tr align="center">
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/os.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/jietiao.png" width="80" height="80"/></td>
<td><img src="https://raw.githubusercontent.com/wiki/Qihoo360/RePlugin/img/apps/qihoo_os.jpg" width="80" height="80"/></td>
<td><img src="https://raw.githubusercontent.com/wiki/Qihoo360/RePlugin/img/apps/qihoo_jietiao.jpg" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
Expand Down
6 changes: 3 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ RePlugin的使用方法非常简单,大部分情况下和“单品”开发无

若您是**第一次接触RePlugin,则[请点击这里阅读《快速上手》](https://github.com/Qihoo360/RePlugin/wiki/%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B)**,跟随我们的指引,了解更多的内容。

若您想**了解更多有关RePlugin的玩法,则[请点击这里阅读《详细教程》](https://github.com/Qihoo360/RePlugin/wiki/%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B)**了解更多好玩的玩法。
若您想**了解更多有关RePlugin的玩法,则[请点击这里阅读《详细教程》](https://github.com/Qihoo360/RePlugin/wiki/%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B)**了解更多好玩的玩法。

若您想**看下RePlugin的Sample工程,进而了解框架的具体用法,则[请点击这里查看Sample源代码](https://github.com/Qihoo360/RePlugin/blob/master/replugin-sample)**

Expand Down Expand Up @@ -118,8 +118,8 @@ RePlugin的使用方法非常简单,大部分情况下和“单品”开发无
       <td><b><a href="http://www.jielem.com/">借了吗</a></b></td>
</tr>
<tr align="center">
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/os.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/jietiao.png" width="80" height="80"/></td>
<td><img src="https://raw.githubusercontent.com/wiki/Qihoo360/RePlugin/img/apps/qihoo_os.jpg" width="80" height="80"/></td>
<td><img src="https://raw.githubusercontent.com/wiki/Qihoo360/RePlugin/img/apps/qihoo_jietiao.jpg" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
<td><img src="https://github.com/Qihoo360/RePlugin/wiki/img/apps/yourapps.png" width="80" height="80"/></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,11 @@ private HashMap<String, String> getConfigProcessMap(ApplicationInfo appInfo) {
private void adjustPluginProcess(ApplicationInfo appInfo) {
HashMap<String, String> processMap = getConfigProcessMap(appInfo);
if (processMap == null || processMap.isEmpty()) {
processMap = genDynamicProcessMap();

PluginInfo pi = MP.getPlugin(mPluginName, false);
if (pi != null && pi.getFrameworkVersion() >= 4) {
processMap = genDynamicProcessMap();
}
}

if (LOG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.content.pm.ProviderInfo;
import android.content.pm.ServiceInfo;
import android.os.IBinder;
import android.os.Parcelable;
import android.os.RemoteException;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
Expand Down Expand Up @@ -229,6 +230,9 @@ static final void cleanIntentPluginParams(Intent intent) {
}

void init() {

RePlugin.getConfig().getCallbacks().initPnPluginOverride();

if (HostConfigHelper.PERSISTENT_ENABLE) {
// (默认)“常驻进程”作为插件管理进程,则常驻进程作为Server,其余进程作为Client
if (IPC.isPersistentProcess()) {
Expand Down Expand Up @@ -381,12 +385,47 @@ private final void refreshPluginMap(List<PluginInfo> plugins) {
}
}

/**
* 把插件Add到插件列表
*
* @param info 待add插件的PluginInfo对象
* @param plugin 待add插件的Plugin对象
*/
private void putPluginObject(PluginInfo info, Plugin plugin) {
// 同时加入PackageName和Alias(如有)
mPlugins.put(info.getPackageName(), plugin);
if (!TextUtils.isEmpty(info.getAlias())) {
// 即便Alias和包名相同也可以再Put一次,反正只是覆盖了相同Value而已
mPlugins.put(info.getAlias(), plugin);
if (mPlugins.containsKey(info.getAlias()) || mPlugins.containsKey(info.getPackageName())) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "当前内置插件列表中已经有" + info.getName() + ",需要看看谁的版本号大。");
}

// 找到已经存在的
Plugin existedPlugin = mPlugins.get(info.getPackageName());
if (existedPlugin == null) {
existedPlugin = mPlugins.get(info.getAlias());
}

if (existedPlugin.mInfo.getVersion() < info.getVersion()) {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "新传入的纯APK插件, name=" + info.getName() + ", 版本号比较大,ver=" + info.getVersion() + ",以TA为准。");
}

// 同时加入PackageName和Alias(如有)
mPlugins.put(info.getPackageName(), plugin);
if (!TextUtils.isEmpty(info.getAlias())) {
// 即便Alias和包名相同也可以再Put一次,反正只是覆盖了相同Value而已
mPlugins.put(info.getAlias(), plugin);
}
} else {
if (LOG) {
LogDebug.d(PLUGIN_TAG, "新传入的纯APK插件" + info.getName() + "版本号还没有内置的大,什么都不做。");
}
}
} else {
// 同时加入PackageName和Alias(如有)
mPlugins.put(info.getPackageName(), plugin);
if (!TextUtils.isEmpty(info.getAlias())) {
// 即便Alias和包名相同也可以再Put一次,反正只是覆盖了相同Value而已
mPlugins.put(info.getAlias(), plugin);
}
}
}

Expand Down Expand Up @@ -1133,7 +1172,7 @@ final void newPluginFound(PluginInfo info, boolean persistNeedRestart) {

// 通知本进程:通知给外部使用者
Intent intent = new Intent(RePluginConstants.ACTION_NEW_PLUGIN);
intent.putExtra(RePluginConstants.KEY_PLUGIN_INFO, info);
intent.putExtra(RePluginConstants.KEY_PLUGIN_INFO, (Parcelable) info);
intent.putExtra(RePluginConstants.KEY_PERSIST_NEED_RESTART, persistNeedRestart);
intent.putExtra(RePluginConstants.KEY_SELF_NEED_RESTART, mNeedRestart);
LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.pm.ActivityInfo;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcelable;
import android.os.RemoteException;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
Expand Down Expand Up @@ -256,6 +257,10 @@ public void regReceiver(String plugin, Map rcvFilMap) throws RemoteException {
return;
}

if (rcvFilMap == null) {
return;
}

HashMap<String, List<IntentFilter>> receiverFilterMap = (HashMap<String, List<IntentFilter>>) rcvFilMap;

// 遍历此插件中所有静态声明的 Receiver
Expand Down Expand Up @@ -378,7 +383,7 @@ private void syncInstalledPluginInfo2All(PluginInfo pi) {
// 通知其它进程去更新
Intent intent = new Intent(PmBase.ACTION_NEW_PLUGIN);
intent.putExtra(RePluginConstants.KEY_PERSIST_NEED_RESTART, mNeedRestart);
intent.putExtra("obj", needToSyncPi);
intent.putExtra("obj", (Parcelable) needToSyncPi);
IPC.sendLocalBroadcast2AllSync(mContext, intent);

if (LOG) {
Expand All @@ -394,7 +399,7 @@ private void syncUninstalledPluginInfo2All(PluginInfo pi) {

// 给各进程发送广播,同步更新
final Intent intent = new Intent(PluginInfoUpdater.ACTION_UNINSTALL_PLUGIN);
intent.putExtra("obj", pi);
intent.putExtra("obj", (Parcelable) pi);
// 注意:若在attachBaseContext中调用此方法,则由于此时getApplicationContext为空,导致发送广播时会出现空指针异常。
// 则应该Post一下,待getApplicationContext有值后再发送广播。
if (RePluginInternal.getAppContext().getApplicationContext() != null) {
Expand Down Expand Up @@ -459,7 +464,7 @@ public boolean pluginExtracted(String path) throws RemoteException {
// 通知其它进程
Intent intent = new Intent(PmBase.ACTION_NEW_PLUGIN);
intent.putExtra(RePluginConstants.KEY_PERSIST_NEED_RESTART, mNeedRestart);
intent.putExtra("obj", info);
intent.putExtra("obj", (Parcelable) info);
IPC.sendLocalBroadcast2AllSync(mContext, intent);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ public boolean isPluginBlocked(PluginInfo pluginInfo) {
// Nothing, allow all
return false;
}
}

/**
* 为了p-n插件初始化PluginOverride逻辑,只有老插件方案使用
* 可以通过该回调,在进程初始化时,设置插件的override逻辑(每个进程都会调到)
*
* @since 2.2.2
*/
public void initPnPluginOverride() {
// default, do Nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public final class RePluginConfig {
private boolean printDetailLog = false;
private int defaultFrameworkVersion = 4;

private String hostVersionName = "";
private String hostBuildID = "";

private boolean optimizeArtLoadDex = false;

/**
* 获取插件回调方法。通常无需调用此方法。
*
Expand Down Expand Up @@ -199,6 +204,66 @@ public RePluginConfig setMoveFileWhenInstalling(boolean moveFileWhenInstalling)
return this;
}

/**
* 获取宿主的 BuildID
*
* @return 宿主的BuildID
* @since 2.2.2
*/
public String getHostBuildID() {
return hostBuildID;
}

/**
* 设置宿主的 BuildID <p>
* BuildID 是一个比 VersionName 和 VersionCode 更细的维度(例如:服务器每 build 一次,版本号加 1)
*
* @param buildID 宿主的BuildID
* @return RePluginConfig自己。这样可以连环调用set方法
* @since 2.2.2
*/
public RePluginConfig setHostBuild(String buildID) {
if (!checkAllowModify()) {
return this;
}
hostBuildID = buildID;
return this;
}

/**
* 获取宿主的 VersionName
*
* @since 2.2.2
*/
public String getHostVersionName() {
return hostVersionName;
}

/**
* 设置宿主的 VersionName
*
* @param versionName 宿主的VersionName
* @return RePluginConfig自己。这样可以连环调用set方法
* @since 2.2.2
*/
public RePluginConfig setHostVersionName(String versionName) {
if (!checkAllowModify()) {
return this;
}
hostVersionName = versionName;
return this;
}

/**
* 获取宿主的VersionBuild号
*
* @return
* @since 2.2.2
*/
public String getHostVersionBuild() {
return RePlugin.getConfig().getHostVersionName() + "." + RePlugin.getConfig().getHostBuildID();
}

/**
* 是否打印更详细的日志?
*
Expand Down Expand Up @@ -274,4 +339,28 @@ private boolean checkAllowModify() {
}
return true;
}
}

/**
* 是否在Art上对首次加载插件速度做优化
*
* @return
*/
public boolean isOptimizeArtLoadDex() {
return optimizeArtLoadDex;
}

/**
* 是否在Art上对首次加载插件速度做优化,默认为false
*
* @param optimizeArtLoadDex
* @return
* @since 2.2.2
*/
public RePluginConfig setOptimizeArtLoadDex(boolean optimizeArtLoadDex) {
if (!checkAllowModify()) {
return this;
}
this.optimizeArtLoadDex = optimizeArtLoadDex;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ public void handleMessage(Message msg) {
Bundle data = msg.getData();
Intent intent = data.getParcelable("intent");

if (intent != null) {
ServiceRecord sr = retrieveServiceLocked(intent);
if (sr != null) {
sr.service.onStartCommand(intent, 0, 0);
} else {
if (LOG) {
LogDebug.e(PLUGIN_TAG, "pss.onStartCommand fail.");
}
ServiceRecord sr = (ServiceRecord)msg.obj;

if (intent != null && sr != null) {
sr.service.onStartCommand(intent, 0, 0);
}else{
if (LOG) {
LogDebug.e(PLUGIN_TAG, "pss.onStartCommand fail.");
}
}
break;
Expand Down Expand Up @@ -152,7 +151,7 @@ ComponentName startServiceLocked(Intent intent, Messenger client) {
Bundle data = new Bundle();
data.putParcelable("intent", intent);
message.setData(data);

message.obj = sr;
mHandler.sendMessage(message);

return cn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* 用来表示一个Service对象的信息
* 包含绑定此Service的连接信息、Intent绑定信息等
*
* <p>
* NOTE 类似于Android的ServiceRecord
*
* @author RePlugin Team
Expand Down Expand Up @@ -110,7 +110,7 @@ public boolean hasAutoCreateConnections() {

@Override
public String toString() {
return "[srv=" + service.getClass().getName() + "; startRequested=" + startRequested + "; bindings=(" + bindings.size() + ") " + bindings + "]";
return "[srv=" + service == null ? "null" : service.getClass().getName() + "; startRequested=" + startRequested + "; bindings=(" + bindings.size() + ") " + bindings + "]";
}

public String getPlugin() {
Expand Down
Loading

0 comments on commit 811dfda

Please sign in to comment.