33package com.urbanairship.reactnative
44
55import android.content.Context
6- import android.content.pm.ApplicationInfo
7- import android.content.pm.PackageManager
86import com.urbanairship.UAirship
97import com.urbanairship.analytics.Extension
108import com.urbanairship.android.framework.proxy.BaseAutopilot
@@ -17,6 +15,8 @@ import com.urbanairship.embedded.AirshipEmbeddedInfo
1715import com.urbanairship.embedded.AirshipEmbeddedObserver
1816import com.urbanairship.json.JsonMap
1917import com.urbanairship.json.jsonMapOf
18+ import com.urbanairship.reactnative.ManifestUtils.extenderClassName
19+ import com.urbanairship.reactnative.ManifestUtils.isHeadlessJSTaskEnabledOnStart
2020import kotlinx.coroutines.CoroutineScope
2121import kotlinx.coroutines.Dispatchers
2222import kotlinx.coroutines.SupervisorJob
@@ -33,7 +33,7 @@ class ReactAutopilot : BaseAutopilot() {
3333 override fun onReady (context : Context , airship : UAirship ) {
3434 ProxyLogger .info(" Airship React Native version: %s, SDK version: %s" , BuildConfig .AIRSHIP_MODULE_VERSION , UAirship .getVersion())
3535
36- val allowHeadlessJsTaskBeforeModule = isHeadlessJSTaskEnabledOnStart(context )
36+ val allowHeadlessJsTaskBeforeModule = context. isHeadlessJSTaskEnabledOnStart()
3737 ProxyLogger .debug(" ALLOW_HEADLESS_JS_TASK_BEFORE_MODULE: $allowHeadlessJsTaskBeforeModule " )
3838
3939 if (allowHeadlessJsTaskBeforeModule) {
@@ -69,48 +69,15 @@ class ReactAutopilot : BaseAutopilot() {
6969
7070 @Suppress(" deprecation" )
7171 private fun createExtender (context : Context ): AirshipExtender ? {
72- val ai : ApplicationInfo
72+ val className = context.extenderClassName() ? : return null
7373 try {
74- ai = context.packageManager.getApplicationInfo(context.packageName, PackageManager .GET_META_DATA )
75-
76- if (ai.metaData == null ) {
77- return null
78- }
79- } catch (e: PackageManager .NameNotFoundException ) {
80- return null
81- }
82-
83- val classname = ai.metaData.getString(EXTENDER_MANIFEST_KEY ) ? : return null
84-
85- try {
86- val extenderClass = Class .forName(classname)
74+ val extenderClass = Class .forName(className)
8775 return extenderClass.getDeclaredConstructor().newInstance() as AirshipExtender
8876 } catch (e: Exception ) {
89- ProxyLogger .error(e, " Unable to create extender: $classname " )
77+ ProxyLogger .error(e, " Unable to create extender: $className " )
9078 }
9179 return null
9280 }
93-
94- private fun isHeadlessJSTaskEnabledOnStart (context : Context ): Boolean {
95- val ai: ApplicationInfo
96- try {
97- ai = context.packageManager.getApplicationInfo(context.packageName, PackageManager .GET_META_DATA )
98-
99- if (ai.metaData == null ) {
100- return true
101- }
102- } catch (e: PackageManager .NameNotFoundException ) {
103- return true
104- }
105-
106- return ai.metaData.getBoolean(HEADLESS_JS_TASK_ON_START_MANIFEST_KEY , true )
107- }
108-
109-
110- companion object {
111- const val HEADLESS_JS_TASK_ON_START_MANIFEST_KEY = " com.urbanairship.reactnative.ALLOW_HEADLESS_JS_TASK_BEFORE_MODULE"
112- const val EXTENDER_MANIFEST_KEY = " com.urbanairship.reactnative.AIRSHIP_EXTENDER"
113- }
11481}
11582
11683internal class PendingEmbeddedUpdated (pending : List <AirshipEmbeddedInfo >) : Event {
0 commit comments