How weliem/blessed-android works
• The core library source under the “blessed” directory, which contains all the BLE logic (classes such as BluetoothCentralManager, BluetoothPeripheral, BluetoothPeripheralManager, BluetoothCentral, and BluetoothBytesParser) and associated callbacks.
• An example app (“app” directory) that demonstrates typical use cases (scanning, connecting, reading/writing characteristics, notifications, bonding, etc.) by utilizing the core library.
There are also additional supporting directories (like “docs” for documentation, Gradle configuration files, CI configurations in .github/workflows, etc.).
Main Components
a. Android BLE Subsystem – representing the native Android Bluetooth stack.
b. Core Blessed Library Components – individual classes/abstractions:
– BluetoothCentralManager (for scanning and managing connections)
– BluetoothPeripheral (as a wrapper for managing GATT operations)
– BluetoothPeripheralManager (to create and manage a peripheral)
– BluetoothCentral (for uses in peripheral creation via callbacks)
– BluetoothBytesParser (a utility for parsing/building BLE byte arrays)
c. Application Layer – the example app that uses the blessed library to demonstrate functionalities (UI activities, example tests, etc.).
d. External Dependencies and Configuration – Gradle, CI/CD (GitHub workflows), and accompanying documentation.
Relationships and Interactions
• The application layer calls the Blessed library’s API. For example, the MainActivity in the “app” package will instantiate a BluetoothCentralManager and register a callback to listen for scan results.
• The BluetoothCentralManager interacts with the underlying Android BLE system to perform scanning and connection efforts.
• Once devices are discovered, the BluetoothPeripheral objects (wrapped versions of Android BluetoothDevice/Gatt) are managed, and service discovery and characteristic read/write operations occur.
• Callbacks such as onConnectedPeripheral, onServicesDiscovered, onCharacteristicUpdate, etc., illustrate the asynchronous communication between the library and the application.
• The library itself abstracts many low-level details like queuing operations, managing threading, handling bonding, and negotiating MTU or Phy settings.
Architectural Patterns and Design Principles
– Abstraction Layer: The library abstracts Android BLE’s low-level APIs so that developers have a simpler interface (similar to iOS’s CoreBluetooth).
– Asynchronous Communication: The use of callbacks for asynchronous operations (e.g., scanning, connecting, bonding) is central to the design.
– Separation of Concerns: There is a clear separation between the core BLE functionality (in the “blessed” package) and the user/developer facing example application (in the “app” package).
– Modular Design: Distinct classes and callback interfaces are defined for each BLE-related operation (scanning, connection handling, characteristic read/write, notifications, and Bluetooth 5 features).
Relevant Technologies, Frameworks, and Libraries
• Android SDK – underlying BLE APIs.
• Gradle – for build and dependency management.
• GitHub Actions (gradle.yml) – for continuous integration.
• Timber – used for logging.
• Java (and optimizations/compatibility for Kotlin) – primary language of the library.