Skip to content

Commit

Permalink
feat: add emulator detection property to static context (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisames authored Aug 8, 2024
1 parent c267815 commit 6d1c76c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- feat: add emulator detection property to static context ([#154](https://github.com/PostHog/posthog-android/pull/154))
- fix: ensure activity name is used when activity label is not defined ([#153](https://github.com/PostHog/posthog-android/pull/153))
- recording: mask views with `contentDescription` setting and mask `WebView` if any masking is enabled ([#149](https://github.com/PostHog/posthog-android/pull/149))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ internal class PostHogAndroidContext(
staticContext["\$lib"] = config.sdkName
staticContext["\$lib_version"] = config.sdkVersion

staticContext["\$is_emulator"] = isEmulator

staticContext
}

Expand Down Expand Up @@ -170,4 +172,22 @@ internal class PostHogAndroidContext(

return dynamicContext
}

// Inspired from https://github.com/fluttercommunity/plus_plugins/blob/a71a27c5fbdbbfc56a30359a1aff0a3d3da8dc73/packages/device_info_plus/device_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/device_info/MethodCallHandlerImpl.kt#L105-L123
private val isEmulator: Boolean
get() = (
(Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) ||
Build.FINGERPRINT.startsWith("generic") ||
Build.FINGERPRINT.startsWith("unknown") ||
Build.HARDWARE.contains("goldfish") ||
Build.HARDWARE.contains("ranchu") ||
Build.MODEL.contains("google_sdk") ||
Build.MODEL.contains("Emulator") ||
Build.MODEL.contains("Android SDK built for x86") ||
Build.MANUFACTURER.contains("Genymotion") ||
Build.PRODUCT.contains("sdk") ||
Build.PRODUCT.contains("vbox86p") ||
Build.PRODUCT.contains("emulator") ||
Build.PRODUCT.contains("simulator")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ internal class PostHogAndroidContextTest {

assertEquals(config.sdkName, staticContext["\$lib"])
assertEquals(config.sdkVersion, staticContext["\$lib_version"])

assertNotNull(staticContext["\$is_emulator"])
}

@Test
Expand Down

0 comments on commit 6d1c76c

Please sign in to comment.