Skip to content

Commit 8d03cf7

Browse files
committed
[MOB-10592] Refactor IterableMobileFrameworkDetector: Remove redundant comments and streamline code for clarity.
1 parent 98f923b commit 8d03cf7

File tree

1 file changed

+0
-11
lines changed

1 file changed

+0
-11
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableMobileFrameworkDetector.kt

-11
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ object IterableMobileFrameworkDetector {
77
private const val TAG = "FrameworkDetector"
88
private lateinit var context: Context
99

10-
// Thread-safe cached framework type
1110
@Volatile
1211
private var cachedFrameworkType: IterableAPIMobileFrameworkType? = null
1312

14-
// Add this as a more flexible way to check for classes
1513
private var hasClass: (String) -> Boolean = { className ->
1614
try {
1715
Class.forName(className)
@@ -27,13 +25,11 @@ object IterableMobileFrameworkDetector {
2725
} else {
2826
this.context = context
2927
}
30-
// Initialize cache on first initialization
3128
if (cachedFrameworkType == null) {
3229
cachedFrameworkType = detectFrameworkInternal(context)
3330
}
3431
}
3532

36-
// Static detection method with caching
3733
@JvmStatic
3834
fun detectFramework(context: Context): IterableAPIMobileFrameworkType {
3935
return cachedFrameworkType ?: synchronized(this) {
@@ -43,20 +39,17 @@ object IterableMobileFrameworkDetector {
4339
}
4440
}
4541

46-
// For backward compatibility - uses initialized context
4742
fun frameworkType(): IterableAPIMobileFrameworkType {
4843
return cachedFrameworkType ?: detectFramework(context)
4944
}
5045

51-
// Internal detection logic
5246
private fun detectFrameworkInternal(context: Context): IterableAPIMobileFrameworkType {
5347
val hasFlutter = hasFrameworkClasses(FrameworkClasses.flutter)
5448
val hasReactNative = hasFrameworkClasses(FrameworkClasses.reactNative)
5549

5650
return when {
5751
hasFlutter && hasReactNative -> {
5852
IterableLogger.d(TAG, "Both Flutter and React Native frameworks detected. This is unexpected.")
59-
// Check multiple indicators for Flutter
6053
when {
6154
context.packageName.endsWith(".flutter") -> IterableAPIMobileFrameworkType.FLUTTER
6255
hasManifestMetadata(context, ManifestMetadata.flutter) -> IterableAPIMobileFrameworkType.FLUTTER
@@ -67,7 +60,6 @@ object IterableMobileFrameworkDetector {
6760
hasFlutter -> IterableAPIMobileFrameworkType.FLUTTER
6861
hasReactNative -> IterableAPIMobileFrameworkType.REACT_NATIVE
6962
else -> {
70-
// Check manifest metadata as fallback
7163
when {
7264
hasManifestMetadata(context, ManifestMetadata.flutter) -> IterableAPIMobileFrameworkType.FLUTTER
7365
hasManifestMetadata(context, ManifestMetadata.reactNative) -> IterableAPIMobileFrameworkType.REACT_NATIVE
@@ -95,14 +87,12 @@ object IterableMobileFrameworkDetector {
9587
}
9688

9789
private object ManifestMetadata {
98-
// Flutter metadata keys
9990
val flutter = listOf(
10091
"flutterEmbedding",
10192
"io.flutter.embedding.android.NormalTheme",
10293
"io.flutter.embedding.android.SplashScreenDrawable"
10394
)
10495

105-
// React Native metadata keys
10696
val reactNative = listOf(
10797
"react_native_version",
10898
"expo.modules.updates.ENABLED",
@@ -116,7 +106,6 @@ object IterableMobileFrameworkDetector {
116106

117107
private fun hasManifestMetadata(context: Context, metadataKeys: List<String>): Boolean {
118108
return try {
119-
// Using packageManager.getPackageInfo instead of getApplicationInfo
120109
val packageInfo = context.packageManager.getPackageInfo(
121110
context.packageName,
122111
PackageManager.GET_META_DATA

0 commit comments

Comments
 (0)