remix the log monitor
This commit is contained in:
@@ -373,7 +373,10 @@ dependencies {
|
||||
apply from: "./functions/widgets.gradle"
|
||||
apply from: "./functions/tts.gradle"
|
||||
|
||||
// implementation group: "com.tencent.matrix", name: "matrix-android-lib", version: '0.6.6', changing: true
|
||||
// implementation group: "com.tencent.matrix", name: "matrix-android-commons", version: '0.6.6', changing: true
|
||||
// implementation group: "com.tencent.matrix", name: "matrix-trace-canary", version:'0.6.6', changing: true
|
||||
// implementation group: "com.tencent.matrix", name: "matrix-io-canary", version: '0.6.6', changing: true
|
||||
|
||||
}
|
||||
|
||||
@@ -381,7 +384,7 @@ dependencies {
|
||||
//matrix {
|
||||
// trace {
|
||||
// enable = true //if you don't want to use trace canary, set false
|
||||
// baseMethodMapFile = "${project.buildDir}/matrix_output/Debug.methodmap"
|
||||
// baseMethodMapFile = "${project.projectDir}/matrixOutput/Debug.methodmap"
|
||||
// blackListFile = "${project.projectDir}/matrixTrace/blackMethodList.txt"
|
||||
// }
|
||||
//}
|
||||
@@ -402,3 +405,4 @@ android.applicationVariants.all { variant ->
|
||||
}
|
||||
|
||||
apply from: "./regroup.gradle"
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.bytedance.boost_multidex.BoostMultiDex;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.network.Utils;
|
||||
import com.mogo.launcher.performance.MogoMonitorIO;
|
||||
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
|
||||
import com.mogo.module.back.BackToLauncherConst;
|
||||
import com.mogo.module.carchatting.card.CallChatConstant;
|
||||
@@ -195,6 +196,7 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
@Override
|
||||
protected void attachBaseContext( Context base ) {
|
||||
super.attachBaseContext( base );
|
||||
MogoMonitorIO.getInstance().init(this);
|
||||
BoostMultiDex.install( base );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.mogo.launcher.performance;
|
||||
|
||||
import com.tencent.mrs.plugin.IDynamicConfig;
|
||||
|
||||
public class DynamicConfigImpl implements IDynamicConfig {
|
||||
|
||||
public boolean isFPSEnable(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTraceEnable(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isMatrixEnable(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key, String defStr) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(String key, int defInt) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long get(String key, long defLong) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean get(String key, boolean defBool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float get(String key, float defFloat) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.mogo.launcher.performance;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.tencent.matrix.Matrix;
|
||||
import com.tencent.matrix.iocanary.IOCanaryPlugin;
|
||||
import com.tencent.matrix.iocanary.config.IOConfig;
|
||||
import com.tencent.matrix.trace.TracePlugin;
|
||||
import com.tencent.matrix.trace.config.TraceConfig;
|
||||
|
||||
public class MogoMonitorIO {
|
||||
|
||||
public static MogoMonitorIO getInstance() {
|
||||
return Holder.mogoMonitorIO;
|
||||
}
|
||||
|
||||
private static class Holder {
|
||||
private static final MogoMonitorIO mogoMonitorIO = new MogoMonitorIO();
|
||||
}
|
||||
|
||||
public void init(Application application) {
|
||||
|
||||
Matrix.Builder builder = new Matrix.Builder(application);
|
||||
builder.patchListener(new PluginListenerImpl(application));
|
||||
|
||||
DynamicConfigImpl dynamicConfig = new DynamicConfigImpl();
|
||||
boolean fpsEnable = dynamicConfig.isFPSEnable();
|
||||
boolean matrixEnable = dynamicConfig.isMatrixEnable();
|
||||
boolean traceEnable = dynamicConfig.isTraceEnable();
|
||||
|
||||
TraceConfig traceConfig = new TraceConfig.Builder()
|
||||
.dynamicConfig(dynamicConfig)
|
||||
.enableFPS(fpsEnable)
|
||||
.enableEvilMethodTrace(traceEnable)
|
||||
.enableAnrTrace(traceEnable)
|
||||
.enableStartup(traceEnable)
|
||||
.isDebug(true)
|
||||
.isDevEnv(true)
|
||||
.build();
|
||||
|
||||
TracePlugin tracePlugin = new TracePlugin(traceConfig);
|
||||
builder.plugin(tracePlugin);
|
||||
|
||||
if (matrixEnable) {
|
||||
IOCanaryPlugin ioCanaryPlugin = new IOCanaryPlugin(
|
||||
new IOConfig.Builder().dynamicConfig(dynamicConfig).build());
|
||||
builder.plugin(ioCanaryPlugin);
|
||||
}
|
||||
Matrix.init(builder.build());
|
||||
tracePlugin.start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.mogo.launcher.performance;
|
||||
|
||||
import com.tencent.matrix.report.Issue;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ParseIssueUtil {
|
||||
|
||||
public static String parseIssue(Issue issue, boolean onlyShowContent) {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (!onlyShowContent) {
|
||||
stringBuilder.append(Issue.ISSUE_REPORT_TAG).append(" : ").append(issue.getTag()).append("\n");
|
||||
stringBuilder.append(Issue.ISSUE_REPORT_TYPE).append(" : ").append(issue.getType()).append("\n");
|
||||
stringBuilder.append("key").append(" : ").append(issue.getKey()).append("\n");
|
||||
}
|
||||
|
||||
stringBuilder.append("content :").append("\n");
|
||||
|
||||
return pauseJsonObj(stringBuilder, issue.getContent()).toString();
|
||||
}
|
||||
|
||||
public static StringBuilder pauseJsonObj(StringBuilder builder, JSONObject object) {
|
||||
Iterator<String> iterator = object.keys();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
String val = object.optString(key);
|
||||
builder.append("\t").append(key).append(" : ").append(val).append("\n");
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.launcher.performance;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tencent.matrix.plugin.DefaultPluginListener;
|
||||
import com.tencent.matrix.report.Issue;
|
||||
|
||||
public class PluginListenerImpl extends DefaultPluginListener {
|
||||
|
||||
private static final String TAG = "PluginListenerImpl";
|
||||
|
||||
|
||||
public PluginListenerImpl(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReportIssue(Issue issue) {
|
||||
printIssue(issue);
|
||||
}
|
||||
|
||||
private void printIssue(Issue issue) {
|
||||
String issueMsg = ParseIssueUtil.parseIssue(issue, true);
|
||||
Log.i(TAG,"issueMsg : " + issueMsg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.mogo.module.extensions.entrance;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -258,7 +257,7 @@ public class EntranceFragment extends MvpFragment<EntranceView, EntrancePresente
|
||||
});
|
||||
|
||||
mUploadRoadCondition.setOnLongClickListener(view -> {
|
||||
mApis.getMogoMonitorApi().showLogDebugDialog();
|
||||
mApis.getMogoMonitorApi().getMogoMonitorLog().showLogDebugDialog();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.widget.FrameLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.context.ContextHolderUtil;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.mvp.MvpActivity;
|
||||
@@ -27,7 +26,6 @@ import com.mogo.module.main.cards.MogoModulesManager;
|
||||
import com.mogo.module.main.service.MogoMainService;
|
||||
import com.mogo.module.main.windowview.FloatingViewHandler;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.adas.IMogoADASControlStatusChangedListener;
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
@@ -206,7 +204,6 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
|
||||
// 初始化MonitorModule
|
||||
// IMogoMonitorProvider monitorProvider = (IMogoMonitorProvider) ARouter.getInstance().build(MogoServicePaths.PATH_MOGO_MONITOR).navigation(this);
|
||||
// monitorProvider.resetActivityContext(this);
|
||||
mServiceApis.getMogoMonitorApi().resetActivityContext( this );
|
||||
}
|
||||
|
||||
private void initAdasControlStatusListener() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.zhidao.mogo.module.monitor;
|
||||
|
||||
class MogoMonitorConst {
|
||||
public class MogoMonitorConst {
|
||||
|
||||
private MogoMonitorConst(){}
|
||||
|
||||
public static final String MODULE_NAME = "MogoMonitor";
|
||||
public static final String MODULE_PATH = "/monitor/api";
|
||||
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
package com.zhidao.mogo.module.monitor;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.monitor.IMogoMonitorLog;
|
||||
import com.mogo.service.monitor.IMogoMonitorProvider;
|
||||
import com.mogo.utils.logger.LogLevel;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.NetConfig;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.mogo.module.monitor.bean.RemoteLogPushContent;
|
||||
import com.zhidao.mogo.module.monitor.dialog.ILogDialogListener;
|
||||
import com.zhidao.mogo.module.monitor.dialog.LogDebugDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.zhidao.mogo.module.monitor.log.MogoLogMonitor;
|
||||
|
||||
/**
|
||||
* 应用监控模块provider
|
||||
@@ -30,153 +13,16 @@ import java.util.List;
|
||||
* @author tongchenfei
|
||||
*/
|
||||
@Route(path = MogoMonitorConst.MODULE_PATH)
|
||||
public class MogoMonitorProvider implements IMogoMonitorProvider,
|
||||
IMogoOnMessageListener<RemoteLogPushContent>, ILogDialogListener, Handler.Callback {
|
||||
private static final String TAG = MogoMonitorConst.MODULE_NAME;
|
||||
private static final int MSG_TRY_CLOSE_LOG = 1001;
|
||||
private static final String MANUAL_CATCH_PKG_NAME = "manual-catch-log";
|
||||
private Context context;
|
||||
private LogDebugDialog logDebugDialog;
|
||||
private RemoteLogPushContent manualContent = new RemoteLogPushContent(60,
|
||||
MANUAL_CATCH_PKG_NAME);
|
||||
private Handler handler = new Handler(this);
|
||||
@Override
|
||||
public void showLogDebugDialog() {
|
||||
logDebugDialog.show();
|
||||
}
|
||||
public class MogoMonitorProvider implements IMogoMonitorProvider {
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
|
||||
apis.getSocketManagerApi(context).registerOnMessageListener(MogoMonitorConst.LOG_PUSH_TYPE, this);
|
||||
startRemoteCtrl();
|
||||
}
|
||||
|
||||
private void startRemoteCtrl(){
|
||||
Intent intent = new Intent("com.mogo.remotecontrol.action");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ComponentName comp = new ComponentName("com.mogo.remotecontrol",
|
||||
"com.mogo.remotecontrol.RemoteCtrlService");
|
||||
intent.setComponent(comp);
|
||||
context.startService(intent);
|
||||
Logger.d(TAG, "startRemoteCtrl");
|
||||
MogoLogMonitor.getInstance().init(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetActivityContext(Context context) {
|
||||
this.context = context;
|
||||
logDebugDialog = new LogDebugDialog(context);
|
||||
logDebugDialog.setDialogListener(this);
|
||||
public IMogoMonitorLog getMogoMonitorLog() {
|
||||
return MogoLogMonitor.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<RemoteLogPushContent> target() {
|
||||
return RemoteLogPushContent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(RemoteLogPushContent obj) {
|
||||
Logger.d(TAG, "收到push消息: " + obj);
|
||||
switch (obj.getType()) {
|
||||
case MogoMonitorConst.START_CATCH_LOG:
|
||||
if(!catchingList.contains(obj.getPkgName())){
|
||||
startCatchLog(obj);
|
||||
}
|
||||
break;
|
||||
case MogoMonitorConst.STOP_CATCH_LOG:
|
||||
stopCatchLog(obj);
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_OPEN_LOG:
|
||||
openLoggerLevel();
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_CLOSE_LOG:
|
||||
closeLoggerLevel();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> catchingList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onLogStart() {
|
||||
// 这个是通过对话框点击开始的回调
|
||||
if(catchingList.contains(MANUAL_CATCH_PKG_NAME)){
|
||||
Toast.makeText(context, "已经在抓日志了", Toast.LENGTH_LONG).show();
|
||||
}else {
|
||||
Logger.d(TAG, "开始抓取日志====");
|
||||
manualContent.setType(MogoMonitorConst.START_CATCH_LOG);
|
||||
startCatchLog(manualContent);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onLogStop() {
|
||||
// 这个是通过对话框点击结束的回调
|
||||
Logger.d(TAG,"结束抓取日志====");
|
||||
manualContent.setType(MogoMonitorConst.STOP_CATCH_LOG);
|
||||
stopCatchLog(manualContent);
|
||||
}
|
||||
|
||||
public void sendCtrlBroadcast(RemoteLogPushContent content) {
|
||||
startRemoteCtrl();
|
||||
|
||||
Intent intent = new Intent(MogoMonitorConst.BROADCAST_LOG_CTRL);
|
||||
intent.putExtra("content", GsonUtil.jsonFromObject(content));
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Logger.d(TAG, "sendCtrlBroadcast: " + content);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 放开Logger的限制
|
||||
*/
|
||||
private void openLoggerLevel() {
|
||||
Logger.init(LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态收紧Logger的限制
|
||||
*/
|
||||
private void closeLoggerLevel() {
|
||||
if(!catchingList.isEmpty()) {
|
||||
Logger.init(DebugConfig.isDebug() ? LogLevel.DEBUG : LogLevel.OFF);
|
||||
NetConfig.instance().setLoggable(DebugConfig.isDebug());
|
||||
}
|
||||
}
|
||||
|
||||
private void startCatchLog(RemoteLogPushContent content){
|
||||
catchingList.add(content.getPkgName());
|
||||
|
||||
long delay = content.getDuration() * 60 * 1000;
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG);
|
||||
if (delay <= 0) {
|
||||
// 如果push 下来的delay小于等于0,那就给个默认最大值一小时
|
||||
delay = 60 * 60 * 1000;
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(MSG_TRY_CLOSE_LOG, delay);
|
||||
openLoggerLevel();
|
||||
sendCtrlBroadcast(content);
|
||||
}
|
||||
|
||||
private void stopCatchLog(RemoteLogPushContent content) {
|
||||
catchingList.remove(content.getPkgName());
|
||||
if (catchingList.isEmpty()) {
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG);
|
||||
}
|
||||
sendCtrlBroadcast(content);
|
||||
closeLoggerLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
if (msg.what == MSG_TRY_CLOSE_LOG) {
|
||||
closeLoggerLevel();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
package com.zhidao.mogo.module.monitor.log;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.context.ContextHolderUtil;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.monitor.IMogoMonitorLog;
|
||||
import com.mogo.utils.logger.LogLevel;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.NetConfig;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.mogo.module.monitor.MogoMonitorConst;
|
||||
import com.zhidao.mogo.module.monitor.MogoMonitorProvider;
|
||||
import com.zhidao.mogo.module.monitor.bean.RemoteLogPushContent;
|
||||
import com.zhidao.mogo.module.monitor.dialog.ILogDialogListener;
|
||||
import com.zhidao.mogo.module.monitor.dialog.LogDebugDialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.zhidao.mogo.module.monitor.MogoMonitorConst.LOG_PUSH_TYPE;
|
||||
import static com.zhidao.mogo.module.monitor.MogoMonitorConst.MODULE_NAME;
|
||||
|
||||
public class MogoLogMonitor implements IMogoOnMessageListener<RemoteLogPushContent>, IMogoMonitorLog,
|
||||
ILogDialogListener, Handler.Callback {
|
||||
|
||||
private static final String TAG = MODULE_NAME + "-Log";
|
||||
|
||||
private static volatile MogoLogMonitor mogoLogMonitor;
|
||||
|
||||
private MogoLogMonitor() {
|
||||
|
||||
}
|
||||
|
||||
public static MogoLogMonitor getInstance() {
|
||||
if (mogoLogMonitor == null) {
|
||||
synchronized (MogoLogMonitor.class) {
|
||||
if (mogoLogMonitor == null) {
|
||||
mogoLogMonitor = new MogoLogMonitor();
|
||||
}
|
||||
}
|
||||
}
|
||||
return mogoLogMonitor;
|
||||
}
|
||||
|
||||
private static final int MSG_TRY_CLOSE_LOG = 1001;
|
||||
private static final String MANUAL_CATCH_PKG_NAME = "manual-catch-log";
|
||||
private LogDebugDialog logDebugDialog;
|
||||
private RemoteLogPushContent manualContent = new RemoteLogPushContent(60,
|
||||
MANUAL_CATCH_PKG_NAME);
|
||||
|
||||
private Handler handler = new Handler(this);
|
||||
|
||||
private List<String> catchingList = new ArrayList<>();
|
||||
|
||||
public void init(Context context) {
|
||||
MogoApisHandler.getInstance().getApis()
|
||||
.getSocketManagerApi(AbsMogoApplication.getApp().getApplicationContext())
|
||||
.registerOnMessageListener(LOG_PUSH_TYPE, this);
|
||||
startRemoteCtrl(context);
|
||||
}
|
||||
|
||||
private void startRemoteCtrl(Context context) {
|
||||
Intent intent = new Intent("com.mogo.remotecontrol.action");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ComponentName comp = new ComponentName("com.mogo.remotecontrol",
|
||||
"com.mogo.remotecontrol.RemoteCtrlService");
|
||||
intent.setComponent(comp);
|
||||
context.startService(intent);
|
||||
Logger.d(TAG, "startRemoteCtrl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
if (msg.what == MSG_TRY_CLOSE_LOG) {
|
||||
closeLoggerLevel();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<RemoteLogPushContent> target() {
|
||||
return RemoteLogPushContent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMsgReceived(RemoteLogPushContent obj) {
|
||||
Logger.d(TAG, "收到push消息: " + obj);
|
||||
switch (obj.getType()) {
|
||||
case MogoMonitorConst.START_CATCH_LOG:
|
||||
if (!catchingList.contains(obj.getPkgName())) {
|
||||
startCatchLog(obj);
|
||||
}
|
||||
break;
|
||||
case MogoMonitorConst.STOP_CATCH_LOG:
|
||||
stopCatchLog(obj);
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_OPEN_LOG:
|
||||
openLoggerLevel();
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_CLOSE_LOG:
|
||||
closeLoggerLevel();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogStart() {
|
||||
// 这个是通过对话框点击开始的回调
|
||||
if (catchingList.contains(MANUAL_CATCH_PKG_NAME)) {
|
||||
Toast.makeText(ContextHolderUtil.getContext(), "已经在抓日志了", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Logger.d(TAG, "开始抓取日志====");
|
||||
manualContent.setType(MogoMonitorConst.START_CATCH_LOG);
|
||||
startCatchLog(manualContent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogStop() {
|
||||
// 这个是通过对话框点击结束的回调
|
||||
Logger.d(TAG, "结束抓取日志====");
|
||||
manualContent.setType(MogoMonitorConst.STOP_CATCH_LOG);
|
||||
stopCatchLog(manualContent);
|
||||
}
|
||||
|
||||
public void sendCtrlBroadcast(RemoteLogPushContent content) {
|
||||
startRemoteCtrl(ContextHolderUtil.getContext());
|
||||
Intent intent = new Intent(MogoMonitorConst.BROADCAST_LOG_CTRL);
|
||||
intent.putExtra("content", GsonUtil.jsonFromObject(content));
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Logger.d(TAG, "sendCtrlBroadcast: " + content);
|
||||
ContextHolderUtil.getContext().sendBroadcast(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 放开Logger的限制
|
||||
*/
|
||||
private void openLoggerLevel() {
|
||||
Logger.init(LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态收紧Logger的限制
|
||||
*/
|
||||
private void closeLoggerLevel() {
|
||||
if (!catchingList.isEmpty()) {
|
||||
Logger.init(DebugConfig.isDebug() ? LogLevel.DEBUG : LogLevel.OFF);
|
||||
NetConfig.instance().setLoggable(DebugConfig.isDebug());
|
||||
}
|
||||
}
|
||||
|
||||
private void startCatchLog(RemoteLogPushContent content) {
|
||||
catchingList.add(content.getPkgName());
|
||||
|
||||
long delay = content.getDuration() * 60 * 1000;
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG);
|
||||
if (delay <= 0) {
|
||||
// 如果push 下来的delay小于等于0,那就给个默认最大值一小时
|
||||
delay = 60 * 60 * 1000L;
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(MSG_TRY_CLOSE_LOG, delay);
|
||||
openLoggerLevel();
|
||||
sendCtrlBroadcast(content);
|
||||
}
|
||||
|
||||
private void stopCatchLog(RemoteLogPushContent content) {
|
||||
catchingList.remove(content.getPkgName());
|
||||
if (catchingList.isEmpty()) {
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG);
|
||||
}
|
||||
sendCtrlBroadcast(content);
|
||||
closeLoggerLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showLogDebugDialog() {
|
||||
if (logDebugDialog == null) {
|
||||
logDebugDialog = new LogDebugDialog(ContextHolderUtil.getContext());
|
||||
logDebugDialog.setDialogListener(this);
|
||||
}
|
||||
if (logDebugDialog.isShowing()) {
|
||||
return;
|
||||
}
|
||||
logDebugDialog.show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mogo.service.monitor;
|
||||
|
||||
public interface IMogoMonitorLog {
|
||||
|
||||
/**
|
||||
* 显示日志抓取窗口
|
||||
*/
|
||||
void showLogDebugDialog();
|
||||
}
|
||||
@@ -9,14 +9,11 @@ import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public interface IMogoMonitorProvider extends IProvider {
|
||||
/**
|
||||
* 显示日志抓取窗口
|
||||
*/
|
||||
void showLogDebugDialog();
|
||||
|
||||
/**
|
||||
* 重置context,设置成activity的context
|
||||
* @param context activity的context
|
||||
* 获取日志监控接口
|
||||
* @return
|
||||
*/
|
||||
void resetActivityContext(Context context);
|
||||
IMogoMonitorLog getMogoMonitorLog();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user