1 // Copyright 2015-present 650 Industries. All rights reserved. 2 package host.exp.exponent 3 4 import android.os.Debug 5 import androidx.multidex.MultiDexApplication 6 import com.facebook.react.bridge.ReactApplicationContext 7 import com.facebook.soloader.SoLoader 8 import host.exp.exponent.analytics.EXL 9 import host.exp.exponent.branch.BranchManager 10 import host.exp.exponent.di.NativeModuleDepsProvider 11 import host.exp.exponent.kernel.* 12 import host.exp.exponent.kernel.ExponentKernelModuleProvider.ExponentKernelModuleFactory 13 import host.exp.exponent.kernel.KernelProvider.KernelFactory 14 import host.exp.exponent.modules.ExponentKernelModule 15 import host.exp.exponent.storage.ExponentSharedPreferences 16 import host.exp.expoview.ExpoViewBuildConfig 17 import host.exp.expoview.Exponent 18 import me.leolin.shortcutbadger.ShortcutBadger 19 import javax.inject.Inject 20 21 abstract class ExpoApplication : MultiDexApplication() { 22 // Override me! 23 abstract val isDebug: Boolean 24 25 @Inject 26 lateinit var exponentSharedPreferences: ExponentSharedPreferences 27 onCreatenull28 override fun onCreate() { 29 super.onCreate() 30 31 ExpoViewBuildConfig.DEBUG = isDebug 32 ExpoViewBuildConfig.USE_EMBEDDED_KERNEL = shouldUseEmbeddedKernel() 33 34 if (ExpoViewBuildConfig.DEBUG && Constants.WAIT_FOR_DEBUGGER) { 35 Debug.waitForDebugger() 36 } 37 38 if (!Constants.isStandaloneApp()) { 39 KernelConstants.MAIN_ACTIVITY_CLASS = LauncherActivity::class.java 40 } 41 42 KernelProvider.setFactory(object : KernelFactory { 43 override fun create(): KernelInterface { 44 return Kernel() 45 } 46 }) 47 48 ExponentKernelModuleProvider.setFactory(object : ExponentKernelModuleFactory { 49 override fun create(reactContext: ReactApplicationContext): ExponentKernelModuleInterface { 50 return ExponentKernelModule( 51 reactContext 52 ) 53 } 54 }) 55 56 Exponent.initialize(this, this) 57 58 NativeModuleDepsProvider.instance.add(Kernel::class.java, KernelProvider.instance) 59 NativeModuleDepsProvider.instance.add(DevMenuManager::class.java, DevMenuManager()) 60 NativeModuleDepsProvider.instance.inject(ExpoApplication::class.java, this) 61 62 BranchManager.initialize(this) 63 64 try { 65 // Remove the badge count on weird launchers 66 // TODO: doesn't work on the Xiaomi phone. bug with the library 67 ShortcutBadger.removeCount(this) 68 } catch (e: Throwable) { 69 EXL.e(TAG, e) 70 } 71 72 if (Constants.DEBUG_COLD_START_METHOD_TRACING) { 73 Debug.startMethodTracing("coldStart") 74 } 75 76 SoLoader.init(applicationContext, false) 77 78 // Add exception handler. This is used by the entire process, so only need to add it here. 79 Thread.setDefaultUncaughtExceptionHandler( 80 ExponentUncaughtExceptionHandler( 81 applicationContext 82 ) 83 ) 84 } 85 86 // we're leaving this stub in here so that if people don't modify their MainApplication to 87 // remove the override of shouldUseInternetKernel() their project will still build without errors shouldUseEmbeddedKernelnull88 fun shouldUseEmbeddedKernel(): Boolean { 89 return !isDebug 90 } 91 92 companion object { 93 private val TAG = ExpoApplication::class.java.simpleName 94 } 95 } 96