From 2f6f5c3ebed162a7cf3fc4267ee575affde0541b Mon Sep 17 00:00:00 2001 From: Florent CHAMPIGNY Date: Fri, 5 Sep 2025 15:27:50 +0200 Subject: [PATCH] fix: network config at startup (#205) Co-authored-by: Florent Champigny --- .../main/java/io/github/openflocon/flocon/Flocon.kt | 13 ++++++++++--- .../openflocon/flocon/client/FloconClientImpl.kt | 10 +++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/Flocon.kt b/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/Flocon.kt index 7170d821..13c62a0c 100644 --- a/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/Flocon.kt +++ b/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/Flocon.kt @@ -14,6 +14,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext object Flocon : FloconApp() { @@ -55,9 +56,15 @@ object Flocon : FloconApp() { // if success, just send a bonjour client.send("bonjour", method = "bonjour", body = "bonjour") } catch (t: Throwable) { - //t.printStackTrace() - delay(3_000) - start(client) + if(t.message?.contains("CLEARTEXT communication to localhost not permitted by network security policy") == true) { + withContext(Dispatchers.Main) { + client.displayClearTextError() + } + } else { + //t.printStackTrace() + delay(3_000) + start(client) + } } } diff --git a/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/client/FloconClientImpl.kt b/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/client/FloconClientImpl.kt index b3cd3d6d..9aaf1482 100644 --- a/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/client/FloconClientImpl.kt +++ b/FloconAndroid/flocon/src/main/java/io/github/openflocon/flocon/client/FloconClientImpl.kt @@ -3,6 +3,8 @@ package io.github.openflocon.flocon.client import android.content.Context import android.os.Build import android.provider.Settings +import android.util.Log +import android.widget.Toast import io.github.openflocon.flocon.FloconApp import io.github.openflocon.flocon.Protocol import io.github.openflocon.flocon.core.FloconPlugin @@ -28,7 +30,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch internal class FloconClientImpl( - appContext: Context, + private val appContext: Context, ) : FloconApp.Client { private val FLOCON_PORT = 9023 @@ -185,4 +187,10 @@ internal class FloconClientImpl( ) } } + + fun displayClearTextError() { + + Toast.makeText(appContext, "Cannot start Flocon : ClearText Issue, see Logcat", Toast.LENGTH_LONG).show() + Log.e("Flocon", "Flocon uses ClearText communication to the server, it seems you already have a network-security-config setup on your project, please ensure you allowed cleartext communication on your debug app https://github.com/openflocon/Flocon?tab=readme-ov-file#-why-flocon-cant-see-your-device-calls-and-how-to-fix-it-") + } } \ No newline at end of file