Four car reports, two root causes.
1. Local music vanished from the Android Auto menu. Self-inflicted, by
c1afe72 yesterday.
That commit moved registrarFuenteNavegacion above every await to keep a
headless engine from dying before it ran -- but left
registrarFuenteMusicaLocal below `await SharedPreferences.getInstance()`.
The root menu decides whether to offer "Música Local" with
`fuenteLocal != null && await fuenteLocal.hayCarpetaConfigurada()`, so
the car could now get a root response in the window between the two
registrations, find a null source, and be told there is no local music.
Android Auto caches the browse root, so it stayed missing for the whole
session. Before the reorder both registrations sat together after the
await and the window did not exist.
FuenteMusicaLocalAutoImpl never needed prefs to be CONSTRUCTED -- it
resolves them lazily per call, the same convention ServicioAlarmas uses
-- so it now registers beside the station source, above every await, and
the window is gone rather than narrowed.
2. PluriWave disappeared from the Auto pane mid-drive, the playback
screen sat frozen, and the equalizer was lost on every navigation
prompt. One cause for all three.
androidWillPauseWhenDucked: true made audio_session translate Android's
AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK into a full PAUSE. In a car that
fires constantly: every navigation instruction, every speed-camera
warning, every voice assistant. And a pause publishes playing:false,
which AudioService.setState turns into exitPlayingState() and, with
androidStopForegroundOnPause: true, into stopForeground(...). The
plugin's own doc for that flag says what follows: "while in this lower
priority state, the operating system will also be able to kill your
service at any time to reclaim resources". A killed service is a media
session that vanishes from the car pane -- and another media app takes
the slot.
Now the app ducks instead of pausing, so playing stays true and session,
notification and pane all survive an interruption; and the service stays
foreground even on a real pause, so a genuine one is not a death
sentence either. androidNotificationOngoing goes to false because the
plugin asserts it implies stopForegroundOnPause, and nothing is lost: a
foreground service already forces the notification to be ongoing.
A real, non-duckable focus loss (a phone call) still pauses and still
auto-resumes -- asserted, so the duck change cannot silently turn a call
into a station playing over it.
3. Previous/next on the car playback screen, for stations too.
skipToPrevious/skipToNext are now advertised unconditionally, since
Android Auto only draws those buttons when the app declares support.
They are no longer inert without a local queue: they walk the narrowest
list the current station belongs to -- favourites, then my stations,
then the catalogue -- wrapping at both ends, because a button that goes
dead at the end of a list reads as broken on a screen with no visible
list position. Matching is by uuid so a refreshed snapshot still
resolves, and a station in no list leaves playback untouched.
The equalizer toggle still fits alongside them: prev/next take their two
reserved slots and the equalizer claims the remaining custom-action room
because construirControlesTransporte places it before MediaControl.stop.
The phone notification is deliberately untouched: `controls` still gates
skip on an active queue, so nativeActions and
androidCompactActionIndices are byte-identical. Only systemActions
changed, and only the car reads those.
Tests: 1146 -> 1158.
97 lines
4.1 KiB
Dart
97 lines
4.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/main.dart';
|
|
|
|
/// Reported: with Android Auto connected, the car screen sometimes came up
|
|
/// completely BLACK, and opening the app on the phone then showed a
|
|
/// completely WHITE screen until it was force-killed and reopened. Never
|
|
/// without Android Auto.
|
|
///
|
|
/// Cause, verified in the plugin source:
|
|
/// `AudioServiceActivity.provideFlutterEngine` returns
|
|
/// `AudioServicePlugin.getFlutterEngine(context)`, which CREATES the engine
|
|
/// and runs `main()` the first time it is asked — and the car asks first,
|
|
/// when it binds the MediaBrowserService, so `main()` runs HEADLESS with no
|
|
/// Activity. `SystemChrome.setPreferredOrientations` travels the
|
|
/// `flutter/platform` channel, whose handler (`PlatformPlugin`) is installed
|
|
/// by the Activity. Headless, nobody answers it.
|
|
///
|
|
/// It was the FIRST `await` in `main()`, so that one call took the whole
|
|
/// startup with it: the Android Auto browse source below it was never
|
|
/// registered (`getChildren` had no source → black car screen) and `runApp`
|
|
/// was never reached. Opening the app then reused that same cached, already
|
|
/// dead engine → white screen. Only a force-kill, which disposes the cached
|
|
/// engine, recovered it — exactly the workaround that was reported.
|
|
///
|
|
/// The user's own guess was that portrait-only + a landscape phone made the
|
|
/// app "go a bit crazy". Right file, right trigger, different mechanism: a
|
|
/// broken layout renders overflow stripes or a red error box, never white.
|
|
/// White means nothing was ever built.
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
group('política de orientación', () {
|
|
test('un móvil se queda en vertical', () {
|
|
expect(orientacionesPara(411), const [DeviceOrientation.portraitUp]);
|
|
expect(orientacionesPara(599.9), const [DeviceOrientation.portraitUp]);
|
|
});
|
|
|
|
test('una tablet puede girar', () {
|
|
expect(orientacionesPara(600), DeviceOrientation.values);
|
|
expect(orientacionesPara(1280), DeviceOrientation.values);
|
|
});
|
|
});
|
|
|
|
group('nunca puede tumbar el arranque', () {
|
|
test('un fallo del canal de plataforma se traga, no se propaga', () async {
|
|
// This is the headless case: no PlatformPlugin, so the call fails.
|
|
// Before the fix this exception escaped out of main() and killed
|
|
// startup before runApp and before the Android Auto registration.
|
|
await expectLater(
|
|
aplicarPoliticaOrientacion(
|
|
aplicar:
|
|
(_) async =>
|
|
throw MissingPluginException(
|
|
'No implementation found for method '
|
|
'SystemChrome.setPreferredOrientations on channel '
|
|
'flutter/platform',
|
|
),
|
|
),
|
|
completes,
|
|
);
|
|
});
|
|
|
|
test('un canal que nunca responde tampoco puede colgar a quien llama, '
|
|
'porque main() ya no lo espera', () async {
|
|
// The structural half of the fix: main() calls this through
|
|
// `unawaited(...)`. Proven here by starting a call that never settles
|
|
// and showing the test still finishes -- if startup awaited it, this
|
|
// future is exactly what would hang forever on the headless engine.
|
|
var termino = false;
|
|
unawaited(
|
|
aplicarPoliticaOrientacion(
|
|
aplicar: (_) => Completer<void>().future,
|
|
).then((_) => termino = true),
|
|
);
|
|
|
|
await Future<void>.delayed(Duration.zero);
|
|
expect(termino, isFalse, reason: 'sigue pendiente, como debe');
|
|
// The point is that nothing above depends on it.
|
|
});
|
|
|
|
test('el camino feliz sigue aplicando la política de la pantalla', () {
|
|
// Guard against "fixed" by neutering: the swallow-everything wrapper
|
|
// must still actually apply something on a healthy engine.
|
|
late List<DeviceOrientation> aplicadas;
|
|
return aplicarPoliticaOrientacion(
|
|
aplicar: (o) async => aplicadas = o,
|
|
).then((_) {
|
|
expect(aplicadas, isNotEmpty);
|
|
expect(aplicadas, orientacionesPara(800 / 1));
|
|
});
|
|
});
|
|
});
|
|
}
|