Files
MoGoEagleEye/app/src/main/java/com/mogo/launcher/MogoApplication.java
2021-07-12 22:59:21 +08:00

341 lines
16 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.mogo.launcher;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import com.alibaba.android.arouter.launcher.ARouter;
import com.auto.zhidao.logsdk.CrashSystem;
import com.bytedance.boost_multidex.BoostMultiDex;
import com.mogo.cloud.httpdns.MogoHttpDnsConfig;
import com.mogo.cloud.httpdns.bean.HttpDnsSimpleLocation;
import com.mogo.cloud.httpdns.listener.IHttpDnsCurrentLocation;
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.map.location.MogoLocation;
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
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.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.module.v2x.utils.ObuConfig;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.test.crashreport.ITestCrashReportProvider;
import com.mogo.test.crashreport.upgrade.UpgradeReportProvider;
import com.mogo.utils.ProcessUtils;
import com.mogo.utils.httpdns.HttpSimpleLocation;
import com.mogo.utils.logger.LogLevel;
import com.mogo.utils.logger.Logger;
import com.mogo.utils.storage.SharedPrefsMgr;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
import com.zhidao.boot.persistent.lib.PersistentManager;
import com.zhidao.mogo.module.left.panel.LeftPanelConst;
/**
* @author congtaowang
* @since 2019-12-18
* <p>
* Launcher application
*/
public class MogoApplication extends AbsMogoApplication {
private static final String TAG = "MogoApplication";
private long start;
private volatile static RefWatcher refWatcher;
@Override
public void onCreate() {
initDebugConfig();
super.onCreate();
if (!shouldInit()) {
return;
}
// Crash 日志收集
start = System.currentTimeMillis();
CrashSystem crashSystem = CrashSystem.getInstance(this);
crashSystem.init();
//设置debug模式日志不上传
// crashSystem.setDebug(BuildConfig.DEBUG);
Logger.init(BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF);
initMogoHttpDns();
initModules();
}
@Override
protected boolean shouldInit() {
Logger.w(TAG, "evaluate shouldInit() with: %s", ProcessUtils.getProcessName(Process.myPid()));
return ProcessUtils.isMainProcess(this);
}
/**
* BuildConfig中渠道配置赋值
*/
private void initDebugConfig() {
DebugConfig.setNetMode(BuildConfig.NET_ENV);
DebugConfig.setDebug(BuildConfig.DEBUG);
DebugConfig.setLaunchLocationService(BuildConfig.LAUNCH_LOCATION_SERVICE);
DebugConfig.setUseCustomNavi(BuildConfig.USE_CUSTOM_NAVI);
DebugConfig.setLauncher(BuildConfig.IS_LAUNCHER);
DebugConfig.setActiveAIAssistFlag(BuildConfig.AI_ASSIST_ACTIVE_STAUTS);
DebugConfig.setUseMockObuData(false);
ObuConfig.useObuLocation = false;
DebugConfig.setCarMachineType(BuildConfig.CAR_MACHINE_TYPE);
DebugConfig.setProductFlavor(BuildConfig.FLAVOR_product);
DebugConfig.setSocketAppId(BuildConfig.SOCKET_APP_ID);
DebugConfig.setRoadEventAnimated(BuildConfig.ROAD_EVENT_ANIMATED);
DebugConfig.setSkinSupported(BuildConfig.IS_SKIN_SUPPORTED);
DebugConfig.setSupportedSearchDestinationOnlineCarList(BuildConfig.IS_SUPPORTED_SEARCH_DESTINATION_ONLINE_CAR_LIST);
DebugConfig.setScheduleCalculateNotHomeCompanyDistanceForPush(BuildConfig.IS_SUPPORT_SCHEDULE_CALCULATE_NOT_HOME_COMPANY_DISTANCE_FOR_PUSH);
DebugConfig.setSupportLauncherCardRefreshStrategy(BuildConfig.IS_SUPPORT_LAUNCHER_CARD_REFRESH_STRATEGY);
DebugConfig.setMapBased(BuildConfig.IS_MAP_BASED);
DebugConfig.setNeedLoadGuideModule(BuildConfig.IS_NEED_LOAD_GUIDE_MODULE);
DebugConfig.setNeedHideAdasWhenShare(BuildConfig.IS_NEED_HIDE_ADAS_WHEN_SHARE);
DebugConfig.setNeedUploadCoordinatesInTime(BuildConfig.IS_NEED_UPLOAD_COORDINATES_IN_TIME);
DebugConfig.setUseAdasRtkLocationInfo(BuildConfig.IS_USE_ADAS_RTK_LOCATION_INFO);
DebugConfig.setObuType(SharedPrefsMgr.getInstance(this).getInt("OBU_TYPE", DebugConfig.OBU_TYPE_CIDI));
}
@Override
protected void asyncInitImpl() {
super.asyncInitImpl();
}
@Override
protected void init() {
super.init();
prepareBaseService();
}
@Override
protected HttpSimpleLocation getCurrentLocation() {
MogoLocation location = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(this).getLastKnowLocation();
if (location == null) {
return null;
} else {
return new HttpSimpleLocation(location.getCityCode(), location.getLatitude(), location.getLongitude());
}
}
/**
* 基础服务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(15 * 1000);
// 设置DNS经纬度位置
clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() {
@Override
public HttpDnsSimpleLocation getCurrentLocation() {
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) {
// 鉴权成功后开启socket长链服务
prepareSocketAndLocationServices();
}
@Override
public void onError(int code, String msg) {
Log.d(TAG,"初始化MogoAiCloudSdk failed ,reason : " + msg + " , 未能开启长链服务和初始化Modules服务");
}
}
);
}
private void prepareSocketAndLocationServices() {
//开启Socket长链服务
IMogoServiceApis apis = MogoApisHandler.getInstance().getApis();
apis.getSocketManagerApi(getApplicationContext()).init(getApplicationContext(), DebugConfig.getSocketAppId());
if (DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_SELF_INNOVATE) {
apis.getLocationInfoApi().start();
apis.getMapServiceApi().getSingletonLocationClient(getApplicationContext()).addLocationListener(location -> {
apis.getLocationInfoApi().provideLocation(location);
});
}
}
private void initModules(){
Logger.d(TAG,"initModules");
if (DebugConfig.isNeedLoadGuideModule()) {
MogoModulePaths.addModule(new MogoModule(MogoModulePaths.PATH_GUIDE, MogoModulePaths.PATH_GUIDE));
}
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_AGREEMENT, AuthorizeConstant.PATH_AGREEMENT_MODULE_NAME));
if (DebugConfig.isLauncher()) {
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_BACK, MogoServicePaths.PATH_BACK));
MogoModulePaths.addModule(new MogoModule(MogoModulePaths.PATH_MEDIA, MogoModulePaths.PATH_MEDIA));
}
MogoModulePaths.addModule(new MogoModule(ServiceConst.PATH_TTS_CONFIG, ServiceConst.PATH_TTS_CONFIG));
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(ShareConstants.TAG, ShareConstants.MODEL_NAME));
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_TANLU_API, "TanluApi"));
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_SHARE, "ShareControl"));
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_TRAFFIC_UPLOAD, "TrafficUpload"));
MogoModulePaths.addModule(new MogoModule(LeftPanelConst.PATH_NAME, LeftPanelConst.MODULE_NAME));
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.addModule(new MogoModule(PushUIConstants.PATH, PushUIConstants.NAME));
// 碰撞报警模块
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_CRASH_WARNING, "CrashWarning"));
// MogoModulePaths.addModule( new MogoModule( IMogoMachineVisionProvider.path, "IMogoMachineVisionProvider" ) );
// 小地图模块
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_SMALL_MAP, "IMogoSmallMapProvider"));
// ADAS模块
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_ADAS, "AdasProvider"));
//前方碰撞预警
MogoModulePaths.addModule(new MogoModule(MogoServicePaths.PATH_V2X_FRONT_CRASH_WARNING, "IV2XManagerProvider"));
MogoModulePaths.addBaseModule(new MogoModule(MogoServicePaths.PATH_GLOBAL_UNWAKE, "GlobalUnwake"));
if (!DebugConfig.isLauncher()) {
PersistentManager.getInstance().initManager(this);
Intent intent = new Intent(this, MogoMainService.class);
startService(intent);
}
if (refWatcher == null){
refWatcher = LeakCanary.install(this);
}
// 初始化 bugly 升级
ARouter.getInstance().navigation(UpgradeReportProvider.class);
// debug 下初始化 bugly 上报
// if (DebugConfig.isDebug()) {
// }
ARouter.getInstance().navigation(ITestCrashReportProvider.class);
Log.i("timer", "cost " + (System.currentTimeMillis() - start) + "ms");
try {
if (DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_LENOVO) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.zhidao.speech.voice.pad",
"com.zhidao.speech.MainActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
BoostMultiDex.install(base);
}
}