Skip to content

chore(app): remove legacy flutter_blue_plus BLE transport#7895

Merged
mdmohsin7 merged 18 commits into
mainfrom
chore/remove-flutter-blue-plus-transport
Jun 15, 2026
Merged

chore(app): remove legacy flutter_blue_plus BLE transport#7895
mdmohsin7 merged 18 commits into
mainfrom
chore/remove-flutter-blue-plus-transport

Conversation

@mdmohsin7

Copy link
Copy Markdown
Member

What

Removes the legacy flutter_blue_plus-based BLE transport from the app. Native BLE (NativeBleTransport + NativeBluetoothDiscoverer via Pigeon → OmiBleManager on iOS/Android) has been the only live BLE path for a while; the flutter_blue_plus implementation was left behind fully intact but disconnected.

Why

Dead code reduction. The legacy transport, discoverer, adapter facade, and device-type helpers were never instantiated/called at runtime — the discoverer registry only wires NativeBluetoothDiscoverer, and the connection factory only builds NativeBleTransport.

Changes

Deleted (dead code):

  • ble_transport.dart — legacy BleTransport, never instantiated
  • bluetooth_discoverer.dart — legacy BluetoothDeviceDiscoverer, not in the discoverer registry
  • bluetooth_adapter.dart — the flutter_blue_plus facade

Stripped dead members (files kept):

  • bt_device.dart — removed getTypeOfBluetoothDevice, isSupportedDevice, fromScanResult, fromBluetoothDevice, and all is*Device*/*FromDevice helpers (~195 lines). BtDevice/DeviceType/BleAudioCodec intact.
  • models.dart — removed uncalled getBleServices/getServiceByUuid/getCharacteristicByUuid. All UUID constants kept.
  • Dropped unused flutter_blue_plus imports in main.dart, speech_profile_provider.dart, devices.dart.

One real refactor — onboarding "enable Bluetooth":

  • Added an async enableBluetooth() to the Pigeon BleHostApi (regenerated Dart/Swift/Kotlin stubs). Android fires ACTION_REQUEST_ENABLE via the existing activity-result plumbing; iOS returns the adapter power state.
  • onboarding_provider.dart now calls BleHostApi().enableBluetooth() instead of FlutterBluePlus.turnOn() / adapterStateNow.

Dependency:

  • Removed the direct flutter_blue_plus from pubspec.yaml; marked it transitive in the lock.

Note: package stays transitively

flutter_blue_plus cannot be fully removed — frame_sdk (Frame glasses, used by frame_transport.dart) depends on it transitively. This PR removes our direct dependency and all of our direct usage; lib/ now has zero flutter_blue_plus references.

Verification

  • flutter analyze lib → 0 errors.
  • device_provider_test.dart (BLE-adjacent suite) → 14/14 pass.
  • Not yet done: on-device run of the Android enable-Bluetooth prompt + full pairing flow (needs a physical device).

🤖 Generated with Claude Code

@mdmohsin7 mdmohsin7 marked this pull request as ready for review June 13, 2026 18:21
@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Removes the legacy flutter_blue_plus-based BLE transport stack (three deleted files, ~195 lines stripped from bt_device.dart, dead helpers removed from models.dart) and replaces the one live use of FlutterBluePlus.turnOn() with a new enableBluetooth Pigeon method backed by a proper ACTION_REQUEST_ENABLE activity-result flow on Android and a no-op state-read on iOS.

  • Dead code removed: BleTransport, BluetoothDeviceDiscoverer, BluetoothAdapter façade, and all ScanResult/BluetoothDevice helpers deleted; flutter_blue_plus demoted from direct to transitive dependency.
  • New enableBluetooth Pigeon method: Android implementation stores the callback, fires ACTION_REQUEST_ENABLE (request code 43, distinct from companion's 42), and resolves via onActivityResult; correctly guards against concurrent calls introduced since the prior review round.
  • onboarding_provider.dart: Calls BleHostApi().enableBluetooth() under the existing Platform.isAndroid guard, swallows errors gracefully, then proceeds to standard permission requests.

Confidence Score: 5/5

Safe to merge — the change is straightforward dead-code removal plus a well-contained new native method; the concurrent-call concern from the previous round has been addressed.

The only live behavior change is swapping FlutterBluePlus.turnOn() for BleHostApi().enableBluetooth(), which is correctly guarded, handles all edge cases (already-on, no-activity, launch exception), and resolves via the existing onActivityResult plumbing. Request codes 42 (companion) and 43 (BT enable) don't collide. The rest of the diff is pure deletion of code that was already unreachable.

app/android/app/src/main/kotlin/com/friend/ios/BleHostApiImpl.kt — the new enableBluetooth path is the only code not yet validated on a physical Android device per the PR description.

Important Files Changed

Filename Overview
app/android/app/src/main/kotlin/com/friend/ios/BleHostApiImpl.kt New enableBluetooth Pigeon method added — properly guards against concurrent calls and handles the activity-result lifecycle. Uses startActivityForResult (deprecated at the project's minSdkVersion 29) instead of ActivityResultLauncher.
app/ios/Runner/BleHostApiImpl.swift Correct iOS no-op stub for enableBluetooth — synchronously reports adapter power state since iOS cannot programmatically enable Bluetooth.
app/lib/providers/onboarding_provider.dart Replaced FlutterBluePlus.turnOn() / adapterStateNow with BleHostApi().enableBluetooth() under the existing Platform.isAndroid guard; error is swallowed gracefully before permission requests proceed.
app/lib/providers/speech_profile_provider.dart Dropped the OnConnectionStateChangedEvent generic from StreamSubscription (that type came from flutter_blue_plus); the field is effectively always null, so the change is non-breaking.
app/lib/backend/schema/bt_device/bt_device.dart Removed ~195 lines of ScanResult/BluetoothDevice helpers that only the deleted legacy transport used; BtDevice, DeviceType, and BleAudioCodec are untouched.
app/lib/services/devices/models.dart Deleted dead getBleServices/getServiceByUuid/getCharacteristicByUuid functions; all UUID constants kept intact.
app/lib/gen/pigeon_communicator.g.dart Regenerated Dart Pigeon stub for enableBluetooth — standard generated code, correct async pattern.
app/android/app/src/main/kotlin/com/friend/ios/PigeonCommunicator.g.kt Regenerated Kotlin Pigeon glue for enableBluetooth; standard generated wiring, no issues.
app/pubspec.yaml Dropped direct flutter_blue_plus: 2.1.0 dependency; transitive dependency via frame_sdk preserved in the lockfile.

Sequence Diagram

sequenceDiagram
    participant Dart as OnboardingProvider (Dart)
    participant Pigeon as BleHostApi (Pigeon channel)
    participant Native as BleHostApiImpl (Kotlin)
    participant Android as Android OS

    Dart->>Pigeon: enableBluetooth()
    Pigeon->>Native: enableBluetooth(callback)

    alt Bluetooth already on
        Native-->>Dart: Result.success(true)
    else Another request in flight
        Native-->>Dart: Result.success(false)
    else No activity
        Native-->>Dart: Result.success(false)
    else Normal path
        Native->>Android: startActivityForResult(ACTION_REQUEST_ENABLE, 43)
        Android-->>Native: onActivityResult(43, RESULT_OK/CANCELED)
        Native-->>Dart: Result.success(true / false)
    end

    Dart->>Dart: Permission.bluetoothScan.request()
    Dart->>Dart: Permission.bluetoothConnect.request()
Loading

Reviews (2): Last reviewed commit: "fix(android): guard enableBluetooth agai..." | Re-trigger Greptile

Comment thread app/android/app/src/main/kotlin/com/friend/ios/BleHostApiImpl.kt
@mdmohsin7

Copy link
Copy Markdown
Member Author

@greptile-apps re-review

@mdmohsin7 mdmohsin7 merged commit 17161f7 into main Jun 15, 2026
3 checks passed
@mdmohsin7 mdmohsin7 deleted the chore/remove-flutter-blue-plus-transport branch June 15, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant