opt
This commit is contained in:
@@ -35,7 +35,8 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation rootProject.ext.dependencies.mogologlib
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
|
||||
@@ -8,4 +8,18 @@ class MogoMonitorConst {
|
||||
|
||||
public static final int START_CATCH_LOG = 1;
|
||||
public static final int STOP_CATCH_LOG = 2;
|
||||
/**
|
||||
* 本应用设置,打开日志
|
||||
*/
|
||||
public static final int LOCAL_CONFIG_OPEN_LOG = 3;
|
||||
/**
|
||||
* 本应用设置,关闭日志
|
||||
*/
|
||||
public static final int LOCAL_CONFIG_CLOSE_LOG = 4;
|
||||
|
||||
|
||||
public static final String BROADCAST_START_CATCH_LOG = "com.mogo.controller.action" +
|
||||
".START_CATCH_LOG";
|
||||
public static final String BROADCAST_STOP_CATCH_LOG = "com.mogo.controller.action" +
|
||||
".STOP_CATCH_LOG";
|
||||
}
|
||||
|
||||
@@ -1,58 +1,53 @@
|
||||
package com.zhidao.mogo.module.monitor;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.service.IMogoServiceApis;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.monitor.IMogoMonitorProvider;
|
||||
import com.mogo.utils.logger.LogLevel;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.loglib.ILogListener;
|
||||
import com.zhidao.loglib.LogInfoManager;
|
||||
import com.zhidao.loglib.bean.RemoteLogPushContent;
|
||||
import com.zhidao.loglib.dialog.ILogDialogListener;
|
||||
import com.zhidao.loglib.upload.UploadManager;
|
||||
import com.zhidao.loglib.util.Constant;
|
||||
import com.zhidao.loglib.util.LogInfoManagerFactory;
|
||||
import com.zhidao.loglib.util.LoggingNotice;
|
||||
import com.mogo.utils.network.NetConfig;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* 应用监控模块provider
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
@Route(path = MogoMonitorConst.MODULE_PATH)
|
||||
public class MogoMonitorProvider implements IMogoMonitorProvider, IMogoOnMessageListener<RemoteLogPushContent>, ILogDialogListener , ILogListener {
|
||||
public class MogoMonitorProvider implements IMogoMonitorProvider,
|
||||
IMogoOnMessageListener<RemoteLogPushContent>, ILogDialogListener {
|
||||
private static final String TAG = MogoMonitorConst.MODULE_NAME;
|
||||
private LogInfoManager manualCatchLog = null;
|
||||
private Map<String, LogInfoManager> managerCache = new ArrayMap<>();
|
||||
private Context context;
|
||||
|
||||
private LogDebugDialog logDebugDialog;
|
||||
@Override
|
||||
public void showLogDebugDialog() {
|
||||
if (manualCatchLog == null) {
|
||||
manualCatchLog = LogInfoManagerFactory.createManualLogInfoManager(context,this);
|
||||
}
|
||||
manualCatchLog.showDebugWindow().setDialogListener(this);
|
||||
logDebugDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
IMogoServiceApis apis =
|
||||
(IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context);
|
||||
apis.getSocketManagerApi(context).registerOnMessageListener(MogoMonitorConst.LOG_PUSH_TYPE,this);
|
||||
apis.getSocketManagerApi(context).registerOnMessageListener(MogoMonitorConst.LOG_PUSH_TYPE, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetActivityContext(Context context) {
|
||||
this.context = context;
|
||||
UploadManager.getInstance().init(context);
|
||||
LoggingNotice.getInstance().init(context);
|
||||
logDebugDialog = new LogDebugDialog(context);
|
||||
logDebugDialog.setDialogListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,23 +58,17 @@ public class MogoMonitorProvider implements IMogoMonitorProvider, IMogoOnMessage
|
||||
@Override
|
||||
public void onMsgReceived(RemoteLogPushContent obj) {
|
||||
Logger.d(TAG, "收到push消息: " + obj);
|
||||
switch (obj.getType()){
|
||||
switch (obj.getType()) {
|
||||
case MogoMonitorConst.START_CATCH_LOG:
|
||||
if (managerCache.containsKey(obj.getPkgName())) {
|
||||
Logger.d(TAG, "这个包名的日志正在抓了: " + obj);
|
||||
return;
|
||||
}
|
||||
openLoggerLevel();
|
||||
LogInfoManager infoManager =
|
||||
LogInfoManagerFactory.createPushLogInfoManager(context, obj,this);
|
||||
infoManager.start();
|
||||
managerCache.put(obj.getPkgName(), infoManager);
|
||||
onLogStart();
|
||||
break;
|
||||
case MogoMonitorConst.STOP_CATCH_LOG:
|
||||
LogInfoManager stopManager = managerCache.remove(obj.getPkgName());
|
||||
if (stopManager != null) {
|
||||
stopManager.stop();
|
||||
}
|
||||
onLogStop();
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_OPEN_LOG:
|
||||
openLoggerLevel();
|
||||
break;
|
||||
case MogoMonitorConst.LOCAL_CONFIG_CLOSE_LOG:
|
||||
closeLoggerLevel();
|
||||
break;
|
||||
default:
|
||||
@@ -90,41 +79,31 @@ public class MogoMonitorProvider implements IMogoMonitorProvider, IMogoOnMessage
|
||||
@Override
|
||||
public void onLogStart() {
|
||||
// 这个是通过对话框点击开始的回调
|
||||
isInManualCatchLog = true;
|
||||
Logger.d(TAG,"开始抓取日志====");
|
||||
context.sendBroadcast(new Intent(MogoMonitorConst.BROADCAST_START_CATCH_LOG));
|
||||
openLoggerLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogStop() {
|
||||
// 这个是通过对话框点击结束的回调
|
||||
isInManualCatchLog = false;
|
||||
Logger.d(TAG,"结束抓取日志====");
|
||||
context.sendBroadcast(new Intent(MogoMonitorConst.BROADCAST_STOP_CATCH_LOG));
|
||||
closeLoggerLevel();
|
||||
}
|
||||
private boolean isInManualCatchLog = false;
|
||||
|
||||
/**
|
||||
* 放开Logger的限制
|
||||
*/
|
||||
private void openLoggerLevel(){
|
||||
private void openLoggerLevel() {
|
||||
Logger.init(LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态收紧Logger的限制
|
||||
*/
|
||||
private void closeLoggerLevel(){
|
||||
if (!isInManualCatchLog && managerCache.size() == 0) {
|
||||
Logger.init( BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(String pkgName) {
|
||||
if (pkgName.equals(Constant.MANUAL_PKG_NAME)) {
|
||||
onLogStop();
|
||||
}else{
|
||||
LogInfoManager stopManager = managerCache.remove(pkgName);
|
||||
closeLoggerLevel();
|
||||
}
|
||||
private void closeLoggerLevel() {
|
||||
Logger.init(DebugConfig.isDebug() ? LogLevel.DEBUG : LogLevel.OFF);
|
||||
NetConfig.instance().setLoggable(DebugConfig.isDebug());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zhidao.mogo.module.monitor.bean;
|
||||
|
||||
public class RemoteLogPushContent {
|
||||
private int type;
|
||||
/**
|
||||
* 日志抓取时长,单位是分钟
|
||||
*/
|
||||
private int duration;
|
||||
private String cmd;
|
||||
private String pkgName;
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getCmd() {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public void setCmd(String cmd) {
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public String getPkgName() {
|
||||
return pkgName;
|
||||
}
|
||||
|
||||
public void setPkgName(String pkgName) {
|
||||
this.pkgName = pkgName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RemoteLogPushContent{" +
|
||||
"type=" + type +
|
||||
", duration=" + duration +
|
||||
", cmd='" + cmd + '\'' +
|
||||
", pkgName='" + pkgName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.zhidao.mogo.module.monitor.dialog;
|
||||
|
||||
/**
|
||||
* Log调试对话框操作回调
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public interface ILogDialogListener {
|
||||
/**
|
||||
* 点击了开始抓日志
|
||||
*/
|
||||
void onLogStart();
|
||||
|
||||
/**
|
||||
* 点击了结束抓日志
|
||||
*/
|
||||
void onLogStop();
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.zhidao.mogo.module.monitor.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mogo.module.common.dialog.BaseFloatDialog;
|
||||
import com.zhidao.mogo.module.monitor.R;
|
||||
|
||||
/**
|
||||
* 日志手动调用开始结束的对话框,兼容了智慧出行,覆盖adas浮窗
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class LogDebugDialog extends BaseFloatDialog {
|
||||
public LogDebugDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
setContentView(R.layout.dialog_log_debug);
|
||||
findViewById(R.id.btnStart).setOnClickListener(v -> {
|
||||
if (dialogListener != null) {
|
||||
dialogListener.onLogStart();
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
findViewById(R.id.btnStop).setOnClickListener(v->{
|
||||
if (dialogListener != null) {
|
||||
dialogListener.onLogStop();
|
||||
}
|
||||
|
||||
dismiss();
|
||||
});
|
||||
findViewById(R.id.btnForceClearNotice).setOnClickListener(v->{
|
||||
dismiss();
|
||||
});
|
||||
findViewById(R.id.btnRetryFlow).setOnClickListener(v->{
|
||||
dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
private ILogDialogListener dialogListener;
|
||||
|
||||
public void setDialogListener(ILogDialogListener dialogListener) {
|
||||
this.dialogListener = dialogListener;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="20dp" />
|
||||
<gradient
|
||||
android:angle="-45"
|
||||
android:startColor="#3F4057"
|
||||
android:endColor="#2A2B38" />
|
||||
<padding
|
||||
android:left="20dp"
|
||||
android:right="20dp"
|
||||
android:top="20dp"
|
||||
android:bottom="20dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" >
|
||||
<shape>
|
||||
<corners android:radius="16dp" />
|
||||
<gradient android:angle="135" android:endColor="#CC0033" android:startColor="#FF3366" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<corners android:radius="16dp" />
|
||||
<gradient android:angle="135" android:endColor="#FF3333" android:startColor="#FF3366" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<gradient android:angle="135" android:endColor="#ff113361" android:startColor="#ff124B98" android:type="linear" />
|
||||
<corners android:radius="16dp" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<gradient android:angle="135" android:endColor="#ff1e57a4" android:startColor="#ff1f7eff" android:type="linear" />
|
||||
<corners android:radius="16dp" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" >
|
||||
<shape>
|
||||
<corners android:radius="16dp" />
|
||||
<gradient android:angle="135" android:endColor="#1C1E28" android:startColor="#242737" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<corners android:radius="16dp" />
|
||||
<gradient android:angle="135" android:endColor="#48495E" android:startColor="#616381" />
|
||||
<padding android:right="20dp" android:left="20dp" android:top="10dp" android:bottom="10dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/log_debug_dialog_bg">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/tvLogDebugTitle"
|
||||
android:text="日志抓取工具"
|
||||
android:textSize="28sp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:textColor="#fff" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btnStart"
|
||||
android:background="@drawable/log_debug_start_btn_bg"
|
||||
android:text="开始抓取"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvLogDebugTitle"
|
||||
app:layout_constraintRight_toLeftOf="@+id/btnStop"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textColor="#fff" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btnStop"
|
||||
android:background="@drawable/log_debug_stop_btn_bg"
|
||||
android:text="结束抓取"
|
||||
app:layout_constraintTop_toTopOf="@id/btnStart"
|
||||
app:layout_constraintLeft_toRightOf="@id/btnStart"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:textSize="20sp"
|
||||
android:textColor="#fff" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btnForceClearNotice"
|
||||
android:background="@drawable/log_debug_stop_btn_bg"
|
||||
android:text="关闭日志抓取提示"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnStart"
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="20sp"
|
||||
android:textColor="#fff" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btnRetryFlow"
|
||||
android:background="@drawable/log_debug_retry_btn_bg"
|
||||
android:text="若有上传失败,点此重试"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnForceClearNotice"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
android:textSize="20sp"
|
||||
android:textColor="#fff" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
@@ -226,6 +226,7 @@ public class ShareControl implements IMogoShareManager, IMogoIntentListener, IMo
|
||||
|
||||
@Override
|
||||
public void onCmdSelected(String cmd) {
|
||||
Logger.d(TAG, "收到免唤醒词指令: " + cmd);
|
||||
switch (cmd) {
|
||||
case UNWAKE_CANCEL_SHARE:
|
||||
dismissShareDialog();
|
||||
|
||||
Reference in New Issue
Block a user