From 8412c20985f75835ad5d77d8adf592942d52c46e Mon Sep 17 00:00:00 2001 From: Suprhimp Date: Fri, 3 Apr 2026 16:59:50 +0900 Subject: [PATCH] Fix hotspot button not reflecting active hotspot state - refreshHotspotStatus() now checks NetworkInterface directly instead of requiring Shizuku service connection - Set isHotspotActive=true when auto-hotspot enables or detects existing hotspot during mirroring start Co-Authored-By: Claude Opus 4.6 --- .../main/java/com/castla/mirror/MainActivity.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/castla/mirror/MainActivity.kt b/app/src/main/java/com/castla/mirror/MainActivity.kt index 98a2488..b97c8c5 100644 --- a/app/src/main/java/com/castla/mirror/MainActivity.kt +++ b/app/src/main/java/com/castla/mirror/MainActivity.kt @@ -531,11 +531,19 @@ class MainActivity : AppCompatActivity() { } private fun refreshHotspotStatus() { - if (!shizukuSetup.serviceConnected.value) { + // Check hotspot status without requiring Shizuku by inspecting network interfaces directly + try { + val hotspotNames = listOf("swlan0", "wlan1", "ap0", "softap0") + val interfaces = java.net.NetworkInterface.getNetworkInterfaces()?.toList() ?: emptyList() + val active = interfaces.any { iface -> + iface.isUp && hotspotNames.any { name -> iface.name.contains(name) } + } + isHotspotActive = active + Log.d(TAG, "refreshHotspotStatus: active=$active (interfaces=${interfaces.map { it.name }})") + } catch (e: Exception) { + Log.w(TAG, "refreshHotspotStatus failed", e) isHotspotActive = false - return } - isHotspotActive = findHotspotInterface() != null } private fun toggleHotspot() { @@ -920,6 +928,7 @@ class MainActivity : AppCompatActivity() { val alreadyActive = findHotspotInterface() != null if (alreadyActive) { Log.i(TAG, "Hotspot already active — skipping enableHotspot, starting service directly") + isHotspotActive = true launchMirrorService(resultCode, data) } else { Toast.makeText(this, getString(R.string.toast_hotspot_enabling), Toast.LENGTH_SHORT).show() @@ -929,6 +938,7 @@ class MainActivity : AppCompatActivity() { runOnUiThread { if (success) { Toast.makeText(this@MainActivity, getString(R.string.toast_hotspot_enabled), Toast.LENGTH_SHORT).show() + isHotspotActive = true } else { Toast.makeText(this@MainActivity, getString(R.string.toast_hotspot_failed), Toast.LENGTH_SHORT).show() }