1 // Copyright 2015-present 650 Industries. All rights reserved.
2 package host.exp.exponent.kernel
3 
4 import android.app.Application
5 import android.content.Context
6 import android.content.pm.PackageManager
7 import de.greenrobot.event.EventBus
8 import host.exp.exponent.ExpoUpdatesAppLoader
9 import host.exp.exponent.analytics.EXL
10 import host.exp.exponent.di.NativeModuleDepsProvider
11 import host.exp.exponent.kernel.KernelConstants.ExperienceOptions
12 import host.exp.expoview.ExpoViewBuildConfig
13 import javax.inject.Inject
14 
15 class ExpoViewKernel private constructor() : KernelInterface() {
16   class ExpoViewErrorEvent internal constructor(val errorMessage: String)
17 
18   @Inject
19   lateinit var context: Context
20 
21   @Inject
22   lateinit var applicationContext: Application
23 
handleErrornull24   override fun handleError(errorMessage: String) {
25     if (ExpoViewBuildConfig.DEBUG) {
26       EventBus.getDefault().post(ExpoViewErrorEvent(errorMessage))
27     } else {
28       throw RuntimeException(errorMessage)
29     }
30   }
31 
handleErrornull32   override fun handleError(exception: Exception) {
33     if (ExpoViewBuildConfig.DEBUG) {
34       EventBus.getDefault().post(ExpoViewErrorEvent(exception.toString()))
35     } else {
36       throw RuntimeException(exception)
37     }
38   }
39 
openExperiencenull40   override fun openExperience(options: ExperienceOptions) {}
41 
getAppLoaderForManifestUrlnull42   override fun getAppLoaderForManifestUrl(manifestUrl: String?): ExpoUpdatesAppLoader? {
43     return null
44   }
45 
reloadVisibleExperiencenull46   override fun reloadVisibleExperience(manifestUrl: String, forceCache: Boolean): Boolean {
47     return false
48   }
49 
50   val versionName: String?
51 
52   companion object {
53     private val TAG = ExpoViewKernel::class.java.simpleName
54 
<lambda>null55     @JvmStatic val instance: ExpoViewKernel by lazy {
56       ExpoViewKernel()
57     }
58   }
59 
60   init {
61     NativeModuleDepsProvider.instance.inject(ExpoViewKernel::class.java, this)
62 
63     versionName = try {
64       applicationContext.packageManager.getPackageInfo(
65         context.packageName, 0
66       ).versionName
67     } catch (e: PackageManager.NameNotFoundException) {
68       EXL.e(TAG, e)
69       null
70     } catch (e: Throwable) {
71       EXL.e(TAG, e)
72       null
73     }
74   }
75 }
76