Files
MoGoEagleEye/app/src/main/java/com/mogo/launcher/MogoApplication.java
2020-09-15 20:11:45 +08:00

202 lines
8.3 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.Context;
import android.content.Intent;
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.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.Utils;
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant;
import com.mogo.module.back.BackToLauncherConst;
import com.mogo.module.carchatting.card.CallChatConstant;
import com.mogo.module.common.MogoModule;
import com.mogo.module.common.MogoModulePaths;
import com.mogo.module.main.service.MogoMainService;
import com.mogo.module.media.MediaConstants;
import com.mogo.module.push.base.PushUIConstants;
import com.mogo.module.service.ServiceConst;
import com.mogo.module.tanlu.constant.TanluConstants;
import com.mogo.module.v2x.V2XConst;
import com.mogo.module.widgets.MogoWidgetsProvider;
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.UiThreadHandler;
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;
import com.zhidao.mogo.tanlu.api.TanluApiConst;
import static com.mogo.module.guide.GuideConstant.PATH_GUIDE_FRAGMENT;
import static com.mogo.module.guide.GuideConstant.PATH_GUIDE_MODULE_NAME;
/**
* @author congtaowang
* @since 2019-12-18
* <p>
* 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.isLoadGuideModule() ) {
MogoModulePaths.addModule( new MogoModule( PATH_GUIDE_FRAGMENT, PATH_GUIDE_MODULE_NAME ) );
}else{
SharedPrefsMgr.getInstance(this).putBoolean(DebugConfig.getSpGuide(),true);
}
MogoModulePaths.addModule( new MogoModule( MogoServicePaths.PATH_AGREEMENT, AuthorizeConstant.PATH_AGREEMENT_MODULE_NAME ) );
if ( DebugConfig.isLauncher() ) {
MogoModulePaths.addModule( new MogoModule( BackToLauncherConst.MODULE_PATH, BackToLauncherConst.MODULE_NAME ) );
MogoModulePaths.addModule( new MogoModule( MediaConstants.TAG, MediaConstants.MODULE_TYPE ) );
} else {
MogoModulePaths.addBaseModule( new MogoModule( MogoWidgetsProvider.PATH, MogoWidgetsProvider.NAME ) );
}
if ( DebugConfig.getCarMachineType() != DebugConfig.CAR_MACHINE_TYPE_BYD ) {
MogoModulePaths.addModule( new MogoModule( CallChatConstant.PROVIDER, CallChatConstant.MODULE_NAME ) );
}
MogoModulePaths.addModule( new MogoModule( TanluApiConst.MODULE_PATH, TanluApiConst.MODULE_NAME ) );
MogoModulePaths.addBaseModule( new MogoModule( TanluConstants.TAG, TanluConstants.MODEL_NAME ) );
MogoModulePaths.addModule( new MogoModule( MogoServicePaths.PATH_SHARE, "ShareControl" ) );
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_MOGO_MONITOR, "MogoMonitor" ) );
MogoModulePaths.addModule( new MogoModule( V2XConst.PATH_EVENT_PANEL, V2XConst.MODULE_NAME_EVENT_PANEL ) );
MogoModulePaths.addModule( new MogoModule( PushUIConstants.PATH, PushUIConstants.NAME ) );
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() {
return !LeakCanary.isInAnalyzerProcess( this );
}
private void initDebugConfig() {
if ( !shouldInit() ) {
return;
}
DebugConfig.setNetMode( BuildConfig.NET_ENV );
DebugConfig.setDebug( BuildConfig.DEBUG );
DebugConfig.setAIType( BuildConfig.AIType );
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.setCarMachineType( BuildConfig.CAR_MACHINE_TYPE );
DebugConfig.setProductFlavor( BuildConfig.FLAVOR_product );
DebugConfig.setSocketAppId( BuildConfig.SOCKET_APP_ID );
DebugConfig.setRoadEventAnimated( BuildConfig.ROAD_EVENT_ANIMATED );
DebugConfig.setLoadGuideModule( BuildConfig.LOAD_GUIDE_MODULE );
DebugConfig.setSkinSupported( BuildConfig.IS_SKIN_SUPPORTED );
}
@Override
protected void asyncInitImpl() {
super.asyncInitImpl();
}
@Override
protected void init() {
super.init();
final IMogoServiceApis apis = ARouter.getInstance().navigation( IMogoServiceApis.class );
prepareBaseService( apis, 2_000L );
// installSkinManager( this, apis );
}
/**
* 基础服务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 ) {
apis.getPassportManagerApi().requestTicket( new IMogoTicketCallback() {
@Override
public void onTicketGot( String ticket ) {
Logger.d( TAG, "ticket = %s", ticket );
}
@Override
public void onError( int code, String msg ) {
Logger.w( TAG, "code = %s, msg = %s", code, msg );
}
@Override
public void onLoginSuccess( String token, String sn ) {
if ( after != null ) {
after.run();
}
}
} );
}
private void prepareSocketAndLocationServices( IMogoServiceApis apis ) {
apis.getSocketManagerApi( getApplicationContext() ).init( getApplicationContext(), DebugConfig.getSocketAppId() );
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 );
}
}