[3.4.0][Opt]弱网提醒
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.zhjt.mogo_core_function_devatools.weaknetwork
|
||||
|
||||
import androidx.annotation.Keep
|
||||
|
||||
@Keep
|
||||
data class DetectResult(var details: List<PingResult>?) {
|
||||
|
||||
data class PingResult(
|
||||
var detectType: Int,
|
||||
var errorCode: Int,
|
||||
var networkType: Int,
|
||||
var detectIp: String?,
|
||||
var port: Int,
|
||||
var rttStr: String?,
|
||||
var pingLossRate: String?
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.zhjt.mogo_core_function_devatools.weaknetwork
|
||||
|
||||
import android.util.Log
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.weak.network.StubImpl
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
|
||||
@@ -12,7 +13,22 @@ class DetectResultImpl: StubImpl.ReportDetectResultListener {
|
||||
}
|
||||
|
||||
override fun onDetectResult(resultsJson: String?) {
|
||||
resultsJson?.let { invokeWeakResult(it) }
|
||||
resultsJson?.let { json ->
|
||||
kotlin.runCatching {
|
||||
val result = GsonUtils.fromJson(json, DetectResult::class.java)
|
||||
val size = result.details?.size ?: 0
|
||||
var rttSum = 0.0
|
||||
result?.details?.forEach { pingResult ->
|
||||
pingResult.rttStr?.let {
|
||||
rttSum += it.toDouble()
|
||||
}
|
||||
}
|
||||
if (rttSum > 0 && size > 0) {
|
||||
Log.d(TAG, "avg of rtt is:${rttSum / size}ms")
|
||||
}
|
||||
}
|
||||
invokeWeakResult(json)
|
||||
}
|
||||
}
|
||||
|
||||
@ChainLog(
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.mogo.cloud.network.WeakNetworkManager
|
||||
import com.mogo.cloud.network.WeakNetworkManager.setListener
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.weak.network.SdtManager
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
@@ -16,6 +17,10 @@ object WeakNetworkStrategy {
|
||||
// 记录到链路日志中的时间间隔
|
||||
private const val OUTPUT_TIME_INTERVAL = 15000
|
||||
|
||||
private const val WEAK_HTTP_RTT = 1300
|
||||
|
||||
private const val VERY_CONSUMING_TIME_URL = "/yycp-launcherSnapshot/launcherSnapshot/querySnapshotSync"
|
||||
|
||||
private var lastOutputTime = 0L
|
||||
|
||||
private val lock by lazy {
|
||||
@@ -33,6 +38,7 @@ object WeakNetworkStrategy {
|
||||
fun startListen() {
|
||||
setListener(object : WeakNetworkManager.OnWeakHttpListener {
|
||||
override fun onHttpRttReceived(hashCode: Int, url: String, timeStamp: Long) {
|
||||
if (VERY_CONSUMING_TIME_URL in url) return
|
||||
outputLog(url, timeStamp)
|
||||
}
|
||||
|
||||
@@ -57,8 +63,12 @@ object WeakNetworkStrategy {
|
||||
try {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
if (currentTime - lastOutputTime > OUTPUT_TIME_INTERVAL) {
|
||||
invokeWeakResult("url为:$url, 耗时为:$timeStamp${if (isFail) " 连接失败!" else ""}")
|
||||
SdtManager.startActiveCheck()
|
||||
if (timeStamp >= WEAK_HTTP_RTT) {
|
||||
ToastUtils.showShort("当前网络质量差!")
|
||||
} else if (timeStamp in 300 until WEAK_HTTP_RTT) {
|
||||
invokeWeakResult("url为:$url, 耗时为:$timeStamp${if (isFail) " 连接失败!" else ""}")
|
||||
SdtManager.startActiveCheck()
|
||||
}
|
||||
lastOutputTime = currentTime
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user