同步212 版本
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package com.mogo.launcher;
|
||||
|
||||
import com.mogo.eagle.core.function.main.MainMoGoApplication;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.LogLevel;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
|
||||
import com.mogo.launcher.crash.CrashSystem;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
@@ -13,6 +18,45 @@ import com.mogo.launcher.crash.CrashSystem;
|
||||
*/
|
||||
public class MogoApplication extends MainMoGoApplication {
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
// ThreadConfig.Builder builder = new ThreadConfig.Builder().listener(new ThreadConfig.TaskExecuteListener() {
|
||||
// @Override
|
||||
// public boolean isEnabled() {
|
||||
// return true; // 如果返回true,会有后续的回调;如果返回false, 不会有后续的回调
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onExecutorBefore(@NonNull Runnable runnable, @NonNull ThreadConfig.TaskType type) {
|
||||
// //每个任务执行前回调
|
||||
//// if (type == ThreadConfig.TaskType.HandlerThread) {
|
||||
////
|
||||
////
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onExecutorAfter(@NonNull Runnable runnable, @NonNull ThreadConfig.TaskType type) {
|
||||
// //每个任务执行后回调
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param core 线程池的核心数
|
||||
// * @param max 线程池的最大线程数
|
||||
// * @param active 线程池正在活跃的任务数
|
||||
// * @param completed 线程池已完成的任务数
|
||||
// */
|
||||
// @Override
|
||||
// public void onExecutorStateChanged(@NonNull ThreadPoolExecutor pool, int core, int max, int active, long completed) {
|
||||
// //线程池在执行过程,状态变化回调
|
||||
// //Log.d("POOL", "core:" + core + ";max:" + max + ";active:" + active + ";completed:" + completed);
|
||||
// }
|
||||
// });
|
||||
// builder.loggable(false);
|
||||
// ThreadManager.INSTANCE.init(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initCrashConfig() {
|
||||
CrashSystem crashSystem = CrashSystem.getInstance(this);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.mogo.launcher.lancet
|
||||
|
||||
import android.database.sqlite.*
|
||||
import androidx.annotation.*
|
||||
import com.knightboost.lancet.api.*
|
||||
import com.knightboost.lancet.api.annotations.*
|
||||
import com.knightboost.lancet.api.annotations.Weaver
|
||||
|
||||
/**
|
||||
* 此类主要用来修正三方库引起的崩溃
|
||||
*/
|
||||
@Keep
|
||||
@Weaver
|
||||
@Group("leak_canary_crash_fix")
|
||||
class LeakCanaryCrashFix {
|
||||
|
||||
@Insert
|
||||
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
|
||||
@TargetMethod(methodName = "getReadableDatabase")
|
||||
fun proxyGetReadableSQLiteDb(): SQLiteDatabase? {
|
||||
try {
|
||||
return Origin.call() as SQLiteDatabase?
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@Insert
|
||||
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
|
||||
@TargetMethod(methodName = "getWritableDatabase")
|
||||
fun proxyGetWritableSQLiteDb(): SQLiteDatabase? {
|
||||
try {
|
||||
return Origin.call() as SQLiteDatabase?
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@Insert
|
||||
@TargetClass("leakcanary.internal.activity.db.ScopedLeaksDb\$DbOpener")
|
||||
@TargetMethod(methodName = "close")
|
||||
fun proxyClose() {
|
||||
try {
|
||||
Origin.callVoid()
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_FAIL
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_LOST
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_CLOUD_CONNECT_SUCCESS
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_CLOUD_SHOW
|
||||
import com.mogo.eagle.core.data.deva.chain.ChainConstant.Companion.CHAIN_LINK_LOG_CONNECT_STATUS
|
||||
import com.mogo.eagle.core.data.map.MogoLocation
|
||||
@@ -37,6 +38,7 @@ import com.mogo.eagle.core.utilcode.util.AppUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ProcessUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadPoolService
|
||||
import com.mogo.eagle.core.utilcode.util.TimeUtils
|
||||
import com.mogo.map.location.GDLocationClient
|
||||
import com.mogo.module.common.constants.HostConst
|
||||
import com.rousetime.android_startup.AndroidStartup
|
||||
import com.zhjt.mogo_core_function_devatools.env.EnvChangeManager
|
||||
@@ -59,6 +61,8 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
|
||||
private var context: Context? = null
|
||||
|
||||
private var gotToken = false
|
||||
|
||||
override fun callCreateOnMainThread() = true
|
||||
|
||||
override fun waitOnMainThread() = false
|
||||
@@ -73,12 +77,17 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
override fun create(context: Context): Boolean {
|
||||
this.context = context
|
||||
if (ProcessUtils.isMainProcess(context)) {
|
||||
initGDLoc()
|
||||
initHttpDns()
|
||||
initCloudClientConfig()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun initGDLoc() {
|
||||
GDLocationClient.getInstance(context).start()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 HttpDNS ,这里会通过一个接口获取所有鹰眼中使用的微服务域名以及端口号
|
||||
* 后续的网络请求会通过 HttpDnsInterceptor 进行拦截替换
|
||||
@@ -125,10 +134,8 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
//设置长链接的secretKey //todo 通过SHA1和包名找中台服务生成,后续包名分渠道,需要做对应操作
|
||||
clientConfig.secretKey = "YMj2VFDFxJ3Q4gNoZceJ"
|
||||
|
||||
// todo 使用旧链路
|
||||
// clientConfig.setUseOriginSocket(true);
|
||||
clientConfig.iHttpDnsCurrentLocation = object : IHttpDnsCurrentLocation {
|
||||
override fun getCurrentLocation(): HttpDnsSimpleLocation? {
|
||||
override fun getCurrentLocation(): HttpDnsSimpleLocation {
|
||||
val envConfig = EnvChangeManager.getEnvConfig()
|
||||
if (envConfig != null) {
|
||||
return HttpDnsSimpleLocation(envConfig.cityCode, envConfig.lat, envConfig.lon)
|
||||
@@ -140,13 +147,23 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
mogoLocation = locationClient.lastKnowLocation
|
||||
}
|
||||
val httpDnsSimpleLocation =
|
||||
if (mogoLocation != null && mogoLocation.latitude != 0.0 && mogoLocation.longitude != 0.0
|
||||
) {
|
||||
HttpDnsSimpleLocation(
|
||||
mogoLocation.cityCode,
|
||||
mogoLocation.latitude,
|
||||
mogoLocation.longitude
|
||||
)
|
||||
if (mogoLocation != null && mogoLocation.latitude != 0.0 && mogoLocation.longitude != 0.0) {
|
||||
if (mogoLocation.cityCode.isNullOrEmpty() && !GDLocationClient.getInstance(
|
||||
context
|
||||
).lastCityCode.isNullOrEmpty()
|
||||
) {
|
||||
HttpDnsSimpleLocation(
|
||||
GDLocationClient.getInstance(context).lastCityCode,
|
||||
mogoLocation.latitude,
|
||||
mogoLocation.longitude
|
||||
)
|
||||
} else {
|
||||
HttpDnsSimpleLocation(
|
||||
mogoLocation.cityCode,
|
||||
mogoLocation.latitude,
|
||||
mogoLocation.longitude
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val ciyCode =
|
||||
SharedPrefsMgr.getInstance(
|
||||
@@ -171,7 +188,6 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
// e.printStackTrace();
|
||||
HttpDnsSimpleLocation("010", 1.0, 1.0)
|
||||
}
|
||||
//CallerLogger.INSTANCE.d(M_HMI + TAG, "使用缓存GPS信息:" + httpDnsSimpleLocation);
|
||||
}
|
||||
return httpDnsSimpleLocation
|
||||
}
|
||||
@@ -184,15 +200,19 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
MoGoAiCloudClient.getInstance().init(context, clientConfig).addTokenCallbacks(
|
||||
object : IMoGoTokenCallback {
|
||||
override fun onTokenGot(token: String, sn: String) {
|
||||
CallerLogger.d(SceneConstant.M_HMI + TAG, "onTokenGot ")
|
||||
clientConfig.token = token
|
||||
CallerCloudListenerManager.invokeCloudTokenGot(token)
|
||||
// 异步初始化NetConfig
|
||||
asyncInit()
|
||||
// HttpDns ttl回调 --- socketTTL
|
||||
registerSocketHttpDnsTTL(HostConst.SOCKET_CENTER_DOMAIN)
|
||||
// 开启每5s/次定位上报
|
||||
uploadLocPerFiveSecond()
|
||||
// 由于存在token过期问题,在更新后会回调至此处,增加二次判定
|
||||
if(!gotToken){
|
||||
CallerLogger.d(SceneConstant.M_MAP + TAG, "onTokenGot ")
|
||||
CallerCloudListenerManager.invokeCloudTokenGot(token)
|
||||
// 异步初始化NetConfig
|
||||
asyncInit()
|
||||
// HttpDns ttl回调 --- socketTTL
|
||||
registerSocketHttpDnsTTL(HostConst.SOCKET_CENTER_DOMAIN)
|
||||
// 开启每5s/次定位上报
|
||||
uploadLocPerFiveSecond()
|
||||
gotToken = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(code: Int, msg: String) {
|
||||
@@ -236,7 +256,15 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
*/
|
||||
private fun registerSocketHttpDnsTTL(host: String?) {
|
||||
mogoHttpDns.addressChangedListener(object : OnAddressChangedListener {
|
||||
override fun onAddressChanged(address: Map<String, String>?) {
|
||||
@ChainLog(
|
||||
linkChainLog = CHAIN_LINK_LOG_CONNECT_STATUS,
|
||||
linkCode = CHAIN_LINK_CLOUD_SHOW,
|
||||
endpoint = PAD,
|
||||
nodeAliasCode = CHAIN_ALIAS_CODE_HTTP_DNS_CHANGED,
|
||||
paramIndexes = [0, 1],
|
||||
clientPkFileName = "sn"
|
||||
)
|
||||
override fun onAddressChanged(cityCode: String, address: Map<String, String>?) {
|
||||
val dnsCacheIp = mogoHttpDns.getCachedHttpDnsIps(
|
||||
host,
|
||||
HttpDnsConst.HTTP_DNS_ADDRESS_TYPE_HTTP
|
||||
@@ -314,6 +342,18 @@ class HttpDnsStartUp : AndroidStartup<Boolean>() {
|
||||
CallerLogger.d(SceneConstant.M_HMI + TAG, "socket-onConnectLost")
|
||||
DebugConfig.setDownloadSnapshot(false)
|
||||
}
|
||||
|
||||
@ChainLog(
|
||||
linkChainLog = CHAIN_LINK_LOG_CONNECT_STATUS,
|
||||
linkCode = CHAIN_LINK_CLOUD_SHOW,
|
||||
endpoint = PAD,
|
||||
nodeAliasCode = CHAIN_ALIAS_CODE_CLOUD_CONNECT_LOST,
|
||||
paramIndexes = [0, 1],
|
||||
clientPkFileName = "sn"
|
||||
)
|
||||
override fun onError(code: String, msg: String?) {
|
||||
CallerLogger.d(SceneConstant.M_HMI + TAG, "socket-onConnectLost")
|
||||
}
|
||||
})
|
||||
// 开启Socket长链服务
|
||||
val lat = location.latitude
|
||||
|
||||
Reference in New Issue
Block a user