Improved detection of emulator environments (#2323)

This commit is contained in:
Jeremiah K
2025-07-02 13:59:31 -05:00
committed by GitHub
parent eda25a0ee4
commit 23b2dbbeef

View File

@@ -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
}