Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/scripts/check-glibc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Fail if anything in a Linux bundle needs a newer glibc than we support.
#
# libserialport.so is loaded at the first port scan, not at startup, so a build
# that needs too new a glibc still launches and just finds no USB ports.
#
# Usage: check-glibc.sh <bundle-dir> <max-glibc>
set -euo pipefail

bundle="$1"
max="$2"
failed=0

for f in "$bundle"/OpenView "$bundle"/lib/*.so; do
# Some files, such as libapp.so, use no glibc symbols, so grep may match nothing.
need=$(objdump -T "$f" | { grep -oE 'GLIBC_[0-9]+(\.[0-9]+)+' || true; } | sed 's/GLIBC_//' | sort -Vu | tail -1)
[ -n "$need" ] || continue
echo "$(basename "$f"): glibc $need"
if [ "$(printf '%s\n%s\n' "$need" "$max" | sort -V | tail -1)" != "$max" ]; then
echo "::error::$(basename "$f") needs glibc $need, newer than the supported $max."
failed=1
fi
done

exit "$failed"
11 changes: 10 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ jobs:
linux:
name: Linux x64
needs: version
runs-on: ubuntu-latest
# Binaries need at least the glibc they were built against, so this sets the
# oldest Linux we can run on. Don't use ubuntu-latest: when it moved to a
# newer image, v3.3.1 stopped finding USB ports on Ubuntu 24.04.
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- name: Checkout
Expand Down Expand Up @@ -93,6 +96,9 @@ jobs:
# store builds must stay on the default `store` channel.
run: flutter build linux --release --dart-define=OV_CHANNEL=github

- name: Check glibc requirement
run: .github/scripts/check-glibc.sh build/linux/x64/release/bundle 2.35

- name: Package
run: |
cd build/linux/x64/release/bundle
Expand Down Expand Up @@ -151,6 +157,9 @@ jobs:
# store builds must stay on the default `store` channel.
run: flutter build linux --release --dart-define=OV_CHANNEL=github

- name: Check glibc requirement
run: .github/scripts/check-glibc.sh build/linux/arm64/release/bundle 2.39

- name: Package
run: |
cd build/linux/arm64/release/bundle
Expand Down
1 change: 1 addition & 0 deletions lib/controllers/scan_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ScanController extends ChangeNotifier {
notifyListeners();
try {
if (includeUsb) {
_usbResults = const [];
final targets = await usb.scan();
_usbResults = targets.map(_annotate).toList(growable: false);
} else {
Expand Down
10 changes: 9 additions & 1 deletion lib/transport/usb_serial_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import 'transport_service.dart';
/// `transport_factory.dart`. The `dart:io` `Platform` check inside `scan`
/// is a belt-and-braces guard.
class UsbSerialService extends TransportService {
UsbSerialService({List<String> Function()? listPorts})
: _listPorts = listPorts ?? (() => SerialPort.availablePorts);

final List<String> Function() _listPorts;

final _bytesController = StreamController<Uint8List>.broadcast();
final _eventsController = StreamController<TransportEvent>.broadcast();

Expand Down Expand Up @@ -98,7 +103,7 @@ class UsbSerialService extends TransportService {
_setStatus(TransportStatus.scanning);
final targets = <TransportTarget>[];
try {
for (final name in SerialPort.availablePorts) {
for (final name in _listPorts()) {
final p = SerialPort(name);
String display = name;
String? subtitle;
Expand All @@ -121,6 +126,9 @@ class UsbSerialService extends TransportService {
} catch (e) {
_eventsController.add(TransportEvent(TransportStatus.error,
message: 'scan failed', error: e));
// Let the caller report it: an empty list would read as "nothing plugged
// in", which is misleading when the serial library itself failed to load.
rethrow;
} finally {
_setStatus(TransportStatus.idle);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/screens/scan_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,9 @@ class _Hints extends StatelessWidget {
hints.add(_HintLine(
icon: Icons.warning_amber,
color: theme.colorScheme.error,
text: 'Scan: $scanError',
text: transport == TransportKind.usb
? 'Could not list USB ports: $scanError'
: 'Scan: $scanError',
));
}

Expand Down Expand Up @@ -558,7 +560,9 @@ class _Hints extends StatelessWidget {
));
} else {
// USB
if (results.isEmpty && !scanning) {
if (results.isEmpty && !scanning && scanError != null) {
// The scan failed, so it can't say whether a board is plugged in.
} else if (results.isEmpty && !scanning) {
hints.add(_HintLine(
icon: Icons.info_outline,
color: theme.colorScheme.onSurfaceVariant,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: OpenView
description: Companion app for ProtoCentral biosignal & sensor boards over USB, BLE, and Wi-Fi.

version: 3.3.1+137
version: 3.3.2+139

environment:
sdk: ^3.3.0
Expand Down
63 changes: 63 additions & 0 deletions test/transport/usb_scan_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024-2026 protocentral
// SPDX-License-Identifier: MIT

import 'package:OpenView/controllers/scan_controller.dart';
import 'package:OpenView/transport/ble_service.dart';
import 'package:OpenView/transport/transport_service.dart';
import 'package:OpenView/transport/usb_serial_service.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

const loadError = "Failed to load dynamic library 'libserialport.so': "
"version `GLIBC_2.42' not found";

ScanController controllerFor(List<String> Function() listPorts) =>
ScanController(
usb: UsbSerialService(listPorts: listPorts),
ble: BleService(),
);

test('a failed port listing reaches the caller and resets the status',
() async {
final usb = UsbSerialService(listPorts: () => throw ArgumentError(loadError));

await expectLater(usb.scan(), throwsArgumentError);
expect(usb.status, TransportStatus.idle);
});

test('the scan controller reports the failure instead of no devices',
() async {
final scan = controllerFor(() => throw ArgumentError(loadError));

await scan.refresh(includeBle: false);

expect(scan.lastError, contains('GLIBC_2.42'));
expect(scan.usbResults, isEmpty);
expect(scan.scanning, isFalse);
});

test('a failed rescan drops ports from the previous scan', () async {
var fail = false;
final scan = controllerFor(
() => fail ? throw ArgumentError(loadError) : const <String>[]);

await scan.refresh(includeBle: false);
expect(scan.lastError, isNull);

fail = true;
await scan.refresh(includeBle: false);
expect(scan.lastError, isNotNull);
expect(scan.usbResults, isEmpty);
});

test('no ports and no error stays a clean empty result', () async {
final scan = controllerFor(() => const []);

await scan.refresh(includeBle: false);

expect(scan.lastError, isNull);
expect(scan.usbResults, isEmpty);
});
}
Loading