[Change]下沉 MoGoApplication 中对初始化的调用

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2021-11-16 11:22:24 +08:00
parent 7b3744813e
commit 2739a20076
10 changed files with 434 additions and 322 deletions

View File

@@ -43,21 +43,95 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Crash日志收集
implementation rootProject.ext.dependencies.crashSdk
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.boostmultidex
implementation rootProject.ext.dependencies.mogologlib
compileOnly rootProject.ext.dependencies.adasapi
compileOnly rootProject.ext.dependencies.adasconfigapi
debugImplementation rootProject.ext.dependencies.debugleakcanary
releaseImplementation rootProject.ext.dependencies.releaseleakcanary
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
kapt rootProject.ext.dependencies.aroutercompiler
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
api rootProject.ext.dependencies.modulemain
implementation rootProject.ext.dependencies.mogoaicloudservicesdk
implementation rootProject.ext.dependencies.mogocommons
implementation rootProject.ext.dependencies.modulecommon
implementation rootProject.ext.dependencies.mogoservice
implementation rootProject.ext.dependencies.moduleV2x
implementation rootProject.ext.dependencies.moduleshare
implementation rootProject.ext.dependencies.tanluupload
implementation rootProject.ext.dependencies.mogomonitor
implementation rootProject.ext.dependencies.moduleextensions
implementation rootProject.ext.dependencies.modulemap
implementation rootProject.ext.dependencies.mogomodulewidgets
implementation rootProject.ext.dependencies.moduleADAS
implementation rootProject.ext.dependencies.mogomoduleback
implementation rootProject.ext.dependencies.moduleapps
implementation rootProject.ext.dependencies.modulepushbase
implementation rootProject.ext.dependencies.modulepush
implementation rootProject.ext.dependencies.callchat
implementation rootProject.ext.dependencies.callchatprovider
implementation rootProject.ext.dependencies.mapcustom
implementation rootProject.ext.dependencies.crashreportupgrade
implementation rootProject.ext.dependencies.crashreportbugly
implementation rootProject.ext.dependencies.moduleservice
implementation rootProject.ext.dependencies.mogo_core_data
implementation rootProject.ext.dependencies.mogo_core_function_obu_mogo
implementation rootProject.ext.dependencies.mogo_core_function_smp
implementation rootProject.ext.dependencies.mogo_core_function_hmi
implementation rootProject.ext.dependencies.mogo_core_function_notice
implementation rootProject.ext.dependencies.mogo_core_function_autopilot
implementation rootProject.ext.dependencies.mogo_core_function_check
implementation rootProject.ext.dependencies.mogo_core_function_map
implementation rootProject.ext.dependencies.mogo_core_function_v2x
implementation rootProject.ext.dependencies.mogo_core_function_monitoring
implementation rootProject.ext.dependencies.modulemain
} else {
api project(":modules:mogo-module-main")
implementation project(':foudations:mogo-aicloud-services-sdk')
implementation project(':foudations:mogo-commons')
implementation project(':modules:mogo-module-common')
implementation project(':modules:mogo-module-service')
implementation project(':modules:mogo-module-v2x')
implementation project(':modules:mogo-module-share')
implementation project(':modules:tanlulib')
implementation project(':modules:mogo-module-monitor')
implementation project(':modules:mogo-module-extensions')
implementation project(':modules:mogo-module-map')
implementation project(':modules:mogo-module-widgets')
implementation project(':modules:mogo-module-adas')
implementation project(':modules:mogo-module-back')
implementation project(':modules:mogo-module-apps')
implementation project(":modules:mogo-module-push-base")
implementation project(":modules:mogo-module-push")
implementation project(':modules:mogo-module-carchatting')
implementation project(':modules:mogo-module-carchattingprovider')
implementation project(':libraries:map-custom')
implementation project(':test:crashreport-upgrade')
implementation project(':test:crashreport-bugly')
implementation project(':modules:mogo-module-service')
implementation project(':core:mogo-core-data')
implementation project(':core:function-impl:mogo-core-function-obu-mogo')
implementation project(':core:function-impl:mogo-core-function-smp')
implementation project(':core:function-impl:mogo-core-function-hmi')
implementation project(':core:function-impl:mogo-core-function-autopilot')
implementation project(':core:function-impl:mogo-core-function-check')
implementation project(':core:function-impl:mogo-core-function-map')
implementation project(':core:function-impl:mogo-core-function-notice')
implementation project(':core:function-impl:mogo-core-function-v2x')
implementation project(':core:function-impl:mogo-core-function-monitoring')
implementation project(":modules:mogo-module-main")
}
}

View File

@@ -2,13 +2,29 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.eagle.core.function.main">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application>
<!--保活用-->
<service
android:name="com.zhidao.boot.persistent.lib.PersistentAliveService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.zhidao.boot.persistent.lib.action" />
</intent-filter>
</service>
<activity
android:name="com.zhidao.boot.persistent.lib.PersistentAliveActivity"
android:resizeableActivity="false"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".MainLauncherActivity"
android:clearTaskOnLaunch="true"

View File

@@ -0,0 +1,323 @@
package com.mogo.eagle.core.function.main;
import android.content.Context;
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import com.bytedance.boost_multidex.BoostMultiDex;
import com.mogo.cloud.httpdns.MogoHttpDnsConfig;
import com.mogo.cloud.httpdns.bean.HttpDnsSimpleLocation;
import com.mogo.cloud.passport.IMoGoTokenCallback;
import com.mogo.cloud.passport.MoGoAiCloudClient;
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.constants.SharedPrefsConstants;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.Utils;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.map.MapApiPath;
import com.mogo.module.carchatting.card.CallChatConstant;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.common.constants.HostConst;
import com.mogo.module.main.service.MogoMainService;
import com.mogo.module.push.base.PushUIConstants;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.share.constant.ShareConstants;
import com.mogo.module.v2x.V2XConst;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.cloud.socket.IMogoLifecycleListener;
import com.mogo.test.crashreport.CrashReportConstants;
import com.mogo.test.crashreport.upgrade.UpgradeReportConstants;
import com.mogo.utils.ProcessUtils;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.storage.SharedPrefsMgr;
import com.zhidao.boot.persistent.lib.PersistentManager;
/**
* 默认初始化一些基础服务配置
*/
public abstract class MainMoGoApplication extends AbsMogoApplication {
private static final String TAG = "MogoApplication";
private long start;
@Override
public void onCreate() {
initBuildConfig();
super.onCreate();
if (!shouldInit()) {
return;
}
start = System.currentTimeMillis();
// Crash 日志收集
initCrashConfig();
initLogConfig();
initTipToast();
initModules();
}
@Override
protected boolean shouldInit() {
Logger.w(TAG, "evaluate shouldInit() with: %s", ProcessUtils.getProcessName(Process.myPid()));
return ProcessUtils.isMainProcess(this);
}
/**
* BuildConfig中渠道配置赋值
*/
protected abstract void initBuildConfig();
/**
* 初始化异常采集配置
*/
protected abstract void initCrashConfig();
/**
* 初始化日志
*/
protected abstract void initLogConfig();
@Override
protected void asyncInitImpl() {
super.asyncInitImpl();
}
@Override
protected void initHttpDns() {
super.initHttpDns();
prepareBaseService();
}
/**
* 基础服务passport、location、socket
*/
private void prepareBaseService() {
// 第三方平台的sn是由AI云SDK中服务调用通过服务端生成的
preparePassportEnvironment();
}
private void preparePassportEnvironment() {
// 配置云服务API
MoGoAiCloudClientConfig clientConfig = MoGoAiCloudClientConfig.getInstance();
// 设置网络环境HTTP_DNS_ENV_QA、HTTP_DNS_ENV_RELEASE、HTTP_DNS_ENV_DEV
switch (DebugConfig.getNetMode()) {
case DebugConfig.NET_MODE_DEV:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEV);
break;
case DebugConfig.NET_MODE_QA:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_QA);
break;
case DebugConfig.NET_MODE_DEMO:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_DEMO);
break;
default:
clientConfig.setNetMode(MogoHttpDnsConfig.HTTP_DNS_ENV_RELEASE);
}
// 设置是否是第三APP登录
clientConfig.setThirdLogin(DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE);
// 设置是否输出日志
clientConfig.setShowDebugLog(true);
// 设置是否是直播推流的主播
clientConfig.setAnchor(false);
// 设置从蘑菇AI开放平台获取的APPKey
switch (DebugConfig.getCarMachineType()) {
// 自研车机
case DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE:
clientConfig.setThirdPartyAppKey("wbvpzgar");
break;
// 比亚迪
case DebugConfig.CAR_MACHINE_TYPE_BYD:
clientConfig.setThirdPartyAppKey("bydauto");
break;
// 衡阳-鹰眼项目
case DebugConfig.CAR_MACHINE_TYPE_LENOVO:
clientConfig.setThirdPartyAppKey("pfieouqg");
break;
}
// 设置应用服务AppId 长链、鉴权
if (DebugConfig.getNetMode() == DebugConfig.NET_MODE_RELEASE) {
clientConfig.setServiceAppId("com_mogo_launcher");
} else {
clientConfig.setServiceAppId("com.mogo.launcher");
}
// 设置AI云平台分配给三方应用的签名密钥需要从AI云平台申请
// 设置车机设备的唯一标识(这些表识必须是通过后台录入的设备)
clientConfig.setThirdPartyDeviceId(Utils.getDevicesId());
// 设置循环检测间隔时间
clientConfig.setLoopCheckDelay(5 * 1000);
clientConfig.setIHttpDnsCurrentLocation(() -> {
MogoLocation mogoLocation =
MogoApisHandler.getInstance()
.getApis().getMapServiceApi()
.getSingletonLocationClient(getApp())
.getLastKnowLocation();
HttpDnsSimpleLocation httpDnsSimpleLocation;
if (mogoLocation != null
&& mogoLocation.getLatitude() != 0
&& mogoLocation.getLongitude() != 0) {
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
mogoLocation.getCityCode(),
mogoLocation.getLatitude(),
mogoLocation.getLongitude());
Logger.i(TAG, "使用实时GPS信息" + httpDnsSimpleLocation);
} else {
String ciyCode = SharedPrefsMgr.getInstance(getApp())
.getString(SharedPrefsConstants.LOCATION_CITY_CODE);
String latitude = SharedPrefsMgr.getInstance(getApp())
.getString(SharedPrefsConstants.LOCATION_LATITUDE);
String longitude = SharedPrefsMgr.getInstance(getApp())
.getString(SharedPrefsConstants.LOCATION_LONGITUDE);
try {
httpDnsSimpleLocation = new HttpDnsSimpleLocation(
ciyCode,
Double.parseDouble(latitude),
Double.parseDouble(longitude));
} catch (NumberFormatException e) {
e.printStackTrace();
httpDnsSimpleLocation = new HttpDnsSimpleLocation("010", 1, 1);
}
Logger.i(TAG, "使用缓存GPS信息" + httpDnsSimpleLocation);
}
return httpDnsSimpleLocation;
});
// 初始化SDK可以设置状态回调来监听
MoGoAiCloudClient.getInstance().init(this, clientConfig).addTokenCallbacks(
new IMoGoTokenCallback() {
@Override
public void onTokenGot(String token, String sn) {
Logger.d("TEST-SOCKET", "onTokenGot ");
// 异步初始化NetConfig
asyncInit();
// HttpDns ttl回调 --- socketTTL
registerSocketHttpDnsTTL(HostConst.SOCKET_CENTER_DOMAIN);
// 开启每5s/次定位上报
uploadLocPerFiveSecond();
}
@Override
public void onError(int code, String msg) {
Log.d(TAG, "初始化MogoAiCloudSdk failed ,reason : " + msg + " , 未能开启长链服务和初始化Modules服务");
}
}
);
}
/**
* 上传自车位置信息到云端
*/
private void uploadLocPerFiveSecond() {
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE) {
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
apis.getLocationInfoApi().start();
apis.getMapServiceApi().getSingletonLocationClient(getApplicationContext()).addLocationListener(location -> {
apis.getLocationInfoApi().provideLocation(location);
});
}
}
private void startSocketService() {
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
// 关闭长链服务
apis.getSocketManagerApi(getApplicationContext()).destroy();
apis.getSocketManagerApi(this).registerLifecycleListener(10020, new IMogoLifecycleListener() {
@Override
public void onConnectFailure() {
DebugConfig.setDownloadSnapshot(false);
}
@Override
public void onConnectSuccess() {
DebugConfig.setDownloadSnapshot(true);
}
@Override
public void onConnectLost() {
DebugConfig.setDownloadSnapshot(false);
}
});
// 开启Socket长链服务
apis.getSocketManagerApi(getApplicationContext()).init(getApplicationContext(), DebugConfig.getSocketAppId());
}
@Override
protected void socketTTL() {
// 鉴权成功后开启socket长链服务
startSocketService();
}
private void initModules() {
Logger.d(TAG, "initModules");
// 初始化 bugly 升级
MogoModulePaths.addBaseModule(new MogoModule(UpgradeReportConstants.PATH, UpgradeReportConstants.NAME));
// 初始化 bugly 日志采集
MogoModulePaths.addBaseModule(new MogoModule(CrashReportConstants.PATH, CrashReportConstants.NAME));
if (DebugConfig.isLauncher()) {
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_BACK, MogoServicePaths.PATH_BACK));
}
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_WIDGETS, MogoServicePaths.PATH_WIDGETS));
if (DebugConfig.isMapBased()) {
MogoModulePaths.addModule(new MogoModule(CallChatConstant.PROVIDER, CallChatConstant.MODULE_NAME));
}
MogoModulePaths.addBaseModule(new MogoModule(MapApiPath.PATH, "CustomMapApiBuilder"));
MogoModulePaths.addBaseModule(new MogoModule(ServiceConst.PATH_TTS_CONFIG, ServiceConst.PATH_TTS_CONFIG));
MogoModulePaths.addBaseModule(new MogoModule(ShareConstants.TAG, ShareConstants.MODEL_NAME));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_TANLU_API, "TanluApi"));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_TRAFFIC_UPLOAD, "TrafficUpload"));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_SHARE, "ShareControl"));
MogoModulePaths.addBaseModule(new MogoModule(ServiceConst.PATH_REFRESH_STRATEGY, ServiceConst.PATH_REFRESH_STRATEGY));
MogoModulePaths.addBaseModule(new MogoModule(V2XConst.PATH_V2X_UI, V2XConst.MODULE_NAME));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_STRATEGY_SHARE, "StrategyShare"));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_GAODE_AIMLESS_SHARE, "GaoDeAimlessShare"));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_MOGO_MONITOR, "MogoMonitor"));
// 域控制器模块(新)
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_AUTO_PILOT, "IMoGoAutoPilotProvider"));
// OBU 模块
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_V2X_OBU_MOGO, "IMoGoObuProvider"));
// 超视距,路测、行车记录仪监控
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_AI_MONITORING, "IMoGoMonitoringProvider"));
// V2X 模块
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_V2X_MODULE, "V2XProvider"));
// 自动驾驶系统检测模块
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_CHECK, "CheckProvider"));
// 推送模块
MogoModulePaths.addModule(new MogoModule(PushUIConstants.PATH, PushUIConstants.NAME));
// 碰撞报警模块
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_CRASH_WARNING, "IMogoCrashWarnProvider"));
// ADAS模块慢慢被 域控制器模块 替换掉)
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_ADAS, "AdasProvider"));
// 前方碰撞预警
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_V2X_FRONT_CRASH_WARNING, "IV2XManagerProvider"));
// 全局语音唤醒
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_GLOBAL_UNWAKE, "GlobalUnwake"));
// 云公告发布
MogoModulePaths.addModuleFunction(new MogoModule(MogoServicePaths.PATH_AI_NOTICE, "IMoGoNoticeProvider"));
if (!DebugConfig.isLauncher()) {
PersistentManager.getInstance().initManager(this);
Intent intent = new Intent(this, MogoMainService.class);
startService(intent);
}
Log.i(TAG, "App launch timer cost " + (System.currentTimeMillis() - start) + "ms");
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
BoostMultiDex.install(base);
}
}