{"id":50818469,"url":"https://github.com/adityachandak287/airmini-sync","last_synced_at":"2026-06-13T12:00:46.916Z","repository":{"id":364493485,"uuid":"1268067294","full_name":"adityachandak287/airmini-sync","owner":"adityachandak287","description":"Extract CPAP therapy data from the Resmed Airmini.","archived":false,"fork":false,"pushed_at":"2026-06-13T08:58:54.000Z","size":471,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-13T09:16:40.257Z","etag":null,"topics":["airmini","bluetooth","cpap","reverse-engineering"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adityachandak287.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-13T05:30:44.000Z","updated_at":"2026-06-13T08:58:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/adityachandak287/airmini-sync","commit_stats":null,"previous_names":["adityachandak287/airmini-sync"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/adityachandak287/airmini-sync","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityachandak287%2Fairmini-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityachandak287%2Fairmini-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityachandak287%2Fairmini-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityachandak287%2Fairmini-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adityachandak287","download_url":"https://codeload.github.com/adityachandak287/airmini-sync/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityachandak287%2Fairmini-sync/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34283391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["airmini","bluetooth","cpap","reverse-engineering"],"created_at":"2026-06-13T12:00:27.604Z","updated_at":"2026-06-13T12:00:46.907Z","avatar_url":"https://github.com/adityachandak287.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# On-Device AirMini Bluetooth Sync\n\nWe have transitioned the Bluetooth connection logic to run directly on your Android phone. This completely bypasses macOS RFCOMM virtual serial port issues.\n\n## Sync Architecture \u0026 Data Flow\n\n```mermaid\nsequenceDiagram\n    autonumber\n    participant Mac as Host Mac\n    participant Phone as Android Phone (shell/app_process)\n    participant JNI as figlib (Native C++)\n    participant AirMini as AirMini CPAP\n\n    Note over Mac, Phone: Setup \u0026 Compilation\n    Mac-\u003e\u003ePhone: Compile, package, \u0026 push sync_v3.jar\n    Mac-\u003e\u003ePhone: Push latest_sync.json (incremental timestamps)\n    Mac-\u003e\u003ePhone: Force-close official AirMini app\n\n    Note over Phone, AirMini: Bluetooth RFCOMM Connection\n    Phone-\u003e\u003ePhone: Query System Services \u0026 Bind IBluetooth\n    Phone-\u003e\u003eAirMini: Connect RFCOMM SPP Socket\n    AirMini--\u003e\u003ePhone: Established (32-byte socket handshake)\n\n    Note over Phone, AirMini: Authenticated Handshake (DH Exchange)\n    Phone-\u003e\u003eJNI: GetPairKey (PIN)\n    JNI-\u003e\u003ePhone: Formatted StartKeyExchange packet\n    Phone-\u003e\u003eAirMini: Send StartKeyExchange\n    AirMini--\u003e\u003ePhone: Return StartKeyExchange Response (Public Key + Salt)\n    Phone-\u003e\u003eJNI: nativeDecode(Response)\n    JNI-\u003e\u003eJNI: Compute DH Shared Secret \u0026 Session Key\n    JNI--\u003e\u003ePhone: ConfirmKeyExchange packet queued\n    Phone-\u003e\u003eAirMini: Send ConfirmKeyExchange\n    AirMini--\u003e\u003ePhone: Handshake Success Confirmation\n\n    Note over Phone, AirMini: Decrypted Telemetry Sync\n    loop For each Data Stream ID\n        Phone-\u003e\u003eJNI: GetLoggedData (since fromTime)\n        JNI--\u003e\u003ePhone: Encrypted Request Packet\n        Phone-\u003e\u003eAirMini: Send GetLoggedData\n        loop Until Stream marked Complete\n            AirMini--\u003e\u003ePhone: Stream Encrypted Data Chunks\n            Phone-\u003e\u003eJNI: nativeDecode(Chunk)\n            JNI--\u003e\u003ePhone: Callback with Decrypted JSON String\n        end\n    end\n\n    Note over Phone, Mac: Local Merging \u0026 Saving\n    Phone--\u003e\u003eMac: Pipe Decrypted JSON to stdout\n    Mac-\u003e\u003eMac: Strip native JNI logs (\"HandleResponse\")\n    Mac-\u003e\u003eMac: Merge \u0026 Deduplicate with sleep_data.json\n```\n\n---\n\n## How it works\n\n### 1. Direct-Binder Bluetooth Connection\n\nSince the runner executes via `app_process` under the `shell` user, standard Android APIs like `BluetoothAdapter.getDefaultAdapter()` return `null` (due to the lack of an initialized application context/looper). \n\nTo solve this, the Java agent:\n\n- Obtains the lower-level `\"bluetooth_manager\"` service binder from the system `ServiceManager`.\n- Construct a dynamic Java proxy to implement the hidden `IBluetoothManagerCallback` interface.\n- Calls `registerAdapter()` on the manager using the proxy to obtain the main `IBluetooth` adapter binder.\n- Builds an `AttributionSource` representing the `com.android.shell` package (UID 2000) using reflection.\n- Queries `getBondedDevices(attributionSource)` on the `IBluetooth` service to discover the bonded CPAP machine.\n- Retrieves the `IBluetoothSocketManager` service and calls `connectSocket(...)` directly, returning a raw socket `ParcelFileDescriptor` for the RFCOMM SPP channel.\n\n### 2. On-Device Encryption/Decryption\n\nInstead of routing packets back and forth between the Mac and the phone for encryption, all data encoding/decoding happens directly on the phone inside the JVM process using the JNI C++ library (`/data/local/tmp/libfiglib.so`). Decrypted telemetry streams are printed to stdout and saved directly to the Mac.\n\n---\n\n## Sync Instructions\n\n### Step 1: Put the AirMini in Pairing Mode\n\nBefore starting, ensure the AirMini's Bluetooth module is actively listening:\n\n1. Locate the **physical Bluetooth button** on your ResMed AirMini machine.\n2. Press and hold the button until the **blue LED starts flashing**.\n\n### Step 2: Run the Sync Script\n\nOnce the blue LED is flashing, run the sync helper on your Mac:\n\n```bash\n./run_sync.sh \u003c4-digit-pin-for-resmed-airmini\u003e\n```\n\nThis script will:\n\n1. Force-stop the official AirMini app (releasing its Bluetooth socket lock).\n2. Scan for existing synchronized timestamps in `sleep_data.json` to perform a **smart incremental sync** (only downloading new records).\n3. Connect, execute the pairing handshake, download, decrypt, and merge new data blocks.\n\n---\n\n## Telemetry Utilities\n\n### 1. View Therapy Statistics\n\nTo compile and view therapy statistics (mask sessions, total duration, leak percentiles, and respiratory event distributions), run the stats tool on your Mac:\n\n```bash\n./stats.py [optional_path_to_json]\n```\n\n*(By default, it will parse `sleep_data.json` in the current directory).*\n\n### 2. Prune Historical Data\n\nIf the machine contains stale factory-test records or you only want to focus on data after a certain date (e.g. 1st Jan 2026), run the pruning script:\n\n```bash\n./prune.py 2026-01-01 [optional_path_to_json]\n```\n\nThis filters out all database entries prior to your cutoff date and automatically writes a backup file to `sleep_data.json.bak` before saving the pruned output.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityachandak287%2Fairmini-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadityachandak287%2Fairmini-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityachandak287%2Fairmini-sync/lists"}