From 23b2dbbeef1e18b3081efb4f2090949347e9f43c Mon Sep 17 00:00:00 2001 From: Jeremiah K <17190268+jeremiah-k@users.noreply.github.com> Date: Wed, 2 Jul 2025 13:59:31 -0500 Subject: [PATCH] Improved detection of emulator environments (#2323) --- .../mesh/repository/radio/RadioInterfaceService.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt index f40c733d1..c93978051 100644 --- a/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/repository/radio/RadioInterfaceService.kt @@ -26,6 +26,7 @@ import com.geeksville.mesh.BuildConfig import com.geeksville.mesh.CoroutineDispatchers import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.android.BinaryLogFile +import com.geeksville.mesh.android.BuildUtils import com.geeksville.mesh.android.GeeksvilleApplication import com.geeksville.mesh.android.Logging import com.geeksville.mesh.concurrent.handledLaunch @@ -143,6 +144,14 @@ class RadioInterfaceService @Inject constructor( return BuildConfig.DEBUG || (context as GeeksvilleApplication).isInTestLab } + /** + * Determines whether to default to mock interface for device address. + * This keeps the decision logic separate and easy to extend. + */ + private fun shouldDefaultToMockInterface(): Boolean { + return BuildUtils.isEmulator + } + /** Return the device we are configured to use, or null for none * device address strings are of the form: * @@ -156,7 +165,7 @@ class RadioInterfaceService @Inject constructor( var address = prefs.getString(DEVADDR_KEY, null) // If we are running on the emulator we default to the mock interface, so we can have some data to show to the user - if (address == null && isMockInterface()) { + if (address == null && shouldDefaultToMockInterface()) { address = mockInterfaceAddress }