Skip to content

Commit

Permalink
The version was upgraded to v2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cundong committed Sep 25, 2017
1 parent 8085850 commit 5b48b76
Show file tree
Hide file tree
Showing 36 changed files with 625 additions and 129 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

[![license](http://img.shields.io/badge/license-Apache2.0-brightgreen.svg?style=flat)](https://github.com/Qihoo360/RePlugin/blob/master/LICENSE)
[![Release Version](https://img.shields.io/badge/release-2.2.0-brightgreen.svg)](https://github.com/Qihoo360/RePlugin/wiki/%E5%8F%91%E8%A1%8C%E6%B3%A8%E8%AE%B0)
[![Release Version](https://img.shields.io/badge/release-2.2.1-brightgreen.svg)](https://github.com/Qihoo360/RePlugin/wiki/%E5%8F%91%E8%A1%8C%E6%B3%A8%E8%AE%B0)


## RePlugin —— A flexible, stable, easy-to-use Android Plug-in Framework
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>

[![license](http://img.shields.io/badge/license-Apache2.0-brightgreen.svg?style=flat)](https://github.com/Qihoo360/RePlugin/blob/master/LICENSE)
[![Release Version](https://img.shields.io/badge/release-2.2.0-brightgreen.svg)](https://github.com/Qihoo360/RePlugin/wiki/%E5%8F%91%E8%A1%8C%E6%B3%A8%E8%AE%B0)
[![Release Version](https://img.shields.io/badge/release-2.2.1-brightgreen.svg)](https://github.com/Qihoo360/RePlugin/wiki/%E5%8F%91%E8%A1%8C%E6%B3%A8%E8%AE%B0)


## RePlugin —— 历经三年多考验,数亿设备使用的,稳定占坑类插件化方案
Expand Down
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.0"
def static final VER = "2.2.1"

/** 打印信息时候的前缀 */
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.0"
version = "2.2.1"
group = 'com.qihoo360.replugin' // 组名

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ interface IPluginClient {
* @param Intent 广播的 Intent 数据
*/
void onReceive(String plugin, String receiver, in Intent intent);
}

/**
* dump通过插件化框架启动起来的Service信息
*/
String dumpServices();

/**
* dump插件化框架中存储的详细Activity坑位映射表
*/
String dumpActivities();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ interface IPluginHost {

PluginInfo pluginDownloaded(String path);

boolean pluginUninstalled(in PluginInfo info);

boolean pluginExtracted(String path);

oneway void sendIntent2Process(String target, in Intent intent);
Expand Down Expand Up @@ -109,4 +111,9 @@ interface IPluginHost {
* 通过PID来获取进程名
*/
String getProcessNameByPid(int pid);
}

/**
* dump详细的运行时信息
*/
String dump();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface IPluginServiceServer {

int bindService(in Intent intent, in IServiceConnection conn, int flags, in Messenger client);
boolean unbindService(in IServiceConnection conn);
}

String dump();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
public class BuildCompat {

public static final String ARM = "arm";

public static final String ARM64 = "arm64";

public static final String[] SUPPORTED_ABIS;

public static final String[] SUPPORTED_32_BIT_ABIS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2005-2017 Qihoo 360 Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.qihoo360.loader2;

import android.os.IBinder;
import android.util.Log;

import com.qihoo360.replugin.RePluginInternal;

import java.io.FileDescriptor;
import java.io.PrintWriter;

/**
* 运行时 dump 工具类
*
* @author RePlugin Team
*/
public class DumpUtils {

private static final String TAG = RePluginInternal.FOR_DEV ? DumpUtils.class.getSimpleName() : "DumpUtils";

/**
* dump RePlugin框架运行时的详细信息,包括:Activity 坑位映射表,正在运行的 Service,以及详细的插件信息
*
* @param fd
* @param writer
* @param args
*/
public static void dump(FileDescriptor fd, PrintWriter writer, String[] args) {

IBinder binder = PluginProviderStub.proxyFetchHostBinder(RePluginInternal.getAppContext());

if (binder == null) {
return;
}

IPluginHost pluginHost = IPluginHost.Stub.asInterface(binder);

try {
String dumpInfo = pluginHost.dump();

if (RePluginInternal.FOR_DEV) {
Log.d(TAG, "dumpInfo:" + dumpInfo);
}

if (writer != null) {
writer.println(dumpInfo);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ final boolean loadDex(ClassLoader parent, int load) {
mPackageInfo.applicationInfo.sourceDir = mPath;
mPackageInfo.applicationInfo.publicSourceDir = mPath;

if (TextUtils.isEmpty(mPackageInfo.applicationInfo.processName)) {
mPackageInfo.applicationInfo.processName = mPackageInfo.applicationInfo.packageName;
}

// 添加针对SO库的加载
// 此属性最终用于ApplicationLoaders.getClassLoader,在创建PathClassLoader时成为其参数
// 这样findLibrary可不用覆写,即可直接实现SO的加载
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,11 @@ public static final boolean pluginUninstall(String pluginName) {
return true;
}

// 插件已安装
try {
return PluginManagerProxy.uninstall(pi);
} catch (RemoteException e) {
e.printStackTrace();
if (LOG) {
e.printStackTrace();
return PluginProcessMain.getPluginHost().pluginUninstalled(pi);
} catch (Throwable e) {
if (LOGR) {
LogRelease.e(PLUGIN_TAG, "uninstall. error: " + e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
import com.qihoo360.replugin.base.IPC;
import com.qihoo360.replugin.component.process.PluginProcessHost;
import com.qihoo360.replugin.helper.HostConfigHelper;
import com.qihoo360.replugin.helper.JSONHelper;
import com.qihoo360.replugin.helper.LogDebug;
import com.qihoo360.replugin.helper.LogRelease;

import org.json.JSONArray;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -41,6 +45,7 @@
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
import static com.qihoo360.loader2.PluginContainers.ActivityState.toName;
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 @@ -771,4 +776,28 @@ final ActivityState lookupByContainer(String container) {

return null;
}
}

final String dump() {

JSONArray activityArr = new JSONArray();
JSONObject activityObj;

for (Map.Entry<String, ActivityState> entry : mStates.entrySet()) {
String container = entry.getKey();
ActivityState state = entry.getValue();

if (!TextUtils.isEmpty(state.plugin) && !TextUtils.isEmpty(state.activity)) {
activityObj = new JSONObject();
JSONHelper.putNoThrows(activityObj, "process", IPC.getCurrentProcessName());
JSONHelper.putNoThrows(activityObj, "className", container);
JSONHelper.putNoThrows(activityObj, "plugin", state.plugin);
JSONHelper.putNoThrows(activityObj, "realClassName", state.activity);
JSONHelper.putNoThrows(activityObj, "state", toName(state.state));
JSONHelper.putNoThrows(activityObj, "refs", state.refs != null ? state.refs.size() : 0);
activityArr.put(activityObj);
}
}

return activityArr.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public boolean startActivity(Context context, Intent intent) {
+ isDynamicClass(plugin, componentName.getClassName()));
}
if (isDynamicClass(plugin, componentName.getClassName())) {
intent.putExtra(IPluginManager.KEY_COMPATIBLE, true);
intent.setComponent(new ComponentName(IPC.getPackageName(), componentName.getClassName()));
context.startActivity(intent);
return false;
Expand Down Expand Up @@ -225,6 +226,7 @@ public boolean startActivity(Context context, Intent intent, String plugin, Stri
}

if (Factory2.isDynamicClass(plugin, activity)) {
intent.putExtra(IPluginManager.KEY_COMPATIBLE, true);
intent.setComponent(new ComponentName(IPC.getPackageName(), activity));
context.startActivity(intent);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import com.qihoo360.replugin.packages.PluginManagerProxy;
import com.qihoo360.replugin.packages.PluginManagerServer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
Expand Down Expand Up @@ -229,6 +233,10 @@ public String toString() {
}
return super.toString();
}

public IPluginClient getClient() {
return client;
}
}

static final void reportStatus() {
Expand All @@ -242,6 +250,73 @@ static final void reportStatus() {
}
}

static final String dump() {

// 1.dump Activity映射表, service列表
JSONArray activityArr = new JSONArray();
JSONArray serviceArr = new JSONArray();

for (ProcessClientRecord clientRecord : ALL.values()) {
try {
IPluginClient pluginClient = clientRecord.getClient();
if (pluginClient == null) {
continue;
}

String activityDumpInfo = pluginClient.dumpActivities();
if (!TextUtils.isEmpty(activityDumpInfo)) {
JSONArray activityList = new JSONArray(activityDumpInfo);
int activityCount = activityList.length();
if (activityCount > 0) {
for (int i = 0; i < activityCount; i++) {
activityArr.put(activityList.getJSONObject(i));
}
}
}

String serviceDumpInfo = pluginClient.dumpServices();
if (!TextUtils.isEmpty(serviceDumpInfo)) {
JSONArray serviceList = new JSONArray(serviceDumpInfo);
int serviceCount = serviceList.length();
if (serviceCount > 0) {
for (int i = 0; i < serviceCount; i++) {
serviceArr.put(serviceList.getJSONObject(i));
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}

// 2.dump 插件信息表
JSONArray pluginArr = new JSONArray();
List<PluginInfo> pluginList = MP.getPlugins(false);
if (pluginList != null) {
JSONObject pluginObj;
for (PluginInfo pluginInfo : pluginList) {
try {
pluginObj = new JSONObject();
pluginObj.put(pluginInfo.getName(), pluginInfo.toString());
pluginArr.put(pluginObj);
} catch (JSONException e) {
e.printStackTrace();
}
}
}

JSONObject detailObj = new JSONObject();
try {
detailObj.put("activity", activityArr);
detailObj.put("service", serviceArr);
detailObj.put("plugin", pluginArr);
} catch (JSONException e) {
e.printStackTrace();
}

return detailObj.toString();
}

static final void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
if (LogDebug.DUMP_ENABLED) {
writer.println("--- ALL.length = " + ALL.size() + " ---");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,29 @@ final String bindActivity(String plugin, int process, String activity, Intent in
public void onReceive(String plugin, final String receiver, final Intent intent) {
PluginReceiverHelper.onPluginReceiverReceived(plugin, receiver, mReceivers, intent);
}
}

@Override
public String dumpServices() {
try {
IPluginServiceServer pss = fetchServiceServer();
if (pss != null) {
try {
return pss.dump();
} catch (Throwable e) {
if (LOGR) {
LogRelease.e(PLUGIN_TAG, "psc.sts: pss e", e);
}
}
}
} catch (RemoteException e) {
e.printStackTrace();
}

return null;
}

@Override
public String dumpActivities() {
return mACM.dump();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,8 @@ final void callAppCreate() {
if (!IPC.isPersistentProcess()) {
// 由于常驻进程已经在内部做了相关的处理,此处仅需要在UI进程注册并更新即可
registerReceiverAction(ACTION_NEW_PLUGIN);
registerReceiverAction(ACTION_UNINSTALL_PLUGIN);
}
// 由于常驻进程内未做处理,因此需要在常驻和UI进程同时注册并更新缓存信息
registerReceiverAction(ACTION_UNINSTALL_PLUGIN);
}

/**
Expand Down
Loading

0 comments on commit 5b48b76

Please sign in to comment.