fix(alarmas,auto): guard the native snooze anchor, surface the EQ in the car
Three reported issues, two fixed and one instrumented. 1. Posponer left the alarm snoozed ~1444 minutes (24h04m). Traced end to end in Kotlin. onAlarmFired runs from the receiver BEFORE the ringing notification exists, and persists snoozeOriginMillis = null plus a triggerAtMillis already advanced to TOMORROW by computeNextTriggerMillis. snooze() then anchored on `spec.snoozeOriginMillis ?: spec.triggerAtMillis` and picked up tomorrow. The existing clamp could not catch it: it only rescues anchors in the PAST, so an anchor +24h out sails through. The countdown text is honest -- ceilMinutes(snoozeUntil - now) over Dart's own template -- the corrupt value is snoozeUntil. With N=5 and a tap at T+1min the arithmetic lands on 1444 exactly. This is the defecta9da855fixed on the Dart side with EstadoAlarmas._ocurrenciaSonando, after9c7cf4ehad fixed only one of two adjacent callers. The native lane never got that guard. Now it has anchorOccurrenceMillis, with a per-surface forward allowance: none for snooze() (the ringing notification closes an occurrence that has arrived) and a full PRE_NOTICE_MILLIS for postponeNext() (the pre-notice notification's occurrence legitimately has not). No Kotlin test source set exists in this project, so CI cannot verify this and no Dart test sees it (all use FakePuertoAlarmasAndroid). Verified by reading; needs an on-device pass. 2. The equalizer toggle stayed invisible on the Android Auto playback screen even on v1.2.14+136, which does contain it. On Android 13+ createCustomAction (AudioService.java:466-469) turns MediaControl.stop into a custom action too, so the car receives TWO in list order and stop was first -- a head unit exposing one custom-action slot shows that and buries the rest in an overflow menu. The equalizer now precedes stop and wins the slot; it is the better occupant, since the car has its own path to stop playback while the equalizer is reachable no other way from that screen. No platform detection needed, and the phone notification is untouched on every API level: nativeActions comes out [prev?, play/pause, stop, next?] below 13 and [prev?, play/pause, next?] on 13+, exactly as before. Both are now asserted. The list also moves to a public construirControlesTransporte. The guard test used to re-declare its own copy of the shape, so it stayed green while asserting a list lib/ no longer produced. It calls the real builder now. 3. Android Auto shows PLAY while a station is audibly playing: NOT fixed, deliberately. The car takes that icon from PlaybackStateCompat.getState() (AudioService.java:601-611), not from controls -- so none of the recent controls work can be the cause. All eight playbackState.add sites were audited and none publishes playing:false while audio runs, which leaves no traced input to fix. A proposed resync off bufferedPositionStream was rejected: it can publish a spurious idle, which AudioService.java:565-567 turns into stop() and tears down the foreground service -- the exact regressionabc6b47fixed, on the highest-frequency listener in the handler. Added instead a change-gated trace of the state actually published, with eqDisponible alongside it (that flag gates the equalizer action and is otherwise unobservable). One car session with `adb logcat -s ServicioAudio` settles both this and issue 2. Tests: 1124 -> 1127.
This commit is contained in:
@@ -137,55 +137,114 @@ void main() {
|
||||
});
|
||||
|
||||
group('transport row keeps its shape', () {
|
||||
/// Mirrors `_controlesTransporte`'s construction. Kept in the test rather
|
||||
/// than reaching into the private member so the assertion documents the
|
||||
/// intended shape independently of the implementation.
|
||||
// Calls the REAL builder, never a copy of it. This group used to
|
||||
// re-declare the list inline, which meant it stayed green while asserting
|
||||
// a shape lib/ no longer produced — a guard blind to the thing it guards.
|
||||
List<MediaControl> transporte({
|
||||
required bool colaActiva,
|
||||
required bool playing,
|
||||
required bool eqDisponible,
|
||||
}) => [
|
||||
if (colaActiva) MediaControl.skipToPrevious,
|
||||
if (playing) MediaControl.pause else MediaControl.play,
|
||||
MediaControl.stop,
|
||||
if (colaActiva) MediaControl.skipToNext,
|
||||
...controlesEcualizadorPersonalizados(
|
||||
disponible: eqDisponible,
|
||||
activo: true,
|
||||
l10n: lookupAppLocalizations(const Locale('es')),
|
||||
),
|
||||
];
|
||||
}) => construirControlesTransporte(
|
||||
colaActiva: colaActiva,
|
||||
playing: playing,
|
||||
eqDisponible: eqDisponible,
|
||||
eqActivo: true,
|
||||
l10n: lookupAppLocalizations(const Locale('es')),
|
||||
);
|
||||
|
||||
/// What `AudioService.setState` (AudioService.java:513-521) would route to
|
||||
/// `nativeActions` — the ONLY list the phone's media notification is built
|
||||
/// from, and the list `androidCompactActionIndices` indexes into.
|
||||
///
|
||||
/// On Android 13+ `MediaControl.stop` also becomes a custom action
|
||||
/// (:466-469), so pass [sdk33] to model that split.
|
||||
List<MediaControl> nativas(
|
||||
List<MediaControl> controles, {
|
||||
required bool sdk33,
|
||||
}) =>
|
||||
controles
|
||||
.where((c) => c.customAction == null)
|
||||
.where((c) => !(sdk33 && c == MediaControl.stop))
|
||||
.toList();
|
||||
|
||||
for (final colaActiva in [false, true]) {
|
||||
for (final playing in [false, true]) {
|
||||
test('compact index still points at play/pause '
|
||||
test('compact index still points at play/pause on BOTH API levels '
|
||||
'(colaActiva=$colaActiva playing=$playing)', () {
|
||||
final controles = transporte(
|
||||
colaActiva: colaActiva,
|
||||
playing: playing,
|
||||
eqDisponible: true,
|
||||
);
|
||||
|
||||
// androidCompactActionIndices is `[colaActiva ? 1 : 0]`. The EQ
|
||||
// action is APPENDED, so the native transport buttons keep
|
||||
// indices 0-3 and the collapsed shade still shows play/pause.
|
||||
final indiceCompacto = colaActiva ? 1 : 0;
|
||||
expect(controles.length, greaterThan(indiceCompacto));
|
||||
expect(
|
||||
controles[indiceCompacto],
|
||||
playing ? MediaControl.pause : MediaControl.play,
|
||||
);
|
||||
|
||||
// The custom action must never sit among the transport buttons:
|
||||
// `nativeActions` and `customActions` are built by walking this
|
||||
// list in order, so an interleaved custom action would renumber
|
||||
// the notification's own actions.
|
||||
final indiceCustom = controles.indexWhere(
|
||||
(c) => c.customAction != null,
|
||||
);
|
||||
expect(indiceCustom, controles.length - 1);
|
||||
for (final sdk33 in [false, true]) {
|
||||
final row = nativas(controles, sdk33: sdk33);
|
||||
expect(row.length, greaterThan(indiceCompacto));
|
||||
expect(
|
||||
row[indiceCompacto],
|
||||
playing ? MediaControl.pause : MediaControl.play,
|
||||
reason:
|
||||
'androidCompactActionIndices is [colaActiva ? 1 : 0] and it '
|
||||
'indexes nativeActions (AudioService.java:613-618, :637-639)',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test('the equalizer comes BEFORE stop, so it wins the first custom-action '
|
||||
'slot on the car', () {
|
||||
// Reported on v1.2.14+136: the toggle was in the binary but invisible on
|
||||
// the head unit. On Android 13+ stop is ALSO a custom action, and it used
|
||||
// to be first — a unit exposing one slot showed stop and buried the
|
||||
// equalizer in an overflow menu.
|
||||
final controles = transporte(
|
||||
colaActiva: true,
|
||||
playing: true,
|
||||
eqDisponible: true,
|
||||
);
|
||||
|
||||
final custom = controles.where(
|
||||
(c) => c.customAction != null || c == MediaControl.stop,
|
||||
);
|
||||
expect(
|
||||
custom.first.customAction,
|
||||
isNotNull,
|
||||
reason: 'on Android 13+ this is the order the car receives them in',
|
||||
);
|
||||
});
|
||||
|
||||
test('reordering did NOT disturb the notification row', () {
|
||||
// The whole safety argument for the swap: nativeActions must come out
|
||||
// [prev?, play/pause, stop, next?] on <13 and [prev?, play/pause, next?]
|
||||
// on 13+, exactly as before the equalizer moved.
|
||||
final controles = transporte(
|
||||
colaActiva: true,
|
||||
playing: true,
|
||||
eqDisponible: true,
|
||||
);
|
||||
|
||||
expect(nativas(controles, sdk33: false), [
|
||||
MediaControl.skipToPrevious,
|
||||
MediaControl.pause,
|
||||
MediaControl.stop,
|
||||
MediaControl.skipToNext,
|
||||
]);
|
||||
expect(nativas(controles, sdk33: true), [
|
||||
MediaControl.skipToPrevious,
|
||||
MediaControl.pause,
|
||||
MediaControl.skipToNext,
|
||||
]);
|
||||
});
|
||||
|
||||
test('a device with no equalizer gets the exact pre-existing list', () {
|
||||
expect(transporte(colaActiva: true, playing: true, eqDisponible: false), [
|
||||
MediaControl.skipToPrevious,
|
||||
MediaControl.pause,
|
||||
MediaControl.stop,
|
||||
MediaControl.skipToNext,
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user