| 80 | import java.lang.ref.WeakReference |
| 81 | import java.util.concurrent.atomic.AtomicBoolean |
| 82 | |
| 83 | class ValdiRuntimeManager(context: Context, |
| 84 | customLogger: Logger? = null, |
| 85 | val tweaks: ValdiTweaks? = null, |
| 86 | val requestManager: HTTPRequestManager? = null, |
| 87 | executorFactory: ExecutorFactory? = null, |
| 88 | typefaceResLoader: TypefaceResLoader? = null, |
| 89 | hostUncaughtExceptionHandler: HostUncaughtExceptionHandler? = null, |
| 90 | tracer: Tracer? = null, |
| 91 | val customModuleProvider: IValdiCustomModuleProvider? = null |
| 92 | ) : LifecycleObserver, ComponentCallbacks, FontManager.Listener { |
| 93 | |
| 94 | val logger: Logger |
| 95 | |
| 96 | val nativeHandle: Long |
| 97 | get() = handle.nativeHandle |
| 98 | |
| 99 | private val nativeBridge = NativeBridge() |
| 100 | private val viewManager: ValdiViewManager |
| 101 | private val contextManager: ContextManager |
| 102 | |
| 103 | private val handle: NativeHandleWrapper |
| 104 | |
| 105 | private var observingProcessLifecycle = false |
| 106 | |
| 107 | private var mainRuntimeHolder: ValdiRuntime? = null |
| 108 | |
| 109 | private val mainRuntimeLazy = lazy { |
| 110 | synchronized(mainRuntimeListeners) { |
| 111 | mainRuntimeHolder = doCreateRuntime(customModuleProvider, true) |
| 112 | mainRuntimeHolder!!.also { notifyMainRuntimeListeners(it) } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | private var forceDarkMode = false |
| 117 | |
| 118 | private var isIntegrationTestEnvironment = false |
| 119 | |
| 120 | /** |
| 121 | * `baseContext` will be a ContextWrapper if context passed to the constructor is a ContextWrapper. |
| 122 | * `context` will always be the Application context. |
| 123 | * Ideally `baseContext` is the only Context reference. However, it's unclear if there are any |
| 124 | * call sites that require the Application context specifically, so we provide both for now. |
| 125 | */ |
| 126 | val baseContext: Context = context |
| 127 | val context: Context = context.applicationContext |
| 128 | |
| 129 | val mainRuntime: ValdiRuntime by mainRuntimeLazy |
| 130 | |
| 131 | val fontManager = FontManager(context, typefaceResLoader ?: DefaultTypefaceResLoader()) |
| 132 | |
| 133 | val snapDrawingRuntime: SnapDrawingRuntime? |
| 134 | get() = snapDrawingRuntimeField |
| 135 | |
| 136 | private val snapDrawingMaxRenderTargetSizeLazy = lazy { |
| 137 | if (tweaks?.enableHardwareLayerWorkaround == true) { |
| 138 | snapDrawingRuntime?.getMaxRenderTargetSize() ?: -1 |
| 139 | } else { |
no test coverage detected