From c643c90c5957d79fefcdd4b59d2f838af00b9d17 Mon Sep 17 00:00:00 2001 From: Moe Hamade <69801237+moehamade@users.noreply.github.com> Date: Sun, 26 Jul 2026 15:17:07 +0300 Subject: [PATCH] fix: declare ACCESS_LOCAL_NETWORK for Wi-Fi Aware on Android 17 Android 17 (API 37) makes local network protection mandatory for apps targeting it. WifiAwareMeshService reaches peers over link-local IPv6 TCP sockets (connectAwareClientSocket), which may be gated by the new ACCESS_LOCAL_NETWORK runtime permission once targetSdk is raised to 37. The official local network permission documentation frames the feature as LAN access and does not explicitly state whether Wi-Fi Aware peer-to-peer networks are in scope, so this is defensive rather than confirmed-necessary. The sockets are bound to a dedicated Aware Network obtained via requestNetwork, not the user's subnet. Declaring it costs nothing: ACCESS_LOCAL_NETWORK shares the NEARBY_DEVICES group with NEARBY_WIFI_DEVICES, so users who have already granted the latter are not prompted again. The runtime request is gated on SDK_INT >= 37 so older devices are unaffected. Raised by automated review on #750. Verified: compileDebugKotlin, testDebugUnitTest (124 tests, 0 failures), bundleRelease, and ACCESS_LOCAL_NETWORK present in the merged manifest. Not verified on an Android 17 device. Co-Authored-By: Claude Opus 5 (1M context) --- app/src/main/AndroidManifest.xml | 8 +++++++ .../android/onboarding/PermissionManager.kt | 22 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f83ecefb3..341d39d76 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,6 +27,14 @@ + + diff --git a/app/src/main/java/com/bitchat/android/onboarding/PermissionManager.kt b/app/src/main/java/com/bitchat/android/onboarding/PermissionManager.kt index e7e022034..787026b70 100644 --- a/app/src/main/java/com/bitchat/android/onboarding/PermissionManager.kt +++ b/app/src/main/java/com/bitchat/android/onboarding/PermissionManager.kt @@ -39,6 +39,24 @@ class PermissionManager(private val context: Context) { } } + /** + * Runtime permissions needed for the Wi‑Fi Aware transport. + * + * Android 17 (API 37) makes local network protection mandatory for apps that target it. + * WifiAwareMeshService reaches peers over link-local IPv6 TCP sockets + * (connectAwareClientSocket), so ACCESS_LOCAL_NETWORK is requested defensively there. + * It shares the NEARBY_DEVICES group with NEARBY_WIFI_DEVICES, so granting it does not + * cost the user an extra prompt. + */ + private fun wifiAwarePermissions(): List { + val permissions = mutableListOf(Manifest.permission.NEARBY_WIFI_DEVICES) + // API 37 == Android 17; no named VERSION_CODES constant is available yet. + if (Build.VERSION.SDK_INT >= 37) { + permissions.add(Manifest.permission.ACCESS_LOCAL_NETWORK) + } + return permissions + } + /** * Check if this is the first time the user is launching the app */ @@ -87,7 +105,7 @@ class PermissionManager(private val context: Context) { // Wi‑Fi Aware: Android 13+ requires NEARBY_WIFI_DEVICES runtime permission if (shouldRequireWifiAwarePermission()) { - permissions.add(Manifest.permission.NEARBY_WIFI_DEVICES) + permissions.addAll(wifiAwarePermissions()) } // Notification permission intentionally excluded to keep it optional @@ -232,7 +250,7 @@ class PermissionManager(private val context: Context) { // Wi‑Fi Aware category (Android 13+) if (shouldRequireWifiAwarePermission()) { - val wifiAwarePermissions = listOf(Manifest.permission.NEARBY_WIFI_DEVICES) + val wifiAwarePermissions = wifiAwarePermissions() categories.add( PermissionCategory( type = PermissionType.WIFI_AWARE,