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) <noreply@anthropic.com>
This commit is contained in:
Moe HamadeandClaude Opus 5 committed 2026-07-26 15:17:07 +03:00
1 parent 8689ba44b3
commit c643c90c59
2 files changed
+28 -2

No files matched your search

+8
View File
@@ -27,6 +27,14 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Android 13+ runtime permission for Wi‑Fi operations (including Aware) -->
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
<!--
Android 17 (API 37) makes local network protection mandatory for apps targeting it.
The Wi‑Fi Aware transport reaches peers over link-local IPv6 TCP sockets
(WifiAwareMeshService.connectAwareClientSocket), so declare this defensively.
It belongs to the NEARBY_DEVICES group, so it does not add a prompt for users
who have already granted NEARBY_WIFI_DEVICES.
-->
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
<!-- Signature permission for internal UI shutdown broadcasts -->
<uses-permission android:name="com.bitchat.android.permission.FORCE_FINISH" />
<!-- Foreground service and boot permissions for long-running background mesh -->
@@ -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<String> {
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,