# Design: Multi-Device Equalizer ## Technical Approach Add a device dimension to the existing 2-level EQ resolution (station > global) by introducing a platform channel bridge for device detection, a Dart service abstraction, and extending `EstadoEcualizador` to resolve through a 4-level hierarchy. Follows existing project patterns: ChangeNotifier state, SharedPreferences persistence via `ServicioEcualizador`, platform channels in `MainActivity.kt`, and constructor-injected fakes for testing. ## Architecture Decisions ### ADR-1: Platform Channel vs Package **Decision**: Custom platform channel `pluriwave/audio_devices` - Rationale: Project already has 3 platform channels. Pattern is established. BT MAC from `AudioManager.getDevices()` requires no extra permission. ### ADR-2: Device Service as Abstract Class **Decision**: Abstract `ServicioDispositivoAudio` with real + fake implementations - Rationale: Testable without platform channels. Matches existing service pattern. ### ADR-3: Composite Key for Matrix Persistence **Decision**: `"stationUuid:deviceId"` string key in flat map - Rationale: Simple serialization. ~80 bytes/entry, predictable SP size. ### ADR-4: Resolution Wiring Point **Decision**: `EstadoEcualizador` subscribes and resolves internally - Rationale: Single owner of resolution logic. Handler stays thin and testable. ### ADR-5: EQ Re-application After `_recrearPlayer()` **Decision**: State layer keeps `_presetActual` updated on device/station change - Rationale: Handler unchanged. State layer ensures `_presetActual` is always resolved. ### ADR-6: Feature Toggle Scope **Decision**: SP key `eq_multi_device_enabled_v1` read by `EstadoEcualizador` - Rationale: Zero behavioral change when off. Toggle at state layer fully isolates feature. ## Data Flow ``` Platform (Android/iOS) | AudioDeviceCallback / routeChangeNotification | EventChannel: pluriwave/audio_devices | ServicioDispositivoAudio (Stream) | EstadoEcualizador (4-level resolution: matrix > station > device > global) | aplicarPresetActivo(resolved) | ServicioAudio + ServicioEcualizador ``` ## File Changes 19 files modified or created: - `lib/modelos/dispositivo_audio.dart` (NEW) - `lib/servicios/servicio_dispositivo_audio.dart` (NEW) - `android/app/src/main/kotlin/.../MainActivity.kt` (MODIFIED) - `ios/Runner/AudioDevicesPlugin.swift` (NEW) - `ios/Runner/AppDelegate.swift` (MODIFIED) - `lib/servicios/servicio_ecualizador.dart` (MODIFIED) - `lib/estado/estado_ecualizador.dart` (MODIFIED) - `lib/servicios/servicio_export_import.dart` (MODIFIED) - `lib/pantallas/pantalla_ajustes.dart` (MODIFIED) - `lib/l10n/app_en.arb` (MODIFIED) - `lib/l10n/app_es.arb` (MODIFIED) - `test/` — 8 new/extended test files (See Engram observation #2187 for complete design document with all interfaces and contracts)