From 311e5e0af1948249e42ffb43ef470df4678b635d Mon Sep 17 00:00:00 2001 From: zhongchao Date: Thu, 16 Dec 2021 19:20:47 +0800 Subject: [PATCH] add new func of logcatch --- ZD_README/README_VersionHistory.md | 1 - config.gradle | 1 - .../mogo-core-function-devatools}/.gitignore | 0 .../build.gradle | 29 ++- .../gradle.properties | 3 + .../proguard-rules.pro | 0 .../src/main/AndroidManifest.xml | 13 ++ .../DevaToolsProvider.kt | 31 +++ .../logcatch/MogoLogCatchConst.kt | 28 +++ .../logcatch/MogoLogCatchManager.kt | 162 ++++++++++++++ .../core/data/constants/MogoServicePaths.java | 7 + .../api/devatools/IDevaToolsProvider.kt | 13 ++ .../api/devatools/IMoGoDevaToolsListener.kt | 11 + .../devatools/CallDevaToolsListenerManager.kt | 66 ++++++ gradle.properties | 2 +- modules-back.txt | 0 modules.txt | 1 - .../mogo-module-monitor/consumer-rules.pro | 1 - modules/mogo-module-monitor/gradle.properties | 3 - .../src/main/AndroidManifest.xml | 5 - .../mogo/module/monitor/MogoMonitorConst.java | 30 --- .../module/monitor/MogoMonitorProvider.java | 28 --- .../monitor/bean/RemoteLogPushContent.java | 62 ------ .../monitor/dialog/ILogDialogListener.java | 17 -- .../module/monitor/dialog/LogDebugDialog.java | 46 ---- .../module/monitor/log/MogoLogMonitor.java | 199 ------------------ .../main/res/drawable/log_debug_dialog_bg.xml | 13 -- .../res/drawable/log_debug_retry_btn_bg.xml | 17 -- .../res/drawable/log_debug_start_btn_bg.xml | 17 -- .../res/drawable/log_debug_stop_btn_bg.xml | 17 -- .../src/main/res/layout/dialog_log_debug.xml | 76 ------- settings.gradle | 6 +- 32 files changed, 360 insertions(+), 545 deletions(-) rename {modules/mogo-module-monitor => core/function-impl/mogo-core-function-devatools}/.gitignore (100%) rename {modules/mogo-module-monitor => core/function-impl/mogo-core-function-devatools}/build.gradle (60%) create mode 100644 core/function-impl/mogo-core-function-devatools/gradle.properties rename {modules/mogo-module-monitor => core/function-impl/mogo-core-function-devatools}/proguard-rules.pro (100%) create mode 100644 core/function-impl/mogo-core-function-devatools/src/main/AndroidManifest.xml create mode 100644 core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt create mode 100644 core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchConst.kt create mode 100644 core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchManager.kt create mode 100644 core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt create mode 100644 core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IMoGoDevaToolsListener.kt create mode 100644 core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallDevaToolsListenerManager.kt create mode 100644 modules-back.txt delete mode 100644 modules/mogo-module-monitor/consumer-rules.pro delete mode 100644 modules/mogo-module-monitor/gradle.properties delete mode 100644 modules/mogo-module-monitor/src/main/AndroidManifest.xml delete mode 100644 modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorConst.java delete mode 100644 modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorProvider.java delete mode 100644 modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/bean/RemoteLogPushContent.java delete mode 100644 modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/ILogDialogListener.java delete mode 100644 modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/LogDebugDialog.java delete mode 100644 modules/mogo-module-monitor/src/main/res/drawable/log_debug_dialog_bg.xml delete mode 100644 modules/mogo-module-monitor/src/main/res/drawable/log_debug_retry_btn_bg.xml delete mode 100644 modules/mogo-module-monitor/src/main/res/drawable/log_debug_start_btn_bg.xml delete mode 100644 modules/mogo-module-monitor/src/main/res/drawable/log_debug_stop_btn_bg.xml delete mode 100644 modules/mogo-module-monitor/src/main/res/layout/dialog_log_debug.xml diff --git a/ZD_README/README_VersionHistory.md b/ZD_README/README_VersionHistory.md index dc4145150c..4386696855 100644 --- a/ZD_README/README_VersionHistory.md +++ b/ZD_README/README_VersionHistory.md @@ -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}", diff --git a/config.gradle b/config.gradle index ce9ec23bb0..927bb03b04 100644 --- a/config.gradle +++ b/config.gradle @@ -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}", diff --git a/modules/mogo-module-monitor/.gitignore b/core/function-impl/mogo-core-function-devatools/.gitignore similarity index 100% rename from modules/mogo-module-monitor/.gitignore rename to core/function-impl/mogo-core-function-devatools/.gitignore diff --git a/modules/mogo-module-monitor/build.gradle b/core/function-impl/mogo-core-function-devatools/build.gradle similarity index 60% rename from modules/mogo-module-monitor/build.gradle rename to core/function-impl/mogo-core-function-devatools/build.gradle index 67e546d4dc..93b4fab3d8 100644 --- a/modules/mogo-module-monitor/build.gradle +++ b/core/function-impl/mogo-core-function-devatools/build.gradle @@ -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') + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/gradle.properties b/core/function-impl/mogo-core-function-devatools/gradle.properties new file mode 100644 index 0000000000..3a7512bbca --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/gradle.properties @@ -0,0 +1,3 @@ +GROUP=com.mogo.eagle.core.function.impl +POM_ARTIFACT_ID=devatools +VERSION_CODE=1 diff --git a/modules/mogo-module-monitor/proguard-rules.pro b/core/function-impl/mogo-core-function-devatools/proguard-rules.pro similarity index 100% rename from modules/mogo-module-monitor/proguard-rules.pro rename to core/function-impl/mogo-core-function-devatools/proguard-rules.pro diff --git a/core/function-impl/mogo-core-function-devatools/src/main/AndroidManifest.xml b/core/function-impl/mogo-core-function-devatools/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..1c73e6de8b --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/src/main/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt new file mode 100644 index 0000000000..b8ddf3e5f4 --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/DevaToolsProvider.kt @@ -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() + } + +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchConst.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchConst.kt new file mode 100644 index 0000000000..517399f6af --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchConst.kt @@ -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 + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchManager.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchManager.kt new file mode 100644 index 0000000000..e94918d9d7 --- /dev/null +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/logcatch/MogoLogCatchManager.kt @@ -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, 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 = 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 { + 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 + } +} \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java index 363aaaa7db..3ba3375cce 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java @@ -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"; } diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt new file mode 100644 index 0000000000..f2567433fc --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IDevaToolsProvider.kt @@ -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() +} \ No newline at end of file diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IMoGoDevaToolsListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IMoGoDevaToolsListener.kt new file mode 100644 index 0000000000..8db193f375 --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/devatools/IMoGoDevaToolsListener.kt @@ -0,0 +1,11 @@ +package com.mogo.eagle.core.function.api.devatools + +/** + * 开发套件工具接口 + */ +interface IMoGoDevaToolsListener { + + fun onLogCatchClose(){ + + } +} \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallDevaToolsListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallDevaToolsListenerManager.kt new file mode 100644 index 0000000000..6bcd8af8de --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/devatools/CallDevaToolsListenerManager.kt @@ -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 = + 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() + } + } + +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f86512241a..a0e65263a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/modules-back.txt b/modules-back.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/modules.txt b/modules.txt index 9754fd7cae..82bfb58278 100644 --- a/modules.txt +++ b/modules.txt @@ -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 diff --git a/modules/mogo-module-monitor/consumer-rules.pro b/modules/mogo-module-monitor/consumer-rules.pro deleted file mode 100644 index 325fdd3146..0000000000 --- a/modules/mogo-module-monitor/consumer-rules.pro +++ /dev/null @@ -1 +0,0 @@ --keep class com.zhidao.mogo.module.monitor.MogoMonitorConst.*{*;} diff --git a/modules/mogo-module-monitor/gradle.properties b/modules/mogo-module-monitor/gradle.properties deleted file mode 100644 index db3ee2befd..0000000000 --- a/modules/mogo-module-monitor/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -GROUP=com.mogo.module -POM_ARTIFACT_ID=module-monitor -VERSION_CODE=1 diff --git a/modules/mogo-module-monitor/src/main/AndroidManifest.xml b/modules/mogo-module-monitor/src/main/AndroidManifest.xml deleted file mode 100644 index 9fdb2a839e..0000000000 --- a/modules/mogo-module-monitor/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - / - \ No newline at end of file diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorConst.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorConst.java deleted file mode 100644 index cb0e03e1c7..0000000000 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorConst.java +++ /dev/null @@ -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"; -} diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorProvider.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorProvider.java deleted file mode 100644 index 5e8c437531..0000000000 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/MogoMonitorProvider.java +++ /dev/null @@ -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(); - } - -} diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/bean/RemoteLogPushContent.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/bean/RemoteLogPushContent.java deleted file mode 100644 index 0a6da6e2b3..0000000000 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/bean/RemoteLogPushContent.java +++ /dev/null @@ -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 + '\'' + - '}'; - } -} diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/ILogDialogListener.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/ILogDialogListener.java deleted file mode 100644 index 8a97de2cb4..0000000000 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/ILogDialogListener.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.zhidao.mogo.module.monitor.dialog; - -/** - * Log调试对话框操作回调 - * @author tongchenfei - */ -public interface ILogDialogListener { - /** - * 点击了开始抓日志 - */ - void onLogStart(); - - /** - * 点击了结束抓日志 - */ - void onLogStop(); -} diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/LogDebugDialog.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/LogDebugDialog.java deleted file mode 100644 index b26eb35859..0000000000 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/dialog/LogDebugDialog.java +++ /dev/null @@ -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; - } - -} diff --git a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/log/MogoLogMonitor.java b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/log/MogoLogMonitor.java index 5b2f42734b..e69de29bb2 100644 --- a/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/log/MogoLogMonitor.java +++ b/modules/mogo-module-monitor/src/main/java/com/zhidao/mogo/module/monitor/log/MogoLogMonitor.java @@ -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, 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 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 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(); - } -} diff --git a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_dialog_bg.xml b/modules/mogo-module-monitor/src/main/res/drawable/log_debug_dialog_bg.xml deleted file mode 100644 index 012558ce6d..0000000000 --- a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_dialog_bg.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_retry_btn_bg.xml b/modules/mogo-module-monitor/src/main/res/drawable/log_debug_retry_btn_bg.xml deleted file mode 100644 index 0cb65e7650..0000000000 --- a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_retry_btn_bg.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_start_btn_bg.xml b/modules/mogo-module-monitor/src/main/res/drawable/log_debug_start_btn_bg.xml deleted file mode 100644 index c21ba027d9..0000000000 --- a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_start_btn_bg.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_stop_btn_bg.xml b/modules/mogo-module-monitor/src/main/res/drawable/log_debug_stop_btn_bg.xml deleted file mode 100644 index d8e32b922f..0000000000 --- a/modules/mogo-module-monitor/src/main/res/drawable/log_debug_stop_btn_bg.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/modules/mogo-module-monitor/src/main/res/layout/dialog_log_debug.xml b/modules/mogo-module-monitor/src/main/res/layout/dialog_log_debug.xml deleted file mode 100644 index fd3a32aa17..0000000000 --- a/modules/mogo-module-monitor/src/main/res/layout/dialog_log_debug.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - -