From b42a0fb227c15a706fd1a7e4fc8a4e18a93ded94 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Sun, 9 Feb 2025 15:44:43 +1000 Subject: network: Fix 0.0 FPS bug on Android (Part 2) - Add network interface enumeration support for Android - Implement fallback loopback interface when no interfaces are detected - Add ability to force offline mode on critical network errors - Improve socket initialization with better error handling - Add socket state tracking (domain, type, protocol) - Make translation functions static and mark as maybe_unused - Add detailed logging for network initialization failures Part 2 of the Android FPS bug fix focuses on network resilience, particularly handling cases where network initialization fails. Instead of hanging the emulator, it now gracefully falls back to offline mode and provides better diagnostic information. --- .../java/org/citron/citron_emu/NativeLibrary.kt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/android') diff --git a/src/android/app/src/main/java/org/citron/citron_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/citron/citron_emu/NativeLibrary.kt index fc63dc276..c61230906 100644 --- a/src/android/app/src/main/java/org/citron/citron_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/citron/citron_emu/NativeLibrary.kt @@ -21,6 +21,7 @@ import org.citron.citron_emu.utils.Log import org.citron.citron_emu.model.InstallResult import org.citron.citron_emu.model.Patch import org.citron.citron_emu.model.GameVerificationResult +import java.net.NetworkInterface /** * Class which contains methods that interact @@ -459,4 +460,29 @@ object NativeLibrary { * Checks if all necessary keys are present for decryption */ external fun areKeysPresent(): Boolean + + fun getNetworkInterfaces(): Array { + val interfaceList = mutableListOf() + try { + NetworkInterface.getNetworkInterfaces()?.toList()?.forEach { iface -> + if (iface.isUp && !iface.isLoopback) { + iface.inetAddresses.toList() + .filterNot { it.isLoopbackAddress } + .forEach { addr -> + interfaceList.add("${iface.name};${addr.hostAddress}") + } + } + } + } catch (e: Exception) { + Log.error("[NativeLibrary] Failed to enumerate network interfaces: ${e.message}") + } + + // Always ensure we have at least a loopback interface + if (interfaceList.isEmpty()) { + Log.warning("[NativeLibrary] No interfaces found, adding loopback fallback") + interfaceList.add("lo;127.0.0.1") + } + + return interfaceList.toTypedArray() + } } -- cgit v1.2.3