package com.mogo.launcher; import android.content.Context; import android.content.Intent; import android.os.Process; import android.text.TextUtils; 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.MoGoAiCloudClient; import com.mogo.cloud.passport.MoGoAiCloudClientConfig; import com.mogo.commons.AbsMogoApplication; 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.realtime.api.MoGoAiCloudRealTime; import com.mogo.service.map.IMogoSmallMapProvider; 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.service.passport.IMogoTicketCallback; import com.mogo.test.crashreport.ITestCrashReportProvider; import com.mogo.utils.ProcessUtils; import com.mogo.utils.UiThreadHandler; 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.zhidao.boot.persistent.lib.PersistentManager; import com.zhidao.mogo.module.left.panel.LeftPanelConst; /** * @author congtaowang * @since 2019-12-18 *

* Launcher application */ public class MogoApplication extends AbsMogoApplication { private static final String TAG = "MogoApplication"; @Override public void onCreate() { initDebugConfig(); super.onCreate(); if ( !shouldInit() ) { return; } // Crash 日志收集 final long start = System.currentTimeMillis(); CrashSystem crashSystem = CrashSystem.getInstance( this ); crashSystem.init(); //设置debug模式,日志不上传 crashSystem.setDebug( BuildConfig.DEBUG ); Logger.init( BuildConfig.DEBUG ? LogLevel.DEBUG : LogLevel.OFF ); 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" ) ); 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 ); } LeakCanary.install( this ); // debug 下初始化 bugly 上报 if ( DebugConfig.isDebug() ) { ARouter.getInstance().navigation( ITestCrashReportProvider.class ); } Log.i( "timer", "cost " + ( System.currentTimeMillis() - start ) + "ms" ); } @Override protected boolean shouldInit() { Logger.w( TAG, "evaluate shouldInit() with: %s", ProcessUtils.getProcessName( Process.myPid() ) ); return ProcessUtils.isMainProcess( this ); } 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(); final IMogoServiceApis apis = MogoApisHandler.getInstance().getApis(); prepareBaseService( apis, 0L ); } @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( IMogoServiceApis apis, long delay ) { UiThreadHandler.postDelayed( () -> { // 第三方平台的sn是服务端生成的,所以必须在返回后才能开启 if ( TextUtils.isEmpty( Utils.getSn() ) ) { preparePassportEnvironment( apis, () -> { prepareSocketAndLocationServices( apis ); } ); } else { preparePassportEnvironment( apis, null ); prepareSocketAndLocationServices( apis ); } }, delay ); } private void preparePassportEnvironment( IMogoServiceApis apis, Runnable after ) { // 配置云服务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(false); // 设置是否输出日志 clientConfig.setShowDebugLog(DebugConfig.isDebug()); // 设置从蘑菇AI开放平台获取的APPKey clientConfig.setThirdPartyAppKey("wbvpzgar"); // 设置应用服务AppId 长链、鉴权 clientConfig.setServiceAppId("com.mogo.launcher"); // 设置AI云平台分配给三方应用的签名密钥,需要从AI云平台申请 // 设置车机设备的唯一标识(这些表识必须是通过后台录入的设备) clientConfig.setThirdPartyDeviceId(Utils.getSn()); // 设置循环检测间隔时间 clientConfig.setLoopCheckDelay(15 * 1000); // 设置是否使用MoGoAiCloud SDK内部定位进行实时数据上报 clientConfig.setIsUseExternalLocation(true); // 设置DNS经纬度位置 clientConfig.setIHttpDnsCurrentLocation(new IHttpDnsCurrentLocation() { @Override public HttpDnsSimpleLocation getCurrentLocation() { MogoLocation mogoLocation = MogoApisHandler.getInstance() .getApis().getMapServiceApi() .getSingletonLocationClient(getApp()) .getLastKnowLocation(); Logger.i(TAG, "刷新DNS" + mogoLocation); if (mogoLocation != null) { return new HttpDnsSimpleLocation( mogoLocation.getCityCode(), mogoLocation.getLatitude(), mogoLocation.getLongitude()); } return new HttpDnsSimpleLocation("010", 0, 0); } }); // 初始化SDK,可以设置状态回调来监听 MoGoAiCloudClient.getInstance().init(this, clientConfig); } private void prepareSocketAndLocationServices( IMogoServiceApis apis ) { 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 ); } ); } } @Override protected void attachBaseContext( Context base ) { super.attachBaseContext( base ); BoostMultiDex.install( base ); } }