Commit graph

174 commits

Author SHA1 Message Date
eddy
a60f6cdc1c feat: add BleRelayManager GATT callback (connect, UUID verify, notifications) 2026-07-29 19:54:31 +02:00
eddy
92585455c8 feat: add BleRelayManager scan logic with permissions 2026-07-29 19:51:11 +02:00
eddy
82852e086e feat: add BleRelayManager key/HMAC helpers and loadState 2026-07-29 19:49:00 +02:00
eddy
f41f1c3380 feat: add BleRelayManager class skeleton 2026-07-29 19:47:20 +02:00
eddy
61c5c1de32 feat: add BleStatus enum and BleCallbacks interface 2026-07-29 19:45:11 +02:00
eddy
cd89604c9b docs: add BLE refactor implementation plan (8 tasks) 2026-07-29 19:44:17 +02:00
eddy
459dc5f201 docs: add BLE refactor design spec (BleRelayManager extraction) 2026-07-29 19:40:30 +02:00
eddy
d6e37322f3 fix: NimBLE 128-bit UUID scan response + Android key/UUID loading
- Firmware: add explicit setScanResponseData with setCompleteServices for
  128-bit service UUID so Android ScanFilter finds the device
- Android: hexStringToBytes accepts any even-length hex (fixes UUID=32chars
  failing the hardcoded 64-char check)
- Android: onActivityResult matches SettingsActivity.RESULT_SCAN instead of
  Activity.RESULT_OK
2026-07-29 19:30:46 +02:00
eddy
96d3620535 feat: migrate BLE to NimBLE — 45% flash, 33% RAM reduction
- Replaced ESP32 BLE Arduino with h2zero/NimBLE-Arduino@^2
- -DCONFIG_BT_NIMBLE_ENABLED to disable built-in Bluedroid
- NIMBLE_PROPERTY::* replaces BLECharacteristic::PROPERTY_* + setAccessPermissions
- BLE2902 descriptor removed (NimBLE auto-creates it)
- pService->start() removed (NimBLE starts services with server)
- setMinPreferred → setMinInterval/setMaxInterval
- onConnect/onDisconnect/onWrite get extra NimBLEConnInfo& param
- Re-advertise: BLEDevice → NimBLEDevice::startAdvertising()
- Firmware: 533KB flash (was 964KB), 29KB RAM (was 44KB)
2026-07-29 18:58:49 +02:00
eddy
42b8092807 fix: replace EncryptedSharedPreferences with plain MODE_PRIVATE for update survival 2026-07-29 18:51:35 +02:00
eddy
348c55d830 feat: add device UUID pairing — unique identity per ESP-phone pair
- Firmware: auto-generate 16-byte UUID on first boot (NVS), new READ characteristic
- BLE name: AtomS3R-Relay → SylDa_Server
- KEY? now returns DEVICE_ID + HMAC_KEY, SET_ID command for UUID provisioning
- App: UUID+HMAC loaded from prefs, scan by service UUID, verify UUID after connect
- UUID mismatch → disconnect + skip address + rescan
- Key conflict dialog: keep ESP keys, overwrite ESP (with checkbox confirm), or cancel
- NO_KEY with existing app keys: send existing pair instead of generating new
- Added design spec doc
2026-07-29 18:12:13 +02:00
eddy
73b3c0eaa0 docs: add device UUID pairing design spec 2026-07-29 17:56:48 +02:00
eddy
804a728550 docs: mark 5.3 empty catch blocks as resolved 2026-07-27 17:16:29 +02:00
eddy
f88b17cae5 Merge branch 'fix/magic-numbers': extract magic numbers to named constants (review 4.3) 2026-07-27 13:12:31 +02:00
eddy
f676eb259d Extract magic numbers to named constants (review 4.3)
- MainActivity: RECONNECT_DELAY_MS, POST_SETTINGS_RESCAN_MS, ON_RESUME_SCAN_DELAY_MS
- SettingsActivity: FLUSH_TIMEOUT_MS, READ_CHUNK_TIMEOUT_MS, CDC_CONTROL_TIMEOUT_MS
- UsbSerialTransport: CONTROL_LINE_TIMEOUT_MS
- UsbUtils: shared CDC request constants (REQUEST_TYPE, SET_LINE_CODING, SET_CONTROL_LINE_STATE, DTR, RTS)

Pure refactor — no behavior change. All literals replaced by named private const val in companion objects or shared via UsbUtils.
2026-07-27 12:39:41 +02:00
eddy
9c520f57c2 Add .worktrees/ to .gitignore 2026-07-27 12:32:40 +02:00
eddy
c977dc25a2 Voeg thema-selector toe (DayNight, Radiogroep, teal accent) 2026-07-27 00:22:43 +02:00
eddy
5a0dee77b3 Update README with scan retry feature 2026-07-26 23:37:20 +02:00
eddy
7c054a7021 Add scan retry button on timeout 2026-07-26 23:37:02 +02:00
eddy
954264fe37 Add proguard rules for esp32-flash-lib 2026-07-26 23:31:14 +02:00
eddy
05036a5060 Move user-facing strings to strings.xml 2026-07-26 23:21:25 +02:00
eddy
fffc5165a4 Extract magic numbers to named constants 2026-07-26 23:07:11 +02:00
eddy
2bea06d14b Update README with coroutine Job cancellation for EspFlasher 2026-07-26 22:58:28 +02:00
eddy
71b13c51ee Replace volatile cancel flag with coroutine Job cancellation in EspFlasher 2026-07-26 22:58:08 +02:00
eddy
ece115fbd6 Update README with RECEIVER_EXPORTED note 2026-07-26 22:51:54 +02:00
eddy
2dd3f00de4 Use RECEIVER_EXPORTED for USB system broadcasts on API 34+ 2026-07-26 22:51:36 +02:00
eddy
11ba8f3b8f Update README with sequence counter persistence 2026-07-26 22:34:23 +02:00
eddy
af3810554e Persist sequence counter in EncryptedSharedPreferences 2026-07-26 22:33:43 +02:00
eddy
bbf01946ac Convert Thread+Handler to lifecycle-aware coroutines, add GPL-3.0 license 2026-07-26 20:43:37 +02:00
eddy
4a9a15bca5 Update README with all code review changes 2026-07-26 17:29:23 +02:00
eddy
a80abc5c0c Merge branch 'fix/espflasher-cancellable': cancellable flasher + dialog fixes + key exchange reliability 2026-07-26 17:24:40 +02:00
eddy
d21a560d0c Shorten key exchange error toast text 2026-07-26 17:23:55 +02:00
eddy
1d17251341 Add retry hint to key exchange errors and cancel button to flash dialog
1. Append 'probeer het opnieuw' to key exchange error toasts.
2. Add 'Annuleren' button to flash progress dialog that calls
   flasher.cancel() and cleanupAction().
2026-07-26 17:20:49 +02:00
eddy
5acde17efb Fix flash dialog stacking and key exchange reliability
1. Dismiss waiting dialog when flash progress dialog starts,
   preventing orphaned spinner dialog after flash completes.
2. Increase key exchange retries from 3 to 5 and initial delay
   from 500ms to 1000ms to give ESP more time to be ready
   after USB permission grant.
2026-07-26 17:14:50 +02:00
eddy
e116f2b493 Make EspFlasher cancellable to prevent resource leak
Add @Volatile cancelled flag with cancel() method. Check flag at 3
checkpoints (after initial sleep, after transport setup, before each
flash step) so the thread exits early and closes the USB connection
in the finally block. SettingsActivity.onDestroy now calls cancel().

Reviewed in codereview.md (recommendation 3.2).
2026-07-26 17:02:06 +02:00
eddy
14118f4c05 Merge branch 'fix/replace-deprecated-progressdialog': replace ProgressDialog with AlertDialog 2026-07-26 16:59:41 +02:00
eddy
aa13359125 Replace deprecated ProgressDialog with AlertDialog + custom layouts
Use AlertDialog with dialog_waiting.xml (spinner + message) and
dialog_progress.xml (horizontal ProgressBar + message) instead of
the deprecated ProgressDialog. Progress updates now use findViewById
on the dialog view.

Reviewed in codereview.md (recommendation 2.4).
2026-07-26 16:57:07 +02:00
eddy
d2faaf8fbc Merge branch 'fix/handler-postdelayed-cancel': cancel pending BLE scans on pause 2026-07-26 16:53:22 +02:00
eddy
ce0c119416 Use named Runnable for scheduled BLE scans and cancel on pause
Replace anonymous lambdas in handler.postDelayed with a shared
scanRunnable so that handler.removeCallbacks(scanRunnable) in onPause
cancels any pending scan. Prevents duplicate or orphaned scan starts
during rapid activity transitions.

Reviewed in codereview.md (recommendation 2.2).
2026-07-26 16:51:53 +02:00
eddy
5861b1055c Merge branch 'fix/ble-permission-handling': handle denied BLE permissions 2026-07-26 16:48:21 +02:00
eddy
ff091169f6 Handle denied BLE permissions with user feedback
When BLUETOOTH_SCAN, BLUETOOTH_CONNECT or ACCESS_FINE_LOCATION
permissions are denied, show 'Permissies geweigerd — open Instellingen'
and disable the relay button instead of silently hanging.

Reviewed in codereview.md (recommendation 2.1).
2026-07-26 16:46:15 +02:00
eddy
3802b5b07d Merge branch 'fix/gatt-status-logging': add GATT status code logging 2026-07-26 16:44:57 +02:00
eddy
c62cbaa1c2 Add GATT status code logging in callbacks
Log warning when status != GATT_SUCCESS in onConnectionStateChange,
onServicesDiscovered, and onMtuChanged. Service discovery failure now
shows 'Servicefout' and returns early to prevent MTU request on failed
discovery.

Reviewed in codereview.md (recommendation 5.2).
2026-07-26 16:44:21 +02:00
eddy
fd4ba1a922 Merge branch 'fix/upgrade-kotlin': upgrade Kotlin 1.9.24 → 2.0.21 2026-07-26 16:42:49 +02:00
eddy
36856dabc6 Upgrade Kotlin from 1.9.24 to 2.0.21
Kotlin 2.0 uses the K2 compiler for better build performance.
Compatible with AGP 8.5.2 which was upgraded previously.

Reviewed in codereview.md (recommendation 7.3).
2026-07-26 16:40:21 +02:00
eddy
8eb91786d7 Merge branch 'fix/upgrade-agp': upgrade AGP 8.2.2 → 8.5.2 2026-07-26 16:37:36 +02:00
eddy
e712020a64 Upgrade AGP from 8.2.2 to 8.5.2
AGP 8.5.2 is compatible with Gradle 8.14 and Kotlin 1.9.24.
Includes bug fixes and improved Kotlin support.

Reviewed in codereview.md (recommendation 7.1).
2026-07-26 16:34:34 +02:00
eddy
a82f595f5d Merge branch 'fix/on-characteristic-write-callback': add BLE write feedback 2026-07-26 16:32:06 +02:00
eddy
9b7adabc59 Add onCharacteristicWrite callback for BLE write feedback
Implement onCharacteristicWrite in gattCallback to get confirmation
that packets are submitted to the local BLE stack. Logs success/failure
and shows 'Communicatiefout' on write failure. seq++ stays in
sendRelayCommand to ensure unique sequence numbers for rapid ON/OFF.

Reviewed in codereview.md (recommendation #5).
2026-07-26 16:31:07 +02:00
eddy
596a9d54d4 Merge branch 'fix/line-coding-parity-byte': fix CDC parity byte 2026-07-26 16:25:10 +02:00