The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat: implement customizable phone name and device identification for mobile terminal sessions
0xken150cf7602f5292
diff --git a/desktop/design/super-terminal-interaction.md b/desktop/design/super-terminal-interaction.mdindex 442021e20..b39cac88f 100644--- a/desktop/design/super-terminal-interaction.md+++ b/desktop/design/super-terminal-interaction.md@@ -160,7 +160,8 @@ displaced pane keeps its last screen, read only, under a band that says who:"Mac mini took control of this terminal", with Take control (or ⏎) as theway back. The name comes from the taker's own introduction on `terminal_open`(`client: {kind, name, machineId}` — a desktop names its machine in the fleet,-a phone its device name), which the daemon repeats on the incumbent's+a phone the name given it under Settings ▸ This phone, else the name its OS+reports, else its model, "iPhone 15 Pro"), which the daemon repeats on the incumbent's`terminal_closed` as `takenBy`; a machine this app knows is shown by itscurrent fleet name. An older daemon, or a taker that said nothing, reads as"Another app took control of this terminal". The phone draws the same linediff --git a/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt b/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.ktindex 0e7fb372d..a0c4ad7da 100644--- a/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt+++ b/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt@@ -1,5 +1,29 @@package ai.autonomous.harness.android+import android.os.Build+import android.provider.Settingsimport io.flutter.embedding.android.FlutterActivity+import io.flutter.embedding.engine.FlutterEngine+import io.flutter.plugin.common.MethodChannel-class MainActivity : FlutterActivity()+class MainActivity : FlutterActivity() {+ override fun configureFlutterEngine(flutterEngine: FlutterEngine) {+ super.configureFlutterEngine(flutterEngine)+ // `harness/device_name` — what this phone is called, for the far side's "took control" banner+ // (Dart: `lib/core/device_name.dart`). `name` is the one the person set under Settings ▸ About+ // ("Galaxy S23 of Hieu"); null on a ROM that keeps it, and Dart then falls back to the model.+ MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "harness/device_name")+ .setMethodCallHandler { call, result ->+ if (call.method != "describe") { result.notImplemented(); return@setMethodCallHandler }+ val name = try { Settings.Global.getString(contentResolver, "device_name") } catch (e: Exception) { null }+ result.success(+ mapOf(+ "name" to name,+ "model" to Build.MODEL,+ "modelCode" to Build.DEVICE,+ "manufacturer" to Build.MANUFACTURER,+ )+ )+ }+ }+}diff --git a/mobile/ios/Runner/AppDelegate.swift b/mobile/ios/Runner/AppDelegate.swiftindex c30b367ec..0969f9050 100644--- a/mobile/ios/Runner/AppDelegate.swift+++ b/mobile/ios/Runner/AppDelegate.swift@@ -12,5 +12,38 @@ import UIKitfunc didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)+ DeviceNameChannel.register(with: engineBridge.pluginRegistry)+ }+}++/// `harness/device_name` — what this phone is called, for the far side's "took control" banner+/// (Dart: `lib/core/device_name.dart`). `name` is the user's own name for the device where iOS still+/// hands it out (before iOS 16, or with Apple's user-assigned-device-name entitlement); otherwise it+/// is the generic "iPhone" and Dart falls back to the model, read off the hardware code.+enum DeviceNameChannel {+ static func register(with registry: FlutterPluginRegistry) {+ guard let messenger = registry.registrar(forPlugin: "HarnessDeviceName")?.messenger() else { return }+ let channel = FlutterMethodChannel(name: "harness/device_name", binaryMessenger: messenger)+ channel.setMethodCallHandler { call, result in+ guard call.method == "describe" else { result(FlutterMethodNotImplemented); return }+ result([+ "name": UIDevice.current.name,+ "model": UIDevice.current.model,+ "modelCode": modelCode(),+ "manufacturer": "Apple",+ ])+ }+ }++ /// "iPhone16,1" — the hardware identifier; on the simulator, the device it is pretending to be.+ private static func modelCode() -> String {+ if let simulated = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"], !simulated.isEmpty {+ return simulated+ }+ var systemInfo = utsname()+ uname(&systemInfo)+ return withUnsafePointer(to: &systemInfo.machine) {+ $0.withMemoryRebound(to: CChar.self, capacity: 1) { String(validatingCString: $0) ?? "" }+ }}}diff --git a/mobile/lib/core/device_name.dart b/mobile/lib/core/device_name.dartnew file mode 100644index 000000000..1d20ff5da--- /dev/null+++ b/mobile/lib/core/device_name.dart@@ -0,0 +1,243 @@+import 'dart:async';++import 'package:flutter/services.dart';++/// What this phone is called, for the far side's "took control" banner+/// (`TerminalClientDescriptor` in `terminal/terminal_session.dart`).+///+/// `Platform.localHostname` is "localhost" on iOS, which is what a desktop+/// then said had taken its terminal. The name comes from the OS instead, over+/// `harness/device_name` (ios/Runner/AppDelegate.swift, android MainActivity.kt),+/// and reads, in order: the name the person gave this phone in Settings here;+/// the name the OS reports, when it is a real one (iOS 16+ says "iPhone" to an+/// app without Apple's user-assigned-device-name entitlement); the model, by+/// marketing name where the hardware code is known; and a possessive from the+/// signed-in account when all the model can say is "iPhone".++/// What the OS reports, verbatim.+class DeviceInfo {+ const DeviceInfo({this.name, this.model, this.modelCode, this.manufacturer});++ /// The user-assigned device name ("Hieu's iPhone"), or the generic model+ /// name where the OS withholds it; null when the ROM keeps it.+ final String? name;++ /// "iPhone" / "iPad" on iOS, `Build.MODEL` ("SM-S911B") on Android.+ final String? model;++ /// "iPhone16,1" on iOS, `Build.DEVICE` on Android.+ final String? modelCode;+ final String? manufacturer;++ static DeviceInfo? fromMap(Object? raw) {+ if (raw is! Map) return null;+ String? text(Object? value) =>+ value is String && value.trim().isNotEmpty ? value.trim() : null;+ return DeviceInfo(+ name: text(raw['name']),+ model: text(raw['model']),+ modelCode: text(raw['modelCode']),+ manufacturer: text(raw['manufacturer']),+ );+ }+}++/// The native answer, asked once per process and kept: the name is read on+/// every `terminal_open`, and the OS's answer does not change while running.+class NativeDeviceInfo {+ NativeDeviceInfo._();++ static const MethodChannel _channel = MethodChannel('harness/device_name');+ static DeviceInfo? _cached;+ static Future<DeviceInfo?>? _inFlight;++ /// The last answer, or null before the first one lands (or on a platform+ /// with no handler) — the caller falls through to the account's name then.+ static DeviceInfo? get cached => _cached;++ static Future<DeviceInfo?> describe() {+ if (_cached != null) return Future.value(_cached);+ return _inFlight ??= _ask().then((info) {+ _cached = info;+ _inFlight = null;+ return info;+ });+ }++ static Future<DeviceInfo?> _ask() async {+ try {+ return DeviceInfo.fromMap(+ await _channel.invokeMethod<Map<Object?, Object?>>('describe'),+ );+ } on MissingPluginException {+ return null;+ } catch (_) {+ return null;+ }+ }++ /// Tests only: a fixed answer, or none.+ static void setForTest(DeviceInfo? info) {+ _cached = info;+ _inFlight = null;+ }+}++/// Longest a name goes on the wire — the daemon's `CLIENT_NAME_MAX`.+const phoneNameMax = 64;++/// Names the OS hands out that name nothing: the model word alone, and the+/// hostname iOS answers with.+bool isGenericDeviceName(String? name, {String? modelCode}) {+ if (name == null) return true;+ final trimmed = name.trim();+ if (trimmed.isEmpty) return true;+ final lower = trimmed.toLowerCase();+ if (lower == 'localhost' || lower.endsWith('.local')) return true;+ if (const {+ 'iphone',+ 'ipad',+ 'ipod touch',+ 'ipod',+ 'android',+ 'phone',+ }.contains(lower)) {+ return true;+ }+ if (modelCode != null && lower == modelCode.toLowerCase()) return true;+ return false;+}++/// The name this phone introduces itself by — see the library doc for the order.+String composePhoneName({+ String? override,+ DeviceInfo? device,+ String? userName,+}) {+ final chosen = _clean(override);+ if (chosen != null) return chosen;+ final reported = _clean(device?.name);+ if (reported != null &&+ !isGenericDeviceName(reported, modelCode: device?.modelCode)) {+ return reported;+ }+ final model = _clean(deviceModelName(device));+ if (model != null && !isGenericDeviceName(model)) return model;+ final first = _firstName(userName);+ if (first != null) return _clip("$first's ${model ?? 'phone'}");+ return model ?? 'Phone';+}++/// The model as a person would say it: "iPhone 15 Pro" from "iPhone16,1",+/// "Samsung SM-S911B" on Android; "iPhone" when the code is not in the table.+String? deviceModelName(DeviceInfo? device) {+ if (device == null) return null;+ final code = device.modelCode;+ final marketing = code == null ? null : iosMarketingName(code);+ if (marketing != null) return marketing;+ final manufacturer = device.manufacturer;+ final model = device.model;+ if (manufacturer != null &&+ manufacturer.toLowerCase() != 'apple' &&+ model != null) {+ final brand = manufacturer[0].toUpperCase() + manufacturer.substring(1);+ return model.toLowerCase().startsWith(brand.toLowerCase())+ ? model+ : '$brand $model';+ }+ return model;+}++/// `utsname.machine` → the name on the box. Recent phones and pads; a code+/// not here reads as its model word, which the account's name then qualifies.+String? iosMarketingName(String code) => _iosModels[code];++const _iosModels = <String, String>{+ 'iPhone12,1': 'iPhone 11',+ 'iPhone12,3': 'iPhone 11 Pro',+ 'iPhone12,5': 'iPhone 11 Pro Max',+ 'iPhone12,8': 'iPhone SE (2nd gen)',+ 'iPhone13,1': 'iPhone 12 mini',+ 'iPhone13,2': 'iPhone 12',+ 'iPhone13,3': 'iPhone 12 Pro',+ 'iPhone13,4': 'iPhone 12 Pro Max',+ 'iPhone14,2': 'iPhone 13 Pro',+ 'iPhone14,3': 'iPhone 13 Pro Max',+ 'iPhone14,4': 'iPhone 13 mini',+ 'iPhone14,5': 'iPhone 13',+ 'iPhone14,6': 'iPhone SE (3rd gen)',+ 'iPhone14,7': 'iPhone 14',+ 'iPhone14,8': 'iPhone 14 Plus',+ 'iPhone15,2': 'iPhone 14 Pro',+ 'iPhone15,3': 'iPhone 14 Pro Max',+ 'iPhone15,4': 'iPhone 15',+ 'iPhone15,5': 'iPhone 15 Plus',+ 'iPhone16,1': 'iPhone 15 Pro',+ 'iPhone16,2': 'iPhone 15 Pro Max',+ 'iPhone17,1': 'iPhone 16 Pro',+ 'iPhone17,2': 'iPhone 16 Pro Max',+ 'iPhone17,3': 'iPhone 16',+ 'iPhone17,4': 'iPhone 16 Plus',+ 'iPhone17,5': 'iPhone 16e',+ 'iPhone18,1': 'iPhone 17 Pro',+ 'iPhone18,2': 'iPhone 17 Pro Max',+ 'iPhone18,3': 'iPhone 17',+ 'iPhone18,4': 'iPhone Air',+ 'iPad13,1': 'iPad Air (4th gen)',+ 'iPad13,2': 'iPad Air (4th gen)',+ 'iPad13,4': 'iPad Pro 11" (3rd gen)',+ 'iPad13,5': 'iPad Pro 11" (3rd gen)',+ 'iPad13,6': 'iPad Pro 11" (3rd gen)',+ 'iPad13,7': 'iPad Pro 11" (3rd gen)',+ 'iPad13,8': 'iPad Pro 12.9" (5th gen)',+ 'iPad13,9': 'iPad Pro 12.9" (5th gen)',+ 'iPad13,10': 'iPad Pro 12.9" (5th gen)',+ 'iPad13,11': 'iPad Pro 12.9" (5th gen)',+ 'iPad13,16': 'iPad Air (5th gen)',+ 'iPad13,17': 'iPad Air (5th gen)',+ 'iPad13,18': 'iPad (10th gen)',+ 'iPad13,19': 'iPad (10th gen)',+ 'iPad14,1': 'iPad mini (6th gen)',+ 'iPad14,2': 'iPad mini (6th gen)',+ 'iPad14,3': 'iPad Pro 11" (4th gen)',+ 'iPad14,4': 'iPad Pro 11" (4th gen)',+ 'iPad14,5': 'iPad Pro 12.9" (6th gen)',+ 'iPad14,6': 'iPad Pro 12.9" (6th gen)',+ 'iPad14,8': 'iPad Air 11" (M2)',+ 'iPad14,9': 'iPad Air 11" (M2)',+ 'iPad14,10': 'iPad Air 13" (M2)',+ 'iPad14,11': 'iPad Air 13" (M2)',+ 'iPad15,3': 'iPad Air 11" (M3)',+ 'iPad15,4': 'iPad Air 11" (M3)',+ 'iPad15,5': 'iPad Air 13" (M3)',+ 'iPad15,6': 'iPad Air 13" (M3)',+ 'iPad15,7': 'iPad (11th gen)',+ 'iPad15,8': 'iPad (11th gen)',+ 'iPad16,1': 'iPad mini (A17 Pro)',+ 'iPad16,2': 'iPad mini (A17 Pro)',+ 'iPad16,3': 'iPad Pro 11" (M4)',+ 'iPad16,4': 'iPad Pro 11" (M4)',+ 'iPad16,5': 'iPad Pro 13" (M4)',+ 'iPad16,6': 'iPad Pro 13" (M4)',+};++String? _firstName(String? userName) {+ final trimmed = userName?.trim();+ if (trimmed == null || trimmed.isEmpty) return null;+ final first = trimmed.split(RegExp(r'\s+')).first;+ return first.isEmpty ? null : first;+}++/// Control characters out, whitespace trimmed, cut to the wire's limit.+String? _clean(String? raw) {+ if (raw == null) return null;+ final clean = raw+ .replaceAll(RegExp(r'[\u0000-\u001f\u007f]'), ' ')+ .replaceAll(RegExp(r'\s+'), ' ')+ .trim();+ return clean.isEmpty ? null : _clip(clean);+}++String _clip(String value) => value.length > phoneNameMax+ ? value.substring(0, phoneNameMax).trim()+ : value;diff --git a/mobile/lib/core/models.dart b/mobile/lib/core/models.dartindex 89c7e7db5..2478b23a9 100644--- a/mobile/lib/core/models.dart+++ b/mobile/lib/core/models.dart@@ -25,6 +25,10 @@ class CurrentUserProfile {email = 'local terminal',avatarUrl = null;+ /// The stand-in for a local terminal session — not a person, so nothing+ /// should be named after it.+ bool get isLocalSession => id == null && email == 'local terminal';+factory CurrentUserProfile.fromMe(Map<String, dynamic> response) {final rawUser = response['user'];if (rawUser is! Map) {diff --git a/mobile/lib/core/startup.dart b/mobile/lib/core/startup.dartindex bf15b4b37..8513bebd5 100644--- a/mobile/lib/core/startup.dart+++ b/mobile/lib/core/startup.dart@@ -1,9 +1,13 @@+import 'dart:async';+import '../logging/startup_trace.dart';+import '../phone/phone_name_store.dart';import '../phone/voice_language_store.dart';import '../shared/theme/appearance_prefs_store.dart';import '../stats/harness_stats.dart';import '../terminal/terminal_font_store.dart';import '../terminal/terminal_theme_store.dart';+import 'device_name.dart';/// Every preference that has to be in place BEFORE the first frame.///@@ -23,7 +27,12 @@ Future<void> loadPersistedSettings({AppearancePrefsStore? appearance,HarnessStats? stats,VoiceLanguageStore? voiceLanguage,+ PhoneNameStore? phoneName,}) async {+ // What the OS calls this phone, asked now so it is on hand by the first+ // `terminal_open`; not awaited — a slow answer must not hold the first frame,+ // and the name has a fallback (`composePhoneName`) until it lands.+ unawaited(NativeDeviceInfo.describe());// Independent stores may load together, but all must finish before runApp.// Font and appearance share a serialized file store; each reads its related// preferences as one snapshot. Stats uses a separate file and can overlap.@@ -63,5 +72,8 @@ Future<void> loadPersistedSettings({'prefs.voiceLanguage',(voiceLanguage ?? voiceLanguageStore).load,),+ // The person's own name for this phone; read late, the first terminal it+ // took would introduce it by the OS's name instead.+ StartupTrace.time('prefs.phoneName', (phoneName ?? phoneNameStore).load),]);}diff --git a/mobile/lib/phone/phone_name_store.dart b/mobile/lib/phone/phone_name_store.dartnew file mode 100644index 000000000..fb01981ad--- /dev/null+++ b/mobile/lib/phone/phone_name_store.dart@@ -0,0 +1,48 @@+import 'package:flutter/foundation.dart';++import 'package:harness_mobile/core/harness_file_store.dart';+import 'package:harness_mobile/core/local_key_value_store.dart';++/// The name the person gave this phone, remembered across launches — what a+/// desktop it takes a terminal from will call it (`core/device_name.dart`).+/// Null means "whatever the OS says": the row in Settings shows that name+/// then, and clearing the field goes back to it. Loaded by+/// `loadPersistedSettings()` before the first frame.+class PhoneNameStore extends ValueNotifier<String?> {+ PhoneNameStore({LocalKeyValueStore? storage})+ : _storage = storage ?? HarnessFileStore.shared,+ super(null);++ static const _key = 'phone_name';++ final LocalKeyValueStore _storage;++ Future<void> load() async {+ try {+ final saved = await _storage.read(_key);+ final clean = saved?.trim();+ if (clean != null && clean.isNotEmpty) value = clean;+ } on Exception {+ // The OS's name still works; only the memory is missing.+ }+ }++ /// Empty or blank forgets the override.+ Future<void> rename(String? name) async {+ final clean = name?.trim();+ final next = clean == null || clean.isEmpty ? null : clean;+ if (next == value) return;+ value = next;+ try {+ if (next == null) {+ await _storage.delete(_key);+ } else {+ await _storage.write(_key, next);+ }+ } on Exception {+ // Kept in memory for this run.+ }+ }+}++final phoneNameStore = PhoneNameStore();diff --git a/mobile/lib/phone/settings_page.dart b/mobile/lib/phone/settings_page.dartindex be85d689c..1d7dcca6c 100644--- a/mobile/lib/phone/settings_page.dart+++ b/mobile/lib/phone/settings_page.dart@@ -5,6 +5,8 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';import 'package:package_info_plus/package_info_plus.dart';import 'package:harness_mobile/core/app_version.dart';+import 'package:harness_mobile/core/device_name.dart';+import 'package:harness_mobile/shared/widgets/app_dialog.dart';import 'package:harness_mobile/shared/theme/app_theme.dart';import 'package:harness_mobile/shared/theme/appearance_prefs_store.dart';import 'package:harness_mobile/shared/theme/color_palette.dart';@@ -13,6 +15,7 @@ import 'package:harness_mobile/terminal/terminal_font_store.dart';import 'package:harness_mobile/terminal/terminal_theme_store.dart';import 'phone_header.dart';+import 'phone_name_store.dart';import 'phone_sheet.dart';import 'settings_row.dart';import 'stats_entry.dart';@@ -142,6 +145,7 @@ class _Body extends StatelessWidget {// are untouched and still work; this is the only thing that was// drawing them.if (_showVoiceLanguage) _VoiceLanguageRow(),+ _PhoneNameRow(notifier: notifier),_FontRow(),_SizeRow(),_TerminalThemeRow(),@@ -228,6 +232,101 @@ class _VoiceLanguageRow extends StatelessWidget {);}+/// What this phone is called on another screen's "took control" banner —+/// the name the OS gives it until the person types their own here.+class _PhoneNameRow extends StatelessWidget {+ const _PhoneNameRow({required this.notifier});++ final AppNotifier notifier;++ @override+ Widget build(BuildContext context) => ValueListenableBuilder(+ valueListenable: phoneNameStore,+ builder: (context, override, _) {+ AppTheme.watch(context);+ return SettingsRow(+ key: const ValueKey('settings-phone-name'),+ title: 'This phone',+ detail: 'How a desktop names this phone when it takes a terminal',+ value: notifier.phoneClientDescriptor().name,+ onTap: () => unawaited(+ showAppDialog<void>(+ context: context,+ builder: (_) => _PhoneNameDialog(+ current: override ?? '',+ placeholder: composePhoneName(+ device: NativeDeviceInfo.cached,+ userName: notifier.currentUser?.isLocalSession == true+ ? null+ : notifier.currentUser?.name,+ ),+ ),+ ),+ ),+ );+ },+ );+}++/// Owns its controller for the reason `widgets/rename_agent_dialog.dart` gives:+/// a controller disposed while the route is still animating out is a red screen.+class _PhoneNameDialog extends StatefulWidget {+ const _PhoneNameDialog({required this.current, required this.placeholder});++ /// The override on file, or empty for "the OS's name".+ final String current;++ /// What the phone is called with no override — shown as the field's hint.+ final String placeholder;++ @override+ State<_PhoneNameDialog> createState() => _PhoneNameDialogState();+}++class _PhoneNameDialogState extends State<_PhoneNameDialog> {+ late final _controller = TextEditingController(text: widget.current);++ @override+ void dispose() {+ _controller.dispose();+ super.dispose();+ }++ void _submit() {+ unawaited(phoneNameStore.rename(_controller.text));+ Navigator.of(context).pop();+ }++ @override+ Widget build(BuildContext context) {+ AppTheme.watch(context);+ return AlertDialog(+ title: const Text('This phone'),+ content: SizedBox(+ width: 360,+ child: TextField(+ key: const ValueKey('settings-phone-name-field'),+ controller: _controller,+ autofocus: true,+ maxLength: phoneNameMax,+ decoration: InputDecoration(+ hintText: widget.placeholder,+ helperText: 'Leave empty to use the name above.',+ ),+ onSubmitted: (_) => _submit(),+ ),+ ),+ actions: [+ TextButton(+ onPressed: () => Navigator.of(context).pop(),+ child: const Text('Cancel'),+ ),+ FilledButton(onPressed: _submit, child: const Text('Save')),+ ],+ );+ }+}+/// The terminal typeface. A sheet rather than a dropdown: a phone has room for the whole list.class _FontRow extends StatelessWidget {@overridediff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dartindex 5ce0fa57f..7fd34fbf6 100644--- a/mobile/lib/state/app_state.dart+++ b/mobile/lib/state/app_state.dart@@ -21,6 +21,7 @@ import '../core/viewer_mode.dart';import '../core/config.dart';import '../core/agent_preference.dart';import '../core/engine_availability.dart';+import '../core/device_name.dart';import '../core/local_hostname.dart';import '../core/local_git_projects.dart';import '../core/last_opened_agent.dart';@@ -52,6 +53,7 @@ import 'pane_arrangement.dart';import 'pending_question.dart';import '../usage/remote_usage.dart';import '../usage/usage_accounts.dart';+import '../phone/phone_name_store.dart';enum AppStatus {bootstrapping,@@ -5353,24 +5355,27 @@ class AppNotifier extends ChangeNotifier {}}- /// Open the stream for a tile that already knows what it wants.- ///- /// Separate from [assignAgentToPane] because a restored tile takes this path- /// on its own, later, when its machine finally answers — the intent was- /// settled at launch, and nothing about the selection should move again then./// How this phone introduces itself on `terminal_open`, so a desktop it- /// displaces can say "(this phone) took control". The OS's device name when- /// it will give one, else just "Phone".+ /// displaces can say "(this phone) took control": the name given it in+ /// Settings, else the OS's, else its model — `core/device_name.dart` has the+ /// order and why `Platform.localHostname` ("localhost" on iOS) is not it.TerminalClientDescriptor phoneClientDescriptor() {- final name = localHostnameOrNull() ?? 'Phone';+ final user = currentUser;return TerminalClientDescriptor(kind: 'phone',- name: name.length > TerminalClientDescriptor.nameMax- ? name.substring(0, TerminalClientDescriptor.nameMax)- : name,+ name: composePhoneName(+ override: phoneNameStore.value,+ device: NativeDeviceInfo.cached,+ userName: user == null || user.isLocalSession ? null : user.name,+ ),);}+ /// Open the stream for a tile that already knows what it wants.+ ///+ /// Separate from [assignAgentToPane] because a restored tile takes this path+ /// on its own, later, when its machine finally answers — the intent was+ /// settled at launch, and nothing about the selection should move again then.Future<void> _attachSession(TerminalPane pane) async {if (_disposed || !allPanes.contains(pane) || pane.session != null) return;final wantedAgentId = pane.agentId;diff --git a/mobile/test/device_name_test.dart b/mobile/test/device_name_test.dartnew file mode 100644index 000000000..4b4dff189--- /dev/null+++ b/mobile/test/device_name_test.dart@@ -0,0 +1,146 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/core/device_name.dart';++/// What a desktop will call this phone on its "took control" banner: the+/// person's own name for it, else the OS's, else the model — never "localhost".+void main() {+ const iphoneGeneric = DeviceInfo(+ name: 'iPhone',+ model: 'iPhone',+ modelCode: 'iPhone16,1',+ manufacturer: 'Apple',+ );++ test('the name given in Settings wins over everything', () {+ expect(+ composePhoneName(+ override: ' Work phone ',+ device: const DeviceInfo(name: "Hieu's iPhone"),+ userName: 'Hieu Nguyen',+ ),+ 'Work phone',+ );+ });++ test("the OS's own name for the device is used when it is a real one", () {+ expect(+ composePhoneName(+ device: const DeviceInfo(+ name: "Hieu's iPhone",+ model: 'iPhone',+ modelCode: 'iPhone16,1',+ ),+ ),+ "Hieu's iPhone",+ );+ // The simulator reports the device it is pretending to be.+ expect(+ composePhoneName(+ device: const DeviceInfo(name: 'iPhone 16 Pro', model: 'iPhone'),+ ),+ 'iPhone 16 Pro',+ );+ expect(+ composePhoneName(+ device: const DeviceInfo(+ name: 'Galaxy S23 của Hiếu',+ model: 'SM-S911B',+ manufacturer: 'samsung',+ ),+ ),+ 'Galaxy S23 của Hiếu',+ );+ });++ test('a generic name falls back to the model, by its marketing name', () {+ expect(composePhoneName(device: iphoneGeneric), 'iPhone 15 Pro');+ expect(+ composePhoneName(+ device: const DeviceInfo(+ name: 'iPad',+ model: 'iPad',+ modelCode: 'iPad16,3',+ ),+ ),+ 'iPad Pro 11" (M4)',+ );+ expect(+ composePhoneName(+ device: const DeviceInfo(+ model: 'SM-S911B',+ modelCode: 'dm3q',+ manufacturer: 'samsung',+ ),+ ),+ 'Samsung SM-S911B',+ );+ expect(+ composePhoneName(+ device: const DeviceInfo(model: 'Pixel 8', manufacturer: 'Google'),+ ),+ 'Google Pixel 8',+ );+ // A brand already in the model is not said twice.+ expect(+ composePhoneName(+ device: const DeviceInfo(model: 'Xiaomi 14', manufacturer: 'Xiaomi'),+ ),+ 'Xiaomi 14',+ );+ });++ test("localhost is not a name, and neither is the model code", () {+ expect(isGenericDeviceName('localhost'), isTrue);+ expect(isGenericDeviceName('MacbookPro.local'), isTrue);+ expect(isGenericDeviceName('iPhone16,1', modelCode: 'iPhone16,1'), isTrue);+ expect(isGenericDeviceName('iPhone'), isTrue);+ expect(isGenericDeviceName("Hieu's iPhone"), isFalse);+ expect(+ composePhoneName(+ device: const DeviceInfo(name: 'localhost', modelCode: 'iPhone16,1'),+ ),+ 'iPhone 15 Pro',+ );+ });++ test('an unknown model with a signed-in name reads as a possessive', () {+ expect(+ composePhoneName(+ device: const DeviceInfo(+ name: 'iPhone',+ model: 'iPhone',+ modelCode: 'iPhone99,9',+ ),+ userName: 'Hieu Nguyen',+ ),+ "Hieu's iPhone",+ );+ expect(+ composePhoneName(+ device: const DeviceInfo(name: 'iPhone', model: 'iPhone'),+ ),+ 'iPhone',+ );+ expect(composePhoneName(userName: 'Hieu'), "Hieu's phone");+ expect(composePhoneName(), 'Phone');+ });++ test('a name is cut to the wire and stripped of control characters', () {+ expect(composePhoneName(override: 'x' * 100).length, phoneNameMax);+ expect(composePhoneName(override: 'a\u0000b\n c'), 'a b c');+ expect(composePhoneName(override: ' '), 'Phone');+ });++ test('the wire map is read leniently', () {+ final info = DeviceInfo.fromMap({+ 'name': ' iPhone ',+ 'model': 'iPhone',+ 'modelCode': '',+ 'manufacturer': 3,+ });+ expect(info?.name, 'iPhone');+ expect(info?.modelCode, isNull);+ expect(info?.manufacturer, isNull);+ expect(DeviceInfo.fromMap('nope'), isNull);+ });+}diff --git a/mobile/test/phone_name_store_test.dart b/mobile/test/phone_name_store_test.dartnew file mode 100644index 000000000..3e508eef4--- /dev/null+++ b/mobile/test/phone_name_store_test.dart@@ -0,0 +1,31 @@+import 'package:flutter_test/flutter_test.dart';+import 'package:harness_mobile/phone/phone_name_store.dart';++import 'voice_fakes.dart';++void main() {+ late MemoryKeyValueStore storage;+ setUp(() => storage = MemoryKeyValueStore());++ test('no override until the person types one', () {+ expect(PhoneNameStore(storage: storage).value, isNull);+ });++ test('a name is remembered and restored next time', () async {+ final store = PhoneNameStore(storage: storage);+ await store.rename(' Work phone ');+ expect(store.value, 'Work phone');+ expect(storage.values['phone_name'], 'Work phone');+ final next = PhoneNameStore(storage: storage);+ await next.load();+ expect(next.value, 'Work phone');+ });++ test('an empty name forgets the override', () async {+ final store = PhoneNameStore(storage: storage);+ await store.rename('Work phone');+ await store.rename(' ');+ expect(store.value, isNull);+ expect(storage.values.containsKey('phone_name'), isFalse);+ });+}