Gemini gate found a real defect that would have shipped: the Linux MTU stream
would have attached to nothing and reported an MTU for a device never.
`devicesChanged` fires only on deviceAdded / deviceRemoved. At the moment a
device is added BlueZ has not finished service discovery, so `gattServices` is
still empty; this plugin waits on `while (!device.servicesResolved)` elsewhere
for exactly that reason. The original patch built its per-characteristic
subscriptions inside that one event, found no characteristics, and had nothing
to re-trigger it when discovery later completed. Verified in the vendored
source, not taken on the reviewer's word.
Now nested: for each device, rebuild the characteristic subscriptions on every
`device.propertiesChanged`, which includes ServicesResolved flipping true. Same
shape the plugin's own `_initFlutterBluePlus` already uses for its logging, so
this is the file's existing idiom rather than a new one.
Also emits once per rebuild (`startWith(device)`), so an MTU already negotiated
before we were listening is reported rather than waiting on a change that may
never arrive. Safe when unknown: 0 is filtered downstream.
Two other findings reviewed and accepted as clean, recorded so they are not
re-litigated: "max across characteristics" is right because the ATT MTU is
per-connection, not per-characteristic; and the web exemption is sound because
the browser owns fragmentation and 172 is far inside the spec's 512-byte
writeValue limit.
analyze clean, format clean, 981 tests pass.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Upstream flutter_blue_plus_linux returns `Stream.empty()` from onMtuChanged,
so no MTU ever reaches Dart on Linux. FlutterBluePlus._mtuValues stays empty,
mtuNow falls back to its 23-byte ATT default forever, effectiveMaxFrameSize
returns the 20-byte floor, and maxChannelMessageBytes clamps to 0. Every
keystroke is then rejected by the length limiter while the field still focuses
and blinks: the #592 symptom, reported on Linux as locked entry fields.
BlueZ does expose the negotiated MTU, as a property on
org.bluez.GattCharacteristic1, surfaced by the bluez package this plugin
already depends on (BlueZGattCharacteristic.mtu). The value was one layer down
the whole time and simply never read.
The patch watches characteristic property changes for 'MTU' and emits a
BmMtuChangedResponse carrying the largest value across the device's
characteristics. They describe one ATT link so they should agree; the max
stops a characteristic that has not been exercised yet, and so reports
nothing, from dragging the figure down. Zero is filtered out, because
FlutterBluePlus would cache it and hand callers something worse than its own
default, and identical consecutive values are suppressed.
Nothing downstream needed changing: the device.mtu subscription added for
Windows in #686 is platform-agnostic, so Linux now gets the same live budget
recovery through the same path.
Also points dependency_overrides at the vendored copy. Third vendored BLE
backend, alongside android (#694) and winrt (#686).
Verified: analyze clean, format clean, 962 tests pass. NOT verified on Linux
hardware; nobody here runs Linux BLE, which is why the gap survived this long.
#717's acceptance requires a real Linux BLE connect showing a non-default
`MTU now:` in the app log.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CI runs `dart format --output=none --set-exit-if-changed .` across the whole
repo, vendored packages included, so the upstream file's own formatting fails
the analyze check. Third time: #694 hit it on the Android plugin (b33e8485,
chore(#696)) and #686 on the WinRT one.
Formatting only, kept separate so the MTU patch that follows is reviewable
instead of buried in reflowed lines. Re-vendoring upstream later means
re-running dart format on this file.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Pristine import of pub.dev flutter_blue_plus_linux-8.2.2 into packages/,
mirroring the WinRT vendor from #686 and the Android vendor from #695. The
patch rides on top as its own commit so the upstream baseline stays diffable.
Verified against the pub cache with `diff -r --strip-trailing-cr`: all 8 files
identical. FlutterBluePlus License v1.4 and the BSD NOTICE retained unchanged.
No wiring yet: dependency_overrides is not pointed at this copy until the patch
lands, so this commit is inert.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CI runs `dart format --output=none --set-exit-if-changed .` across the whole
repo, vendored packages included, so the upstream file's own formatting fails
the analyze check. Same wall #694 hit on the vendored Android plugin, resolved
the same way there (b33e8485, chore(#696)).
Formatting only: no logic change, and the C++ that carries the actual fix is
untouched. Re-vendoring upstream later means re-running dart format on this
file, which the two-commit structure (pristine import, then patch) keeps
obvious.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Upstream flutter_blue_plus_winrt never populates gatt_sessions_ or
mtu_tokens_, so OnMtuChanged never fires and the Dart MTU cache stays at
the 23-byte default for the whole session (#683 diagnosis). Add
CreateGattSessionAsync, fired after the connect result is reported:
GattSession::FromDeviceIdAsync, store under gatt_cache_mutex_ (never held
across a co_await), subscribe MaxPduSizeChanged, emit the initial value,
and undo via ClearDeviceResources if the device drops mid-creation.
MaintainConnection is never set (#688). The destructor now revokes MTU
tokens and closes sessions, same use-after-free class upstream fixed for
connection tokens in 7b4504a2. Existing ClearDeviceResources and the
requestMtu read path work unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
App-side half of the #592 fix; the plugin-side GattSession patch is a separate
commit on packages/flutter_blue_plus_winrt.
- dependency_overrides points flutter_blue_plus_winrt at the vendored copy
(version 0.0.20+offband.1; interface constraint relaxed to >=8.2.2 since the
Dart layer uses nothing 9.x-only - the 9.x/2.3.x upgrade was deliberately
skipped, owner decision on #685).
- Connector: requestMtu is now attempted on Android only. flutter_blue_plus
throws "android-only" on every other platform before any platform code runs
(#683), so the old call could never succeed off-Android and its failure log
was noise.
- Connector: subscribe to device.mtu and notifyListeners on each value. The
composers read effectiveMaxFrameSize on rebuild, so this is what lets the
message byte budget recover from the 20-byte floor the moment the platform
reports the real MTU, instead of waiting for an unrelated rebuild.
Subscription is cancelled on reconnect and disconnect.
- test/connector/mtu_composer_budget_test.dart: characterizes the collapsed
budgets at the unknown-MTU floor (DM 4 bytes, channel 1 or 0) - the numbers
both field reports reduced to - and the healthy-link budgets. Rescued from
the throwaway diagnosis branch (#683).
- Regenerated plugin registrants picked up plugins missing from the committed
copies (file_selector, screen_retriever, window_manager); stale on dev,
refreshed by pub get after the override.
analyze clean, 958 tests pass.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pristine, unmodified import of chan150/flutter_blue_plus_winrt at
7b4504a2bf8409e7f01118c870ead435c1b1d681 (MIT, Copyright 2025 Himchan Park;
LICENSE retained). All 14 files hash-verified against the fetched upstream
tarball.
Vendored rather than depended on because no published version reports the BLE
MTU on Windows: gatt_sessions_ is declared but never populated, so the MTU
stays at the 23-byte default and the composer is capped at 0-4 bytes (#592,
diagnosed in #683). Our fix lands as a separate commit on top of this one so
it can be reviewed and re-applied against a future upstream.
Based on master rather than 0.0.19 to pick up two unreleased upstream fixes:
86ef4763 (data race, unbounded caches, teardown use-after-free) and 7b4504a2
(revoke per-device ConnectionStatusChanged handlers on teardown).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI's format gate reflows upstream's line style; formatting-only deviation
from pristine, no content change (same class as the documented EOL
whitespace normalization).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Gemini review (gemini-2.5-pro, docs/llm-consultations) flagged that the
5 s backstop acquired mMethodCallMutex blockingly on the main looper, an
ANR class. It now tryAcquires and re-posts itself after 250 ms when a
callback holds the mutex. The other two findings were verified and
rejected with reasons recorded in the PR body: the disconnectAllDevices
race is pre-existing upstream (and naive mutex acquisition there would
deadlock the flutterRestart path, which already holds the semaphore),
and the untranslated new strings follow this repo's standing l10n
process.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Three changes to FlutterBluePlusPlugin.java, per the #689 diagnosis:
1. onConnectionStateChange(CONNECTED): close the handle a map overwrite
replaces. A replaced handle is unreachable forever and holds the link
and a GATT client slot until process death, which is exactly what the
owner's force-stop evidence showed.
2. disconnect: 5 s backstop. If Android never delivers DISCONNECTED for
the handle we asked to disconnect, force gatt.close(), untrack it, and
synthesize the disconnect event (mirrors the existing
cancel-while-connecting path, reason code 23789259). Also caps the
Dart layer's 35 s wait at ~5 s.
3. disconnect with no tracked handle now logs at WARN so the
orphan fingerprint is visible in exported logs.
Vendored version marked 8.2.2+offband.1.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pristine import of pub.dev flutter_blue_plus_android-8.2.2 into
packages/, wired via dependency_overrides, mirroring the WinRT vendor
pattern from #686. FBP License v1.4 and BSD NOTICE retained.
Verified against the pub cache file-by-file: 9 of 12 files
byte-identical; AndroidManifest.xml, LICENSE and
FlutterBluePlusPlugin.java differ ONLY in end-of-line whitespace
(1, 4 and 11 lines respectively; the byte-perfect license text also
ships as LICENSE.md, which is byte-identical). No content changes;
verified with git diff --ignore-space-at-eol. Release APK builds
clean against the vendored copy before any patch.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>