@@ -7,11 +7,9 @@ object IterableMobileFrameworkDetector {
7
7
private const val TAG = " FrameworkDetector"
8
8
private lateinit var context: Context
9
9
10
- // Thread-safe cached framework type
11
10
@Volatile
12
11
private var cachedFrameworkType: IterableAPIMobileFrameworkType ? = null
13
12
14
- // Add this as a more flexible way to check for classes
15
13
private var hasClass: (String ) -> Boolean = { className ->
16
14
try {
17
15
Class .forName(className)
@@ -27,13 +25,11 @@ object IterableMobileFrameworkDetector {
27
25
} else {
28
26
this .context = context
29
27
}
30
- // Initialize cache on first initialization
31
28
if (cachedFrameworkType == null ) {
32
29
cachedFrameworkType = detectFrameworkInternal(context)
33
30
}
34
31
}
35
32
36
- // Static detection method with caching
37
33
@JvmStatic
38
34
fun detectFramework (context : Context ): IterableAPIMobileFrameworkType {
39
35
return cachedFrameworkType ? : synchronized(this ) {
@@ -43,20 +39,17 @@ object IterableMobileFrameworkDetector {
43
39
}
44
40
}
45
41
46
- // For backward compatibility - uses initialized context
47
42
fun frameworkType (): IterableAPIMobileFrameworkType {
48
43
return cachedFrameworkType ? : detectFramework(context)
49
44
}
50
45
51
- // Internal detection logic
52
46
private fun detectFrameworkInternal (context : Context ): IterableAPIMobileFrameworkType {
53
47
val hasFlutter = hasFrameworkClasses(FrameworkClasses .flutter)
54
48
val hasReactNative = hasFrameworkClasses(FrameworkClasses .reactNative)
55
49
56
50
return when {
57
51
hasFlutter && hasReactNative -> {
58
52
IterableLogger .d(TAG , " Both Flutter and React Native frameworks detected. This is unexpected." )
59
- // Check multiple indicators for Flutter
60
53
when {
61
54
context.packageName.endsWith(" .flutter" ) -> IterableAPIMobileFrameworkType .FLUTTER
62
55
hasManifestMetadata(context, ManifestMetadata .flutter) -> IterableAPIMobileFrameworkType .FLUTTER
@@ -67,7 +60,6 @@ object IterableMobileFrameworkDetector {
67
60
hasFlutter -> IterableAPIMobileFrameworkType .FLUTTER
68
61
hasReactNative -> IterableAPIMobileFrameworkType .REACT_NATIVE
69
62
else -> {
70
- // Check manifest metadata as fallback
71
63
when {
72
64
hasManifestMetadata(context, ManifestMetadata .flutter) -> IterableAPIMobileFrameworkType .FLUTTER
73
65
hasManifestMetadata(context, ManifestMetadata .reactNative) -> IterableAPIMobileFrameworkType .REACT_NATIVE
@@ -95,14 +87,12 @@ object IterableMobileFrameworkDetector {
95
87
}
96
88
97
89
private object ManifestMetadata {
98
- // Flutter metadata keys
99
90
val flutter = listOf (
100
91
" flutterEmbedding" ,
101
92
" io.flutter.embedding.android.NormalTheme" ,
102
93
" io.flutter.embedding.android.SplashScreenDrawable"
103
94
)
104
95
105
- // React Native metadata keys
106
96
val reactNative = listOf (
107
97
" react_native_version" ,
108
98
" expo.modules.updates.ENABLED" ,
@@ -116,7 +106,6 @@ object IterableMobileFrameworkDetector {
116
106
117
107
private fun hasManifestMetadata (context : Context , metadataKeys : List <String >): Boolean {
118
108
return try {
119
- // Using packageManager.getPackageInfo instead of getApplicationInfo
120
109
val packageInfo = context.packageManager.getPackageInfo(
121
110
context.packageName,
122
111
PackageManager .GET_META_DATA
0 commit comments