How liangzhengang/okble works
Main Components
• Demo Application (app Module): This is the user-facing Android application that demonstrates usage. It contains UI activities and calls into the library to perform BLE scanning, connecting, reading, writing, and iBeacon simulations.
• BLE Library (okble-lib Module): This module encapsulates all the core BLE operations. It is structured in packages for beacon management, device operations (scan, connect, read/write, notify), permission handling, server side (advertising and simulating peripheral behavior) and client side (central scanning/communication).
• Android BLE Framework: This represents the native Android Bluetooth APIs (both BLE Central and Peripheral APIs) that are abstracted by the library.
• External Dependencies & Tools: Include Gradle build system, dynamic permissions (for Android API 23+), and possibly external utilities (like for logging or UUID utilities).
Relationships and Interactions
• The Demo App (app module) interacts with the okble-lib library through public APIs. For example, the app initiates a scan (via OKBLEScanManager), connects to devices (via OKBLEDevice and its implementations), and triggers various BLE operations.
• The okble-lib module exposes various classes (such as OKBLEDeviceImp, OKBLEBeaconScanManager, OKBLEAdvertiseManager, OKBLEServerDeviceImp, and managers for beacon and peripheral simulation) which internally coordinate with the core Android BLE APIs.
• Callbacks and listener interfaces appear throughout the code (for scan results, operation success/failure, notifications) to handle asynchronous communication. These should be visually represented to show that the app registers listeners and the library, after executing BLE operations, sends responses/events asynchronously.
Architectural Patterns and Design Principles
• Separation of concerns is evident by splitting the demo app and the BLE library.
• Use of callback interfaces for asynchronous event handling (e.g., DeviceScanCallBack, BLEOperation listeners, Server operation listeners) – show these as interfaces that decouple event production and consumption.
• Auto-reconnect and operation queuing: Indicate that the BLE device component uses an operation queue to manage BLE read/write/notification operations. This “queue management” can be shown as an internal component within the BLE device layer.
Technologies and Frameworks
• Android SDK (BLE APIs available from API level 18+).
• Gradle for building the app and library modules.
• Java as the programming language (based on package structure and file types).
• Standard Android components (Activities, Services if any, Broadcast Receivers for dynamic permissions).