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.
This commit is contained in:
Zephyron 2025-02-09 15:44:43 +10:00
parent 5af4803e42
commit b42a0fb227
No known key found for this signature in database
5 changed files with 85 additions and 11 deletions

View file

@ -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<String> {
val interfaceList = mutableListOf<String>()
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()
}
}