Skip to content

Commit

Permalink
- unified networking config in an environmentController new componen…
Browse files Browse the repository at this point in the history
…t that also can provide information of the device (#106)

- can detect if running on simulator
  • Loading branch information
rodvar authored Dec 11, 2024
1 parent 1eccc85 commit 75b177c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package network.bisq.mobile.domain.data

import network.bisq.mobile.client.shared.BuildConfig

// on android there is no 100% accurate way to determine, but this is the most comprehesive one
actual fun provideIsSimulator(): Boolean {
println("Fingerprint ${android.os.Build.FINGERPRINT}")
return (android.os.Build.MANUFACTURER == "Google" && android.os.Build.BRAND == "google" &&
((android.os.Build.FINGERPRINT.startsWith("google/sdk_gphone_")
&& android.os.Build.FINGERPRINT.endsWith(":user/release-keys")
&& android.os.Build.PRODUCT.startsWith("sdk_gphone_")
&& android.os.Build.MODEL.startsWith("sdk_gphone_"))
//alternative
|| (android.os.Build.FINGERPRINT.startsWith("google/sdk_gphone64_") && (android.os.Build.FINGERPRINT.endsWith(":userdebug/dev-keys")
|| (android.os.Build.FINGERPRINT.endsWith(":user/release-keys")) && android.os.Build.PRODUCT.startsWith("sdk_gphone64_")
&& android.os.Build.MODEL.startsWith("sdk_gphone64_")))
//Google Play Games emulator https://play.google.com/googleplaygames https://developer.android.com/games/playgames/emulator#other-downloads
|| (android.os.Build.MODEL == "HPE device" &&
android.os.Build.FINGERPRINT.startsWith("google/kiwi_") && android.os.Build.FINGERPRINT.endsWith(":user/release-keys")
&& android.os.Build.BOARD == "kiwi" && android.os.Build.PRODUCT.startsWith("kiwi_"))
)
//
|| android.os.Build.FINGERPRINT.startsWith("generic")
|| android.os.Build.FINGERPRINT.startsWith("unknown")
|| android.os.Build.MODEL.contains("google_sdk")
|| android.os.Build.MODEL.contains("Emulator")
|| android.os.Build.MODEL.contains("Android SDK built for x86")
//bluestacks
|| "QC_Reference_Phone" == android.os.Build.BOARD && !"Xiaomi".equals(android.os.Build.MANUFACTURER, ignoreCase = true)
//bluestacks
|| android.os.Build.MANUFACTURER.contains("Genymotion")
|| android.os.Build.HOST.startsWith("Build")
//MSI App Player
|| android.os.Build.BRAND.startsWith("generic") && android.os.Build.DEVICE.startsWith("generic")
|| android.os.Build.PRODUCT == "google_sdk"
// another Android SDK emulator check
|| System.getProperties()["ro.kernel.qemu"] == "1")
}

actual fun provideApiHost(): String {
return BuildConfig.WS_ANDROID_HOST.takeIf { it.isNotEmpty() } ?: "10.0.2.2"
}

actual fun provideApiPort(): Int {
return (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import network.bisq.mobile.client.websocket.messages.WebSocketRestApiRequest
import network.bisq.mobile.client.websocket.messages.WebSocketRestApiResponse
import network.bisq.mobile.client.user_profile.ClientUserProfileServiceFacade
import network.bisq.mobile.client.user_profile.UserProfileApiGateway
import network.bisq.mobile.domain.data.EnvironmentController
import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBootstrapFacade
import network.bisq.mobile.domain.service.market_price.MarketPriceServiceFacade
import network.bisq.mobile.domain.service.offerbook.OfferbookServiceFacade
Expand Down Expand Up @@ -68,11 +69,12 @@ val clientModule = module {
}

single<ApplicationBootstrapFacade> { ClientApplicationBootstrapFacade() }

single(named("ApiHost")) { provideApiHost() }
single(named("ApiPort")) { (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt() }
single(named("WebsocketApiHost")) { provideWebsocketHost() }
single(named("WebsocketApiPort")) { (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt() }

single { EnvironmentController() }
single(named("ApiHost")) { get<EnvironmentController>().getApiHost() }
single(named("ApiPort")) { get<EnvironmentController>().getApiPort() }
single(named("WebsocketApiHost")) { get<EnvironmentController>().getWebSocketHost() }
single(named("WebsocketApiPort")) { get<EnvironmentController>().getWebSocketPort() }

single {
WebSocketClient(
Expand All @@ -84,6 +86,7 @@ val clientModule = module {
}
// single { WebSocketHttpClient(get()) }
single {
println("Running on simulator: ${get<EnvironmentController>().isSimulator()}")
WebSocketApiClient(
get(),
get(),
Expand All @@ -101,12 +104,4 @@ val clientModule = module {

single { OfferbookApiGateway(get(), get()) }
single<OfferbookServiceFacade> { ClientOfferbookServiceFacade(get(), get(), get(), get()) }
}

fun provideApiHost(): String {
return BuildConfig.WS_ANDROID_HOST.takeIf { it.isNotEmpty() } ?: "10.0.2.2"
}

fun provideWebsocketHost(): String {
return BuildConfig.WS_ANDROID_HOST.takeIf { it.isNotEmpty() } ?: "10.0.2.2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package network.bisq.mobile.domain.data

/**
* Provides environment config.
*/
class EnvironmentController {
fun getApiHost(): String = provideApiHost()

fun getApiPort(): Int = provideApiPort()

fun getWebSocketHost(): String = provideApiHost()

fun getWebSocketPort(): Int = provideApiPort()

fun isSimulator(): Boolean = provideIsSimulator()
}

expect fun provideIsSimulator(): Boolean

expect fun provideApiHost(): String

expect fun provideApiPort(): Int
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package network.bisq.mobile.domain.data

import network.bisq.mobile.client.shared.BuildConfig
import platform.Foundation.NSProcessInfo

actual fun provideIsSimulator(): Boolean {
val deviceModel = NSProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] as? String
return deviceModel != null
}

actual fun provideApiHost(): String {
return BuildConfig.WS_IOS_HOST.takeIf { it.isNotEmpty() } ?: "localhost"
}

actual fun provideApiPort(): Int {
return (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module

val iosClientModule = module {
single(named("ApiHost")) { provideApiHost() }
single(named("WebsocketApiHost")) { provideWebsocketHost() }

single<NotificationServiceController> {
NotificationServiceController().apply {
this.registerBackgroundTask()
}
}
}

fun provideApiHost(): String {
return BuildConfig.WS_IOS_HOST.takeIf { it.isNotEmpty() } ?: "localhost"
}
fun provideWebsocketHost(): String {
return BuildConfig.WS_IOS_HOST.takeIf { it.isNotEmpty() } ?: "localhost"
}

0 comments on commit 75b177c

Please sign in to comment.