fix(wifiaware): validate ACCESS_FINE_LOCATION permission before starting services (#718)

This commit is contained in:
a1denvalu3
2026-06-19 02:45:24 -05:00
committed by GitHub
parent 9c182aac4c
commit fb8f3c0c79
2 changed files with 37 additions and 0 deletions
@@ -145,6 +145,19 @@ object WifiAwareController {
return
}
// Require ACCESS_FINE_LOCATION runtime permission
val locationPermissionGranted = androidx.core.content.ContextCompat.checkSelfPermission(
ctx,
android.Manifest.permission.ACCESS_FINE_LOCATION
) == android.content.pm.PackageManager.PERMISSION_GRANTED
if (!locationPermissionGranted) {
Log.w(TAG, "Missing ACCESS_FINE_LOCATION permission; not starting WiFi Aware")
addBlockedDebugMessage("missing-fine-location", "Grant Location permission to start Wi-Fi Aware")
synchronized(lifecycleLock) { starting = false }
return
}
// Android 13+: require NEARBY_WIFI_DEVICES runtime permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val granted = androidx.core.content.ContextCompat.checkSelfPermission(ctx, android.Manifest.permission.NEARBY_WIFI_DEVICES) == android.content.pm.PackageManager.PERMISSION_GRANTED
@@ -330,6 +330,30 @@ class WifiAwareMeshService(private val context: Context) : MeshService, Transpor
Log.i(TAG, "Wi-Fi Aware transport disabled by debug settings; not starting")
return
}
// Require ACCESS_FINE_LOCATION runtime permission
val fineLocationGranted = androidx.core.content.ContextCompat.checkSelfPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
) == android.content.pm.PackageManager.PERMISSION_GRANTED
if (!fineLocationGranted) {
Log.w(TAG, "Missing ACCESS_FINE_LOCATION permission; aborting startServices")
return
}
// Android 13+: require NEARBY_WIFI_DEVICES runtime permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val nearbyGranted = androidx.core.content.ContextCompat.checkSelfPermission(
context,
Manifest.permission.NEARBY_WIFI_DEVICES
) == android.content.pm.PackageManager.PERMISSION_GRANTED
if (!nearbyGranted) {
Log.w(TAG, "Missing NEARBY_WIFI_DEVICES permission; aborting startServices")
return
}
}
val supportStatus = com.bitchat.android.wifiaware.WifiAwareSupport.evaluate(context)
if (!supportStatus.supported) {
Log.i(TAG, "Wi-Fi Aware unsupported on this device; not starting (${supportStatus.reason})")