[6.6.0]
1、修复埋点中主线程访问网络bug
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.mogo.commons.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.annotation.Keep
|
||||
import androidx.collection.ArrayMap
|
||||
import com.elegant.analytics.Analytics
|
||||
@@ -15,7 +18,10 @@ import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.util.AppUtils
|
||||
import com.mogo.eagle.core.utilcode.util.DateTimeUtils
|
||||
import com.mogo.eagle.core.utilcode.util.NetworkUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import org.json.JSONObject
|
||||
import java.util.TimerTask
|
||||
|
||||
/**
|
||||
* 埋点&数据统计 管理
|
||||
@@ -23,6 +29,23 @@ import org.json.JSONObject
|
||||
*/
|
||||
object MogoAnalyticUtils {
|
||||
|
||||
var network_is_available = false
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val runnable = object : Runnable {
|
||||
override fun run() {
|
||||
NetworkUtils.isAvailableByPingAsync("49.233.99.26", object : Utils.Consumer<Boolean> {
|
||||
override fun accept(isAvailable: Boolean) {
|
||||
network_is_available = isAvailable
|
||||
}
|
||||
})
|
||||
// 这里执行你的任务
|
||||
// 重新安排下一个任务
|
||||
handler.postDelayed(this, 5000) // 每隔5秒执行一次
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Keep
|
||||
fun init(context: Context?, isDebug: Boolean) {
|
||||
// 1 - debug 近实时上报,积累一条埋点上报,或者积累3秒上报一次。
|
||||
@@ -44,6 +67,9 @@ object MogoAnalyticUtils {
|
||||
}
|
||||
}
|
||||
Analytics.getInstance().start(context)
|
||||
|
||||
// 启动定时任务
|
||||
handler.post(runnable)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,12 +80,24 @@ object MogoAnalyticUtils {
|
||||
*/
|
||||
fun track(event: String?, properties: MutableMap<String, Any>) {
|
||||
try {
|
||||
properties["network_type"] = NetworkUtils.getNetworkType()
|
||||
// 自动驾驶工控机相关信息
|
||||
properties["plate_number"] = AppConfigInfo.plateNumber
|
||||
properties["docker_version"] = AppConfigInfo.dockerVersion
|
||||
properties["ipc_mac_address"] = AppConfigInfo.iPCMacAddress
|
||||
properties["protocol_version_number"] = AppConfigInfo.protocolVersionNumber
|
||||
properties["ad_hd_map_version"] = AppConfigInfo.adHdMapVersion
|
||||
properties["car_type"] =
|
||||
AppIdentityModeUtils.getCarType(FunctionBuildConfig.appIdentityMode).name
|
||||
|
||||
|
||||
// 网络状态监听
|
||||
properties["network_address"] = NetworkUtils.getIPAddress(true)
|
||||
properties["network_type"] = NetworkUtils.getNetworkType().name
|
||||
properties["network_ssid"] = NetworkUtils.getSSID()
|
||||
properties["network_wifi_enabled "] = NetworkUtils.getWifiEnabled()
|
||||
properties["network_is_available"] = NetworkUtils.isAvailable()
|
||||
properties["network_is_available_by_ping"] = NetworkUtils.isAvailableByPing("49.233.99.26")
|
||||
properties["network_is_available"] = network_is_available
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
properties["network_type"] = "获取设备网络状态错误"
|
||||
}
|
||||
Analytics.getInstance().track(event, properties)
|
||||
@@ -106,14 +144,6 @@ object MogoAnalyticUtils {
|
||||
AppIdentityModeUtils.getProduct(FunctionBuildConfig.appIdentityMode).name
|
||||
map["time"] = DateTimeUtils.getTimeText(DateTimeUtils.yyyy_MM_dd_HH_mm_ss_SSS)
|
||||
|
||||
// 自动驾驶工控机相关信息
|
||||
map["plate_number"] = AppConfigInfo.plateNumber
|
||||
map["docker_version"] = AppConfigInfo.dockerVersion
|
||||
map["ipc_mac_address"] = AppConfigInfo.iPCMacAddress
|
||||
map["protocol_version_number"] = AppConfigInfo.protocolVersionNumber
|
||||
map["ad_hd_map_version"] = AppConfigInfo.adHdMapVersion
|
||||
map["car_type"] = AppIdentityModeUtils.getCarType(FunctionBuildConfig.appIdentityMode).name
|
||||
|
||||
return map
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user