// Android only: binding the process to the USB (NCM) Ethernet link to the Orin. // See MainActivity.kt for why Android needs telling. import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; class UsbLink extends ChangeNotifier { static const _ch = MethodChannel('yukart/net'); bool supported = Platform.isAndroid; bool up = false; bool bound = false; /// Development hook: a link test requested by launch intent (see MainActivity.kt). void Function(String label)? onLinkTest; UsbLink() { if (!supported) return; _ch.setMethodCallHandler((call) async { if (call.method == 'ethernet') { final a = Map.from(call.arguments as Map); up = a['up'] == true; bound = a['bound'] == true; notifyListeners(); } else if (call.method == 'linktest') { onLinkTest?.call(call.arguments as String); } }); } /// A link test requested by the intent that launched the app, once. Future takeLinkTest() async => supported ? _ch.invokeMethod('takeLinkTest') : null; /// Bind only when the target is on the USB link; a workstation over WiFi must stay reachable. Future bindFor(Uri target) async { if (!supported) return; final want = target.host.startsWith('192.168.55.'); await _ch.invokeMethod('bindEthernet', want); } }