add new func of logcatch
This commit is contained in:
@@ -82,7 +82,6 @@ mogobaseserviceapk : "com.mogo.base:services-apk:${MOGO_COMMONS_VERSIO
|
||||
mogobasewebsocketsdk : "com.mogo.base:websocket-sdk:${MOGO_COMMONS_VERSION}",
|
||||
mogowebsocket : "com.mogo.module.carchatting:module-carchatt-socket:${MOGO_COMMONS_VERSION}",
|
||||
mogologlib : "com.mogo.module:module-loglib:${MOGO_COMMONS_VERSION}",
|
||||
mogomonitor : "com.mogo.module:module-monitor:${MOGO_COMMONS_VERSION}",
|
||||
mogomodulewidgets : "com.mogo.module:module-widgets:${MOGO_COMMONS_VERSION}",
|
||||
kotlingradleplugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${MOGO_COMMONS_VERSION}",
|
||||
skinsupport : "com.mogo.skin:skin-support:${MOGO_COMMONS_VERSION}",
|
||||
|
||||
@@ -180,7 +180,6 @@ ext {
|
||||
mogobasewebsocketsdk : "com.mogo.base:websocket-sdk:${MOGO_BASE_WEBSOCKET_SDK_VERSION}",
|
||||
mogowebsocket : "com.mogo.module.carchatting:module-carchatt-socket:${WEBSOCKET_VERSION}",
|
||||
mogologlib : "com.mogo.module:module-loglib:${LOGLIB_VERSION}",
|
||||
mogomonitor : "com.mogo.module:module-monitor:${MOGO_MODULE_MONITOR_VERSION}",
|
||||
mogomodulewidgets : "com.mogo.module:module-widgets:${MOGO_MODULE_WIDGETS_VERSION}",
|
||||
kotlingradleplugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}",
|
||||
skinsupport : "com.mogo.skin:skin-support:${MOGO_SKIN_SUPPORT_VERSION}",
|
||||
|
||||
@@ -17,6 +17,7 @@ android {
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
|
||||
//ARouter apt 参数
|
||||
kapt {
|
||||
useBuildCache = false
|
||||
@@ -42,17 +43,27 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
implementation rootProject.ext.dependencies.androidxconstraintlayout
|
||||
|
||||
implementation rootProject.ext.dependencies.kotlinstdlibjdk7
|
||||
implementation rootProject.ext.dependencies.coroutinescore
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
implementation rootProject.ext.dependencies.mogologlib
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
compileOnly rootProject.ext.dependencies.modulecommon
|
||||
} else {
|
||||
compileOnly project(':modules:mogo-module-common')
|
||||
}
|
||||
}
|
||||
implementation rootProject.ext.dependencies.mogoserviceapi
|
||||
implementation rootProject.ext.dependencies.modulecommon
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
implementation rootProject.ext.dependencies.mogo_core_utils
|
||||
implementation rootProject.ext.dependencies.mogo_core_function_api
|
||||
implementation rootProject.ext.dependencies.mogo_core_function_call
|
||||
implementation rootProject.ext.dependencies.mogo_core_data
|
||||
}else {
|
||||
implementation project(':services:mogo-service-api')
|
||||
implementation project(':modules:mogo-module-common')
|
||||
|
||||
implementation project(':core:mogo-core-utils')
|
||||
implementation project(':core:mogo-core-function-api')
|
||||
implementation project(':core:mogo-core-function-call')
|
||||
implementation project(':core:mogo-core-data')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
GROUP=com.mogo.eagle.core.function.impl
|
||||
POM_ARTIFACT_ID=devatools
|
||||
VERSION_CODE=1
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.zhjt.mogo_core_function_devatools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Launcher" />
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.zhjt.mogo_core_function_devatools
|
||||
|
||||
import android.content.Context
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.eagle.core.function.api.devatools.IDevaToolsProvider
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchManager
|
||||
|
||||
@Route(path = MogoServicePaths.PATH_DEVA_TOOLS)
|
||||
class DevaToolsProvider : IDevaToolsProvider {
|
||||
|
||||
override val functionName: String
|
||||
get() = "DevaToolsProvider"
|
||||
|
||||
override fun init(context: Context) {
|
||||
MogoLogCatchManager.init(context)
|
||||
}
|
||||
|
||||
override fun startLogCatch() {
|
||||
MogoLogCatchManager.startCatchLog()
|
||||
}
|
||||
|
||||
override fun stopLogCatch() {
|
||||
MogoLogCatchManager.stopCatchLog()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
MogoLogCatchManager.onDestroy()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.zhjt.mogo_core_function_devatools.logcatch
|
||||
|
||||
class MogoLogCatchConst {
|
||||
|
||||
companion object{
|
||||
const val LOG_PUSH_TYPE = 500000
|
||||
|
||||
/**
|
||||
* 开始抓日志
|
||||
*/
|
||||
const val START_CATCH_LOG = 1
|
||||
|
||||
/**
|
||||
* 结束抓日志
|
||||
*/
|
||||
const val STOP_CATCH_LOG = 2
|
||||
|
||||
/**
|
||||
* 本应用设置,打开日志
|
||||
*/
|
||||
const val LOCAL_CONFIG_OPEN_LOG = 3
|
||||
|
||||
/**
|
||||
* 本应用设置,关闭日志
|
||||
*/
|
||||
const val LOCAL_CONFIG_CLOSE_LOG = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.zhjt.mogo_core_function_devatools.logcatch
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.eagle.core.function.call.devatools.CallDevaToolsListenerManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.toast.TipToast
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.service.cloud.socket.IMogoOnMessageListener
|
||||
import com.mogo.utils.logger.LogLevel
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.mogo.utils.network.NetConfig
|
||||
import com.zhidao.loglib.bean.RemoteLogPushContent
|
||||
import com.zhidao.loglib.call.LogInfoManagerFactory
|
||||
import com.zhidao.loglib.core.ILogListener
|
||||
import com.zhidao.loglib.core.LogInfoManager
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.LOCAL_CONFIG_CLOSE_LOG
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.LOCAL_CONFIG_OPEN_LOG
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.LOG_PUSH_TYPE
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.START_CATCH_LOG
|
||||
import com.zhjt.mogo_core_function_devatools.logcatch.MogoLogCatchConst.Companion.STOP_CATCH_LOG
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object MogoLogCatchManager : IMogoOnMessageListener<RemoteLogPushContent>, Handler.Callback,
|
||||
ILogListener {
|
||||
|
||||
private const val TAG = "MogoLogCatchManager"
|
||||
private const val MANUAL_CATCH_PKG_NAME = "manual-catch-log"
|
||||
private const val MSG_TRY_CLOSE_LOG = 1001
|
||||
|
||||
private var mContext: Context? = null
|
||||
|
||||
private val handler = Handler(this)
|
||||
private val manualContent = RemoteLogPushContent()
|
||||
private val catchingList: MutableList<String> = mutableListOf()
|
||||
private var logInfoManager: LogInfoManager? = null
|
||||
|
||||
fun init(context: Context) {
|
||||
mContext = context
|
||||
MogoApisHandler.getInstance().apis
|
||||
.getSocketManagerApi(AbsMogoApplication.getApp().applicationContext)
|
||||
.registerOnMessageListener(LOG_PUSH_TYPE, this)
|
||||
manualContent.duration = 60
|
||||
manualContent.pkgName = MANUAL_CATCH_PKG_NAME
|
||||
}
|
||||
|
||||
override fun target(): Class<RemoteLogPushContent> {
|
||||
return RemoteLogPushContent::class.java
|
||||
}
|
||||
|
||||
override fun onMsgReceived(obj: RemoteLogPushContent?) {
|
||||
obj?.let {
|
||||
Logger.d(TAG, "收到push消息: $obj")
|
||||
when (obj.type) {
|
||||
START_CATCH_LOG -> if (!catchingList.contains(obj.pkgName)) {
|
||||
startCatchLog(obj)
|
||||
}
|
||||
STOP_CATCH_LOG -> stopCatchLog(obj)
|
||||
LOCAL_CONFIG_OPEN_LOG -> openLoggerLevel()
|
||||
LOCAL_CONFIG_CLOSE_LOG -> closeLoggerLevel()
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleMessage(msg: Message): Boolean {
|
||||
if (msg.what == MSG_TRY_CLOSE_LOG) {
|
||||
CallDevaToolsListenerManager.invokeDevaToolsLogCatch()
|
||||
closeLoggerLevel()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun startCatchLog() {
|
||||
if (catchingList.contains(MANUAL_CATCH_PKG_NAME)) {
|
||||
TipToast.shortTip("已经在抓取日志了,请稍后再试")
|
||||
} else {
|
||||
Logger.d(TAG, "开始抓取日志====")
|
||||
manualContent.type = START_CATCH_LOG
|
||||
startCatchLog(manualContent)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopCatchLog() {
|
||||
Logger.d(TAG, "结束抓取日志====")
|
||||
manualContent.type = STOP_CATCH_LOG
|
||||
stopCatchLog(manualContent)
|
||||
}
|
||||
|
||||
private fun startCatchLog(content: RemoteLogPushContent) {
|
||||
catchingList.add(content.pkgName)
|
||||
var delay = (content.duration * 60 * 1000).toLong()
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG)
|
||||
if (delay <= 0) {
|
||||
// 如果push 下来的delay小于等于0,那就给个默认最大值一小时
|
||||
delay = 60 * 60 * 1000L
|
||||
}
|
||||
handler.sendEmptyMessageDelayed(MSG_TRY_CLOSE_LOG, delay)
|
||||
openLoggerLevel()
|
||||
logInfoManager = LogInfoManagerFactory.createPushLogInfoManager(mContext, content, this)
|
||||
logInfoManager?.start()
|
||||
}
|
||||
|
||||
private fun stopCatchLog(content: RemoteLogPushContent) {
|
||||
catchingList.remove(content.pkgName)
|
||||
if (catchingList.isEmpty()) {
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG)
|
||||
}
|
||||
logInfoManager?.stop()
|
||||
logInfoManager = null
|
||||
closeLoggerLevel()
|
||||
}
|
||||
|
||||
/**
|
||||
* 放开Logger的限制
|
||||
*/
|
||||
private fun openLoggerLevel() {
|
||||
Logger.init(LogLevel.DEBUG)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态收紧Logger的限制
|
||||
*/
|
||||
private fun closeLoggerLevel() {
|
||||
if (catchingList.isNotEmpty()) {
|
||||
Logger.init(if (DebugConfig.isDebug()) LogLevel.DEBUG else LogLevel.OFF)
|
||||
NetConfig.instance().isLoggable = DebugConfig.isDebug()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(errorCount: Int) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
TipToast.shortTip("日志抓取出现错误,出错数量:$errorCount")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClose(pkgName: String?) {
|
||||
ThreadUtils.runOnUiThread {
|
||||
CallDevaToolsListenerManager.invokeDevaToolsLogCatch()
|
||||
TipToast.shortTip("日志抓取默认计时结束")
|
||||
}
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
MogoApisHandler.getInstance().apis
|
||||
.getSocketManagerApi(AbsMogoApplication.getApp().applicationContext)
|
||||
.unregisterLifecycleListener(LOG_PUSH_TYPE)
|
||||
|
||||
if (handler.hasMessages(MSG_TRY_CLOSE_LOG)) {
|
||||
handler.removeMessages(MSG_TRY_CLOSE_LOG)
|
||||
}
|
||||
manualContent.type = 0
|
||||
logInfoManager = null
|
||||
mContext = null
|
||||
}
|
||||
}
|
||||
@@ -352,4 +352,11 @@ public class MogoServicePaths {
|
||||
@Keep
|
||||
@Deprecated
|
||||
public static final String PATH_MAP_LOCATION_UPDATE_4_AUTO_PILOT = "/map_x/location_update";
|
||||
|
||||
/**
|
||||
* deva开发套件
|
||||
*/
|
||||
@Keep
|
||||
@Deprecated
|
||||
public static final String PATH_DEVA_TOOLS = "/deva/tools";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.mogo.eagle.core.function.api.devatools
|
||||
|
||||
import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider
|
||||
|
||||
/**
|
||||
* 开发套件工具接口
|
||||
*/
|
||||
interface IDevaToolsProvider : IMoGoFunctionServerProvider {
|
||||
|
||||
fun startLogCatch()
|
||||
|
||||
fun stopLogCatch()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.mogo.eagle.core.function.api.devatools
|
||||
|
||||
/**
|
||||
* 开发套件工具接口
|
||||
*/
|
||||
interface IMoGoDevaToolsListener {
|
||||
|
||||
fun onLogCatchClose(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mogo.eagle.core.function.call.devatools
|
||||
|
||||
import androidx.annotation.Nullable
|
||||
import com.mogo.eagle.core.function.api.devatools.IMoGoDevaToolsListener
|
||||
import com.mogo.eagle.core.utilcode.util.LogUtils
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object CallDevaToolsListenerManager {
|
||||
|
||||
private const val TAG = "CallDevaToolsListenerManager"
|
||||
|
||||
private val M_DEVA_TOOLS_LISTENER: ConcurrentHashMap<String, IMoGoDevaToolsListener> =
|
||||
ConcurrentHashMap()
|
||||
|
||||
/**
|
||||
* 添加监听
|
||||
* @param tag 标记,用来注销监听使用
|
||||
* @param listener 监听回调
|
||||
*/
|
||||
fun registerDevaToolsLogCatchListener(
|
||||
@Nullable tag: String,
|
||||
@Nullable listener: IMoGoDevaToolsListener
|
||||
) {
|
||||
if (M_DEVA_TOOLS_LISTENER.containsKey(tag)) {
|
||||
LogUtils.eTag(TAG, "Tag:$tag already exists,please use other tag")
|
||||
return
|
||||
}
|
||||
M_DEVA_TOOLS_LISTENER[tag] = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监听
|
||||
* @param tag 标记,用来注销监听使用
|
||||
*/
|
||||
fun unRegisterDevaToolsLogCatchListener(@Nullable tag: String) {
|
||||
if (!M_DEVA_TOOLS_LISTENER.containsKey(tag)) {
|
||||
LogUtils.eTag(TAG, "Tag:$tag not exists")
|
||||
return
|
||||
}
|
||||
M_DEVA_TOOLS_LISTENER.remove(tag)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除监听
|
||||
* @param listener 要删除的监听对象
|
||||
*/
|
||||
fun unRegisterDevaToolsLogCatchListener(@Nullable listener: IMoGoDevaToolsListener) {
|
||||
if (!M_DEVA_TOOLS_LISTENER.containsValue(listener)) {
|
||||
LogUtils.eTag(TAG, "listener:$listener not exists")
|
||||
return
|
||||
}
|
||||
M_DEVA_TOOLS_LISTENER.forEach {
|
||||
if (it.value == listener) {
|
||||
M_DEVA_TOOLS_LISTENER.remove(it.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun invokeDevaToolsLogCatch() {
|
||||
M_DEVA_TOOLS_LISTENER.forEach {
|
||||
val listener = it.value
|
||||
listener.onLogCatchClose()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,7 +60,7 @@ HOOK_LOG_VERSION=1.4.90
|
||||
SERVICE_CHAIN_VERSION=1.0.32
|
||||
################ 外部依赖引用 ################
|
||||
# loglib
|
||||
LOGLIB_VERSION=1.0.4
|
||||
LOGLIB_VERSION=1.1.4
|
||||
######## MogoAiCloudSDK Version ########
|
||||
# 网络请求
|
||||
MOGO_NETWORK_VERSION=1.3.13
|
||||
|
||||
0
modules-back.txt
Normal file
0
modules-back.txt
Normal file
@@ -38,7 +38,6 @@
|
||||
:modules:mogo-module-main
|
||||
:modules:mogo-module-push-base
|
||||
:modules:mogo-module-push
|
||||
:modules:mogo-module-monitor
|
||||
:core:function-impl:mogo-core-function-autopilot
|
||||
:core:function-impl:mogo-core-function-hmi
|
||||
:core:function-impl:mogo-core-function-map
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-keep class com.zhidao.mogo.module.monitor.MogoMonitorConst.*{*;}
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.module
|
||||
POM_ARTIFACT_ID=module-monitor
|
||||
VERSION_CODE=1
|
||||
@@ -1,5 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.zhidao.mogo.module.monitor">
|
||||
|
||||
/
|
||||
</manifest>
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.zhidao.mogo.module.monitor;
|
||||
|
||||
public class MogoMonitorConst {
|
||||
|
||||
private MogoMonitorConst(){}
|
||||
|
||||
public static final String MODULE_NAME = "MogoMonitor";
|
||||
public static final String MODULE_PATH = "/monitor/api";
|
||||
|
||||
public static final int LOG_PUSH_TYPE = 500000;
|
||||
|
||||
/**
|
||||
* 开始抓日志
|
||||
*/
|
||||
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_LOG_CTRL = "com.mogo.control.action.LOG_CTRL";
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.zhidao.mogo.module.monitor;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.monitor.IMogoMonitorLog;
|
||||
import com.mogo.service.monitor.IMogoMonitorProvider;
|
||||
import com.zhidao.mogo.module.monitor.log.MogoLogMonitor;
|
||||
|
||||
/**
|
||||
* 应用监控模块provider
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
@Route(path = MogoMonitorConst.MODULE_PATH)
|
||||
public class MogoMonitorProvider implements IMogoMonitorProvider {
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
MogoLogMonitor.getInstance().init(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMogoMonitorLog getMogoMonitorLog() {
|
||||
return MogoLogMonitor.getInstance();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.zhidao.mogo.module.monitor.bean;
|
||||
|
||||
public class RemoteLogPushContent {
|
||||
private int type;
|
||||
/**
|
||||
* 日志抓取时长,单位是分钟
|
||||
*/
|
||||
private int duration;
|
||||
private String cmd;
|
||||
private String pkgName;
|
||||
|
||||
public RemoteLogPushContent(){
|
||||
|
||||
}
|
||||
|
||||
public RemoteLogPushContent(int duration, String pkgName) {
|
||||
this.duration = duration;
|
||||
this.pkgName = 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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.zhidao.mogo.module.monitor.dialog;
|
||||
|
||||
/**
|
||||
* Log调试对话框操作回调
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public interface ILogDialogListener {
|
||||
/**
|
||||
* 点击了开始抓日志
|
||||
*/
|
||||
void onLogStart();
|
||||
|
||||
/**
|
||||
* 点击了结束抓日志
|
||||
*/
|
||||
void onLogStop();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
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.eagle.core.network.NetConfig;
|
||||
import com.mogo.eagle.core.network.utils.GsonUtil;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.service.cloud.socket.IMogoOnMessageListener;
|
||||
import com.mogo.service.monitor.IMogoMonitorLog;
|
||||
import com.mogo.utils.logger.LogLevel;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.zhidao.mogo.module.monitor.MogoMonitorConst;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,76 +0,0 @@
|
||||
<?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>
|
||||
@@ -54,7 +54,9 @@ include ':libraries:map-autonavi'
|
||||
include ':libraries:mogo-map'
|
||||
|
||||
// OLD业务模块
|
||||
include ':modules:mogo-module-monitor'
|
||||
include ':modules:tanlulib'
|
||||
include ':modules:mogo-module-widgets'
|
||||
include ':modules:mogo-module-obu'
|
||||
include ':modules:mogo-module-adas'
|
||||
include ':modules:mogo-module-map'
|
||||
include ':modules:mogo-module-common'
|
||||
@@ -82,3 +84,5 @@ include ':test:crashreport-bugly'
|
||||
include ':test:crashreport-noop'
|
||||
include ':test:crashreport-upgrade'
|
||||
|
||||
// deva开发工具套件
|
||||
include ':core:function-impl:mogo-core-function-devatools'
|
||||
|
||||
Reference in New Issue
Block a user