Moe Hamade 41544a6840 fix: make Wi-Fi Direct hotspot sharing reliable
Starting the APK-sharing hotspot failed intermittently with
"Failed to create hotspot: BUSY", sometimes for minutes, then
succeeded for no apparent reason. Two distinct causes, both
confirmed against a Pixel 9a via dumpsys and HAL logs.

1. Wi-Fi Aware holds the radio. The mesh's NAN interface and
   Wi-Fi Direct's P2P interface cannot coexist on common chipsets:

     HalDevMgr: bestIfaceCreationProposal is null, requestIface=P2P,
                existingIface=[name=wlan0 type=STA, name=aware_nmi0 type=NAN]
     WifiP2pNative: Failed to create P2p iface

   The P2P state machine then stays in P2pDisabledState and answers
   every createGroup with BUSY, while still broadcasting
   WIFI_P2P_STATE_ENABLED. Whether sharing worked came down to
   whether Aware happened to be attached, which is what made it look
   random. WifiAwareController now releases Aware for the duration of
   the hotspot and blocks restarts until it finishes.

2. Orphaned groups. A P2P group outlives the process that created
   it, so a crash or swipe-away while hosting leaves one behind, and
   the framework answers BUSY for as long as it exists. Startup now
   removes a stale group first, but only one it can show is ours --
   Wi-Fi Direct is shared with Cast, Android Auto and Quick Share.
   Ownership is the group name we recorded creating, with the SSID
   prefix as a fallback for orphans from older builds.

Also fixed while tracing these:

- Channel leak: initialize() ran on every retry attempt and the
  channel was never closed, leaving a binder registration with
  WifiP2pService per attempt. Observed climbing to 7 stale clients.
  It is now initialised once and closed after removeGroup replies.
- BUSY is the framework's catch-all reply, so retrying was futile
  for permanent causes and too impatient for real contention.
  Retries now back off 1s/2s/4s/8s and only for genuinely transient
  failures; P2P being off fails immediately with a message that says
  so rather than 15 seconds ending in "busy".
- Turning Wi-Fi off mid-session left the UI showing an active
  hotspot forever; it now aborts cleanly.

Retry and startup decisions are extracted into HotspotStartupPolicy,
which has no Android dependencies and is covered by 13 unit tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 12:54:01 +03:00
2026-07-27 02:45:07 +02:00
2025-07-08 20:37:46 +02:00
2025-07-08 20:37:46 +02:00
2026-07-27 23:19:51 +02:00
2025-08-29 14:37:35 +02:00

icon_128x128@2x

bitchat for Android

A decentralized peer-to-peer messaging app with dual transport architecture: local Bluetooth mesh networks for offline communication and internet-based Nostr protocol for global reach. No accounts, no phone numbers, no central servers.

This is the Android implementation of bitchat, fully protocol-compatible with the iOS version for cross-platform mesh communication.

bitchat.free

GitHub Releases

Get it on Google Play

License

This project is released into the public domain. See the LICENSE file for details.

Features

  • Dual Transport Architecture: Bluetooth LE mesh for offline messaging, Nostr relays for internet-based messaging
  • Location-Based Channels: Geographic chat rooms using geohash coordinates over Nostr relays
  • Intelligent Message Routing: Automatically chooses the best transport, with queuing and retry when a peer is unreachable
  • End-to-End Encryption: Noise Protocol (XX pattern, X25519 + ChaCha20-Poly1305) for private messages over the mesh
  • Decentralized Mesh Network: Automatic peer discovery and multi-hop relay over Bluetooth LE (max 7 hops)
  • Wi-Fi Aware Transport: Higher-bandwidth local mesh on supported devices
  • Channel Chats: Topic-based group messaging with optional password protection (Argon2id + AES-256-GCM)
  • IRC-Style Commands: Familiar /join, /msg, /who style interface
  • Tor Support: Built-in Tor (Arti) for private internet connectivity
  • Emergency Wipe: Triple-tap to instantly clear all data
  • Cross-Platform: Binary protocol compatible with bitchat on iOS and macOS

Technical Architecture

Bluetooth Mesh Network (Offline)

  • Direct peer-to-peer within Bluetooth range, multi-hop relay through nearby devices
  • Noise Protocol sessions with forward secrecy; peer identities derived from static keys
  • Compact binary packet format with fragmentation, TTL routing, and deduplication
  • Adaptive duty cycling and connection limits for battery efficiency
  • Foreground service keeps the mesh alive within Android background execution limits

Nostr Protocol (Internet)

  • Global reach via public relays, geohash-based location channels
  • Private messages fall back to Nostr for mutual favorites when the mesh is unavailable
  • Ephemeral keys per geohash area

Android Stack

  • Kotlin, Jetpack Compose (Material 3), MVVM
  • Coroutines and Flow for all networking and state
  • Core components: MeshForegroundService (persistent connectivity), BluetoothMeshService / WifiAwareMeshService (transports), UnifiedMeshService (transport selection), NoiseSessionManager (encryption sessions), MessageRouter (mesh/Nostr routing with outbox retry)

Building

Requires Android Studio and the Android SDK (API 26+).

git clone https://github.com/permissionlesstech/bitchat-android.git
cd bitchat-android
./gradlew assembleDebug

Install on a connected device:

adb install -r app/build/outputs/apk/debug/app-debug.apk

The app requests Bluetooth, location (required for BLE scanning), and notification permissions at runtime.

Testing

# Unit tests
./gradlew test

# Lint
./gradlew lint

# Instrumented tests (requires a device or emulator)
./gradlew connectedAndroidTest

Note that BLE mesh behavior is difficult to emulate; protocol and session logic is covered by unit tests, while radio-level behavior needs real devices.

Description
bluetooth mesh chat, IRC vibes
Readme
Languages
Kotlin 86%
Java 10%
Python 2.5%
Shell 1.1%
Rust 0.3%
Other 0.1%