103 Commits
Author SHA1 Message Date
ShanaiaBot d7366bbf99 chore: bump version to 1.3.3+162 [ci skip] 2026-09-06 00:11:34 +02:00
FreeTLab b1bf289e0d fix(eq): entregar los decibelios que pide el usuario, sin estirarlos
Build & Deploy PluriWave / Análisis de código (push) Successful in 29s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m56s
La app promete decibelios en cuatro sitios y no los entregaba en ninguno. El
slider abarca un +/-12 fijo, escribe el numero con su unidad debajo de cada
banda, y `equalizerBandValue` le dice literalmente "decibelios" a TalkBack. El
modelo documenta las bandas como dB y los presets de fabrica estan escritos en
dB. just_audio documenta `setGain` en decibelios y multiplica por 1000 para
llegar a milibelios sin normalizar nada: `minDecibels`/`maxDecibels` son la
CAPACIDAD del dispositivo, no una escala a la que normalizar.

Pese a eso, la ganancia se estiraba por `maxDecibels/12`. Un +6 dB llegaba como
+10 en un movil de rango ancho.

El estiramiento nunca fue una decision de diseño

Antes de a9202c6 el codigo era `setGain(preset.bandas[i])`, decibelios
literales. Ese commit metio la normalizacion sin docstring, sin test y sin nota
de diseño, y traia un fallo: 0 dB caia en el punto medio del rango, asi que un
preset PLANO realzaba. 3449e2c corrigio exactamente eso y nada mas -- su propio
mensaje dice que el objetivo era "0 dB es siempre 0" -- heredando el
estiramiento sin discutirlo. No hay ADR, spec ni comentario que lo justifique.

Lo que de verdad rompia: la portabilidad

Lo que se persiste y se exporta son los dB del usuario, sin escalar; el escalado
ocurre solo al escribir en el efecto nativo. Asi que el mismo backup suena
distinto en cada telefono, y la interfaz informa de una restauracion perfecta
mientras el audio no lo es. Peor con el rango asimetrico habitual de Android
([-12, +19]): los realces se multiplican por 1.58 y los cortes por 1.0, de modo
que el preset no solo sube de nivel, CAMBIA DE FORMA. Jazz [3, -1, -1.5, 2, 4]
se entregaba como [4.75, -1, -1.5, 3.17, 6.33]. Con presets por dispositivo, el
mismo preset se deformaba distinto en el altavoz y en el Bluetooth.

No es un clamp a secas

`db.clamp(minDecibels, maxDecibels)` habria reintroducido el fallo de 3449e2c:
en un dispositivo que reporte [+3, +19], el cero se convierte en +3 y el preset
plano vuelve a realzar. La ventana se fuerza a contener el cero, asi que se
conservan todas las invariantes ganadas -- 0 siempre es 0, el signo nunca se
invierte, el resultado nunca escapa del rango nativo, un dispositivo sin margen
en un lado no puede realzar por ese lado -- y solo desaparece el estiramiento.

Que se oye distinto: en un movil de +/-12 dB, identico a hoy. En uno de rango
ancho los realces bajan, hasta un 40% menos en dB en uno de +/-20. Los cortes
apenas se mueven, porque la forma habitual es [-12, +N] y el lado negativo ya
iba practicamente 1:1. A cambio, los seis presets de fabrica suenan por fin
igual en cualquier telefono.

Ningun preset guardado necesita migracion: lo almacenado siempre fueron los dB
del usuario.

Suite completa: 1534 pasan, 2 omitidos. flutter analyze mantiene los 5 avisos
preexistentes.
2026-09-06 00:08:09 +02:00
FreeTLab 8fc3d99fbd fix: el coche recuerda la ultima emisora y deja de publicar una sesion fantasma
Tres defectos preexistentes alrededor de la reanudacion en Android Auto. Ninguno
es una regresion: el consumidor (la raiz `recent`) se añadio en septiembre y es
lo que dejo el hueco a la vista.

La ultima emisora solo la escribia el telefono

La clave `ultima_emisora_v1` tenia como unico escritor a
`EstadoRadio._persistirUltimaEmisora`, y `EstadoRadio` solo existe si hay arbol
de widgets. El motor que arranca Android Auto es headless de verdad, asi que una
sesion que ocurriera solo en el coche jamas actualizaba la clave y al reconectar
se ofrecia la emisora de la ultima vez que se uso el movil.

El handler recibe ahora sus puertos de lectura y escritura, con la misma forma
que los del ecualizador y el contexto de salto, y escribe desde `_cambiarFuente`:
el cuello de botella por el que pasan todas las rutas -- telefono, toque en el
coche, voz, saltos, avance de cola y la propia reanudacion.

Se ELIMINA el escritor del telefono en vez de sumar un segundo. Dos escritores
independientes de la misma clave acaban divergiendo siempre; es exactamente lo
que ya costo varias rondas con el flag del ecualizador.

Las pistas locales quedan excluidas: un `content://` guardado como ultima
emisora seria una fila de reanudacion que no resuelve a nada.

play() sin fuente levantaba un servicio en primer plano vacio

just_audio publica `playing:true` antes de comprobar si hay fuente, asi que un
`play()` en frio no tocaba la plataforma pero si emitia ese estado sobre
`processingState: idle`. audio_service entraba en estado de reproduccion
mientras el estado nativo seguia en NONE: notificacion con boton de pausa, cero
audio, sin titulo ni caratula, y un Future que no se completaba nunca. El coche
enruta su tecla de play directamente ahi.

Ahora `play()` sin fuente abierta restaura la ultima emisora por la ruta normal,
y si no hay nada que restaurar no toca el reproductor ni publica nada.

En frio no habia metadatos que enseñar

El unico `mediaItem.add` util vivia dentro de `_cambiarFuente`, asi que en un
motor recien arrancado el lado nativo nunca recibia metadatos. Se siembra el
`mediaItem` de la emisora persistida sin cargar ni reproducir nada, con guarda
antes y despues de la lectura de disco para no pisar una emisora ya sonando.

`getMediaItem` resolvia solo contra el universo completo -- vacio en el motor del
coche -- mientras `porUuid` si caia en las destacadas. El coche podia navegar una
emisora destacada y luego no resolver su ficha. Ambos usan ahora la misma ruta.

Suite completa: 1529 pasan, 2 omitidos. flutter analyze mantiene los 5 avisos
preexistentes.
2026-09-06 00:08:09 +02:00
FreeTLab a0fae57219 fix: el ecualizador del coche aplica el preset real y en el orden correcto
Reportado desde el uso real: desde el movil el ecualizador va bien, pero el
boton de Android Auto a veces no hace nada y a veces suena como si se aplicara
una doble ecualizacion.

El preset del handler nunca se sembraba desde disco

`_presetActual` arrancaba en `flat` a fuego. registrarHandler sembraba el flag
de encendido pero no el preset, asi que en un motor donde la interfaz del
telefono nunca corrio -- el que arranca Android Auto -- el toggle del coche
aplicaba `flat`, o lo que hubiera quedado, en vez del preset del usuario. Es la
misma clase de fallo que ya se corrigio para el flag: aquel recibio un puerto
headless y el preset se quedo fuera. Ahora tiene el suyo, con la misma forma:
opcional, el fallo se traza y cae al valor por defecto, nunca propaga.

La siembra respeta un preset ya elegido por EstadoEcualizador, que es mas rico
que la clave principal, para que la lectura de disco en vuelo no lo pise.

El efecto se habilitaba antes de escribir las ganancias

La ruta era setEnabled -> setEnabled -> ganancias: `aplicarPreset` volvia a
llamar a setEnabled por su cuenta. Entre la habilitacion y la escritura sonaban
las ganancias anteriores, y ese hueco es lo que se percibia como doble
ecualizacion. Ahora una funcion pura devuelve los pasos en orden y ambas rutas
la recorren: ganancias primero, habilitacion despues.

Las ganancias NO se resetean al apagar, y es deliberado: setEnabled(false)
puentea el efecto sin liberarlo ni limpiar sus niveles, y la ruta de encendido
los reescribe enteros antes de habilitar, asi que no queda ninguna ventana de
ganancia rancia que un reset pudiera cerrar.

El boton desaparecia en cada cambio de emisora

`_recrearPlayer` bajaba `_eqDisponible` sin republicar controles, asi que cada
cambio de emisora emitia al menos un estado sin la accion de EQ. Peor: las
llamadas nativas estan detras de ese flag, de modo que un toggle en esa ventana
cambiaba el icono sin tocar el audio. Ahora el unico que lo escribe es
`_activarEcualizador`.

Mantenerlo optimista exigia quitar de la ruta del toggle el `await
_eq.parameters`, que es un Completer que solo se completa cuando el reproductor
se engancha: esperarlo dejaba el boton pendiente durante toda la carga, y para
siempre si la carga fallaba. Se cachean los parametros al activarse.

Los fallos nativos dejan de ser mudos

El `catch (_) {}` ocultaba que la llamada nativa habia fallado y dejaba el icono
afirmando un estado que el audio no tenia. Ahora se traza, y un fallo al
habilitar revierte el flag, republica los controles y no persiste.

EstadoEcualizador adopta lo que el motor acepto en vez de asumir que su peticion
prospero: sin eso, el telefono escribia en disco un valor que el handler acababa
de rechazar, reabriendo la divergencia que el dueño unico habia cerrado.

Suite completa: 1515 pasan, 2 omitidos. flutter analyze mantiene los 5 avisos
preexistentes.
2026-09-06 00:08:09 +02:00
ShanaiaBot 405dc18430 chore: bump version to 1.3.3+161 [ci skip] 2026-09-04 14:31:35 +02:00
FreeTLab bcdf3d55c4 ci: publicar los builds de main donde el portal sabe leerlos
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m20s
Desde el 29-08 ningun build de main volvio a aparecer en builds.freetimelab.es,
y nada avisaba: el job salia verde porque el scp subia correctamente, solo que a
una ruta que el indexador no lee.

El portal indexa DOS niveles, <app>/<version>/<ficheros>. La solucion anterior
metia la rama como TERCER nivel (pluriwave/main/v1.3.3/), asi que sus ficheros
quedaban fuera del indice: 39 versiones listadas, ninguna con "main", ninguna
con los codigos 158, 159 ni 160. Encima el echo del propio paso tenia "pluriwave"
escrito a fuego y anunciaba la carpeta antigua, congelada desde el +157, que es
justo donde se miraba al no encontrar nada.

Ahora la rama va en el NOMBRE DE LA APP, que es lo que el portal si entiende.
PRO conserva la entrada limpia "pluriwave" y main tiene la suya, igual que ya
conviven radar-foral y radar-foral-android. Se cumple el objetivo original -- que
el build de desarrollo no aparezca como ultima version de release -- sin romper
el indexado. La ruta impresa se deriva de la misma variable, para que no puedan
volver a desincronizarse.

Se alinea tambien el arreglo del secreto de Google Play que ya esta en PRO: el
paso se omite con un aviso en vez de hacer `exit 1`, y el mensaje de Telegram
deja de afirmar que se publico algo que no se publico. main nunca ejecuta esos
pasos, pero mantener un unico workflow evita conflictos en cada trasvase entre
ramas.
2026-09-04 14:30:59 +02:00
ShanaiaBot 02609ec82c chore: bump version to 1.3.3+160 [ci skip] 2026-09-02 22:59:19 +02:00
FreeTLab 5f35ab7d6a feat: restaurar los grupos de favoritos al importar y recordar la lista del coche
Build & Deploy PluriWave / Análisis de código (push) Successful in 36s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 3m27s
Dos fallos reportados desde el uso real en el coche.

Los grupos de favoritos no volvian al importar

La exportacion nunca estuvo rota: los grupos viajaban desde siempre y la
asignacion de cada emisora va dentro de cada favorito como grupo_id. El fallo
estaba solo al importar. La restauracion reutilizaba ServicioFavoritos.agregar,
que fuerza "sin asignar" a proposito, porque una emisora recien marcada como
favorita no tiene grupo. Correcto para esa ruta, destructivo como primitiva de
restauracion: los grupos volvian vacios y todo aterrizaba en Sin asignar. Se
separa la ruta de restaurar, que respeta el grupo_id del backup y su orden.

Ningun test lo detectaba porque el doble de pruebas era infiel: el fake
conservaba el grupo que la implementacion real destruia, y no tenia
restaurarGrupo, asi que esa ruta estaba sin cubrir. Los tests existentes lo
esquivaban pasando siempre una lista de grupos vacia. Se corrige el doble.

No hace falta subir la version del formato: el envoltorio ya llevaba todo.

El coche perdia la lista al reconectar

El contexto de reproduccion vivia solo en memoria, y el motor que arranca
Android Auto es un proceso nuevo sin interfaz ni EstadoRadio, asi que al
reconectar se reproducia la ultima emisora sin saber a que lista pertenecia y
siguiente/anterior no hacian nada hasta entrar a favoritos a mano. Ahora se
persiste el TIPO de contexto y, cuando aplica, el id del grupo, y se resuelve
contra las listas vivas en cada salto: si el grupo cambia de contenido entre
sesiones, el coche ve lo actual y no una foto vieja.

Cadena de repliegue, decidida por el propietario:
  grupo vivo con la emisora dentro  -> se recorre el grupo
  grupo vivo sin la emisora         -> se permanece en el grupo, primera
  grupo vivo pero vacio             -> se ensancha a favoritos
  grupo borrado                     -> favoritos
  sin favoritos                     -> comportamiento actual

Honrar un grupo de una sola emisora exigia levantar dos barreras, no una:
el resolutor y el propio _saltarEmisora, que se negaba a nombrar un grupo con
menos de dos miembros. emisoraVecina queda intacta: su contrato de no saltar a
ciegas es deliberado y se usa desde mas sitios, asi que el caso de "la emisora
se salio del grupo" se trata en el flujo del salto.

La puerta de entitlement no cambia: un conductor sin premium sigue recorriendo
solo el conjunto gratuito, y un contexto congelado mientras pagaba se descarta
en vez de recorrerse.

Suite completa: 1501 pasan, 2 omitidos. flutter analyze mantiene los 5 avisos
preexistentes.
2026-09-02 22:56:10 +02:00
FreeTLab 241f81e535 fix: cumplir las guias de calidad de Android Auto y localizar el arbol del coche
Google Play devolvio "Approved with Issues" en el codigo 157: "clicking on
stop button makes the entire app useless", citado contra las Android for Cars
App Quality Guidelines. La causa no era el boton de parar.

Maquina de estados del transporte

_cambiarFuente publicaba mediaItem y loading ANTES de su primer await y solo
comprobaba su revision despues de que _recrearPlayer retornase. Los cambios de
fuente se encolan incrementando la revision al encolar, no al ejecutar, asi
que tocar una emisora, tocar otra antes de que cargue y pulsar Stop dejaba que
las entradas obsoletas reescribieran loading sobre el idle que stop() acababa
de publicar. Estado final: loading para siempre sobre una sesion que
audio_service ya habia desactivado. Ahora la guarda de revision es la primera
sentencia del metodo.

pause() no invalidaba una carga en vuelo, asi que la emisora arrancaba igual
despues de pulsar pausa; se revalida la intencion antes de llamar a play().
Se anade un suelo de estado que cierra cualquier loading o buffering sin carga
viva, exento cuando el reproductor ya entrego audio y solo esta rebufferando,
para no convertir un tunel en un error. El presupuesto hasta el primer mensaje
baja a menos de diez segundos y los reintentos ya no borran el mensaje visible.

Tier gratuito en el coche

El arbol devolvia una unica fila no reproducible para cualquier carpeta cuando
no habia premium, y un revisor con instalacion limpia siempre es tier
gratuito. Ademas skipToNext, skipToPrevious, playFromSearch y playFromMediaId
retornaban en silencio. La raiz gratuita pasa a ofrecer una sola carpeta con
emisoras reales y reproducibles, compiladas en el binario para que existan en
frio, y la puerta de entitlement acota contenido en vez de bloquear acciones.
Se elimina la fila "Funcion Premium". Una consulta de voz vacia arranca la
ultima emisora, que fallaba tambien a los clientes de pago.

Localizacion

El locale del handler solo lo fijaba un widget que el motor headless nunca
construye, asi que todo error del coche salia en castellano. Se resuelve desde
el locale de plataforma. Se traducen las once etiquetas del arbol que estaban
a fuego y se retira la convencion que lo justificaba. Un test nuevo falla si
vuelve a aparecer texto visible fuera del sistema de traduccion.

Suite completa: 1455 pasan, 2 omitidos. Los mecanismos se verificaron por
mutacion: borrar cada uno pone la suite en rojo. flutter analyze mantiene los
5 avisos preexistentes.
2026-09-02 22:56:10 +02:00
ShanaiaBot a82dcc9c1b chore: bump version to 1.3.3+159 [ci skip] 2026-08-31 14:38:18 +02:00
FreeTLab 3449e2cb79 fix: corregir ecualizador desincronizado, musica local en Android Auto y bloqueo del paywall
Build & Deploy PluriWave / Análisis de código (push) Successful in 27s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 3m23s
Tres fallos reportados en uso real, con sus causas raiz verificadas en codigo.

1. Ecualizador: el estado no tenia dueño unico

El handler arrancaba con `_ecualizadorActivo = true` a fuego. El valor
persistido solo llegaba por EstadoEcualizador.cargarPersistido(), alcanzable
unicamente desde el arbol de widgets, que un arranque headless de Android Auto
nunca construye. Resultado: el coche reproducia con el EQ forzado a ON mientras
disco e interfaz decian OFF.

Ahora registrarHandler siembra el flag desde disco en todos los motores y
setEcualizadorActivo persiste por su cuenta, asi que un toggle desde el coche o
la notificacion sobrevive sin EstadoEcualizador. _resincronizarConHandler pasa
a ser adopcion pura de interfaz.

Ademas mapearGananciaNativa enviaba 0 dB al punto MEDIO del rango nativo. Con
un getBandLevelRange() asimetrico, un preset plano metia varios dB de boost
real: la causa del "suena muy alto con el boton apagado". Reescrito para
escalar cada lado contra su propio extremo, de modo que 0 dB es siempre 0.

El dispatch de customAction no tenia ningun test. Se extrae decidirToggleEq y
se cubre contra el handler real. El efecto nativo se re-asierta al reactivarse
el reproductor, porque AudioEffect.setEnabled de just_audio es un no-op
mientras la plataforma esta desacoplada.

2. Musica Local no aparecia en el arbol de Android Auto

hayCarpetaConfigurada() consultaba MethodChannel('pluriwave/file_actions'),
registrado solo en MainActivity.configureFlutterEngine. Sin Activity no hay
handler, invokeMethod lanza MissingPluginException y el catch la confundia con
"permiso revocado", omitiendo el nodo. No dependia del entitlement.

La logica SAF sale a packages/pluriwave_file_actions, un paquete plugin local.
El motor headless que crea audio_service ejecuta GeneratedPluginRegistrant en
su constructor, asi que el canal queda registrado en ambos motores. Repuntar el
manifest a una subclase de AudioService no era viable: AudioServicePlugin
enlaza por ComponentName explicito y la app perderia el audio.

EstadoCarpetaLocal de tres valores separa "sin carpeta" de "canal no
disponible"; la raiz decide por la URI persistida y el subarbol muestra un item
explicativo en vez de una carpeta vacia. La invalidacion del arbol cacheado se
dispara al reanudar con el coche ya suscrito; el guardia anterior miraba
View.maybeOf, que bajo runApp siempre existe, por lo que se gastaba en el
arranque headless y no volvia a dispararse.

3. El paywall bloqueaba las compras

restorePurchases() de in_app_purchase_android emite siempre, y con lista vacia
si no hay nada que restaurar. El `if (compras.isEmpty) return;` se la tragaba,
noEncontrada nunca se emitia y la rama que limpia _compraEnCurso estaba muerta
en produccion. Como comprar y restaurar comparten ese flag, un usuario sin
compras que pulsaba restaurar se quedaba sin poder comprar.

Suite completa: 1366 pasan, 2 omitidos. 17 tests nuevos, todos nacidos rojos y
verificados por mutacion. flutter analyze mantiene los 5 avisos preexistentes.
2026-08-31 14:34:49 +02:00
ShanaiaBot 10bb017f4c chore: bump version to 1.3.3+158 [ci skip] 2026-08-29 11:00:00 +02:00
FreeTLab a99df5d055 ci: let PRO own the version name and split artifacts by branch [version set]
Build & Deploy PluriWave / Análisis de código (push) Successful in 28s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m44s
Three related fixes to the release plumbing:

- Only PRO bumps the semver now. main was bumping its patch on every push,
  so it raced permanently ahead of the branch that actually ships (main hit
  1.3.3 while PRO sat at 1.3.0), buried release artifacts under a dev branch
  on the portal, and made every main<->PRO merge conflict on pubspec.yaml.
  The build number still advances on every branch, since Play requires it to
  be monotonic across the whole app.

- The [version set] marker is now searched across every commit the push
  introduced, not just the tip. A plain 'git pull' inserts a merge commit
  with no marker, which silently dropped a pinned name and turned 1.3.0
  into 1.3.1.

- Artifacts land in a per-branch folder so the portal stops interleaving
  development and release builds.
2026-08-29 10:59:20 +02:00
ShanaiaBot ab66f4985c chore: bump version to 1.3.3+157 [ci skip] 2026-08-28 23:53:24 +02:00
FreeTLab d61c62540a ci: name build artifacts by branch and version code [version set]
Build & Deploy PluriWave / Análisis de código (push) Successful in 23s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m57s
Every build of a given semver was published as `pluriwave-v1.3.0.aab` into
the same folder, so main and PRO overwrote each other and three different
builds became indistinguishable once downloaded — the browser saves them as
"(1)", "(2)" and the version code is only visible by unzipping the bundle.

That cost two rejected uploads to Play Console for reusing a version code.
Artifacts are now `pluriwave-<branch>-v<semver>+<build>.<ext>", which
identifies itself weeks later and outside this repo.
2026-08-28 23:52:41 +02:00
ShanaiaBot 25d5841d57 chore: bump version to 1.3.3+156 [ci skip] 2026-08-28 23:38:07 +02:00
FreeTLab 663fed5f41 merge: alarm-import recovery, dismissible paywall and complete config export
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 2m41s
Three fixes that all came out of on-device testing:
- e57f7bb restores alarms after a backup import. The import wrote the JSON
  to prefs but EstadoAlarmas never re-read it, so imported alarms were
  invisible, were overwritten by the next edit, and were never scheduled
  natively — they would not have rung.
- a2bed18 makes the premium sheet dismissible (close button, 'not now',
  back gesture) and replaces the bare title with the five concrete things
  the purchase unlocks. A purchase sheet with no way out is a Play policy
  risk, not just bad UX.
- 4ca2813 closes the last export gap: the equalizer on/off toggle now
  travels with the backup (schema v4, additive; an old backup without the
  field leaves the current toggle untouched).
2026-08-28 23:35:37 +02:00
FreeTLab 4ca2813267 feat(ecualizador): include equalizer on/off toggle in export/import
The backup envelope carried favorites, EQ presets, alarms and the
multi-device toggle but not EstadoEcualizador's own on/off flag, so
restoring a backup on another device silently kept that device's
existing toggle state instead of the source device's.

Bumps the backup schema to v4 (additive over v3): the flag is only
written when explicitly provided, so old exports stay at v2/v3.
Importing an old backup without the field leaves the current toggle
untouched rather than defaulting it. Applying the imported value
reuses EstadoEcualizador.cambiarActivo so it persists and pushes to
the live audio engine exactly like a manual toggle.
2026-08-28 23:07:01 +02:00
FreeTLab a2bed18937 fix(paywall): add dismiss controls and honest premium copy
The premium sheet had no close affordance or way to defer, and its
copy only said "Función Premium" without stating what it unlocks.
Adds a header close (X) button and a "not now" secondary action so
dismissal is never harder than purchasing, and replaces the bare
title with a concrete, honest breakdown of the 5 things premium
unlocks (no ads, Android Auto, station recording, alarm vacation
ranges, unlimited alarms) plus the one-time-purchase framing. The
phone equalizer is never listed, since it stays free for everyone.
New l10n keys added to all 13 locales.
2026-08-28 22:47:53 +02:00
FreeTLab e57f7bb17b fix(alarmas): reload and re-sync alarms after backup import
Importing a backup wrote the alarm/vacation/exception block straight to
SharedPreferences but never told EstadoAlarmas about it, so the UI kept
showing the pre-import alarms, a later edit could persist that stale
state back over the imported one, and imported alarms were never
(re)scheduled with the Android native layer. The backup screen now
calls EstadoAlarmas.cargarPersistidasSinRecalcular() followed by
refrescarProgramacion() after a successful import, extracted into a
directly-testable aplicarImportacionConfig() function.
2026-08-28 22:47:38 +02:00
ShanaiaBot fdddd95199 chore: bump version to 1.3.2+155 [ci skip] 2026-08-28 20:07:12 +02:00
FreeTLab 1bfd5a2348 Merge branch 'main' of https://git.freetimelab.es/FreeTLab/pluriwave
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m54s
2026-08-28 20:06:20 +02:00
FreeTLab 4ea5d2056c test(alarmas): anchor the vacation pill test on a relative future range
The test hardcoded 4-18 August 2026, which was in the future when it was
written and is now in the past. The pill only renders for the active or
next range, so the assertion started failing purely because the calendar
moved on — the production code was never wrong.

Anchor the range on next month (days 4-18, so it never straddles a month
boundary) and assert against rangoFechasCorto, the same pure formatter the
widget uses, so the test checks that the pill is rendered rather than
restating the formatter's own output.
2026-08-28 20:06:10 +02:00
ShanaiaBot b5940b2758 chore: bump version to 1.3.1+154 [ci skip] 2026-08-28 20:02:32 +02:00
FreeTLab 9efa6d8937 merge: bring the freemium/IAP release line into main
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m13s
main had drifted behind PRO by the whole 1.3.0 line: the freemium/IAP
feature, the code-review fixes, the real AdMob ids, the equalizer
cross-surface resync and the closed-testing ad switch all shipped through
PRO only. This reconciles main so day-to-day work no longer branches from
a stale base.

# Conflicts:
#	pubspec.yaml
2026-08-28 19:59:12 +02:00
FreeTLab 55fe50d07d merge: equalizer cross-surface sync + test ads for the closed-testing phase [version set]
Build & Deploy PluriWave / Análisis de código (push) Successful in 24s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 3m9s
Brings in two independent fixes that both need to reach testers:
- e9f47d4 resyncs EstadoEcualizador with car/notification-initiated changes
  and closes the persistence gap that lost them on restart.
- 2e15d05 forces Google test ad units in release builds while
  usarAnunciosDePruebaEnRelease is true, so no tester can generate invalid
  traffic against the AdMob account during closed testing.

[version set] keeps the 1.3.0 name; CI advances the build number.
2026-08-28 19:56:26 +02:00
FreeTLab 2e15d05431 fix(ads): force test ad units in release during closed testing
Closed-testing human testers cannot be registered as AdMob test
devices, so release builds serving real ad units risked invalid
traffic against an AdMob account that currently earns essentially
nothing. Add usarAnunciosDePruebaEnRelease, a single boolean switch
defaulted to true, that keeps bannerAdUnitId/interstitialAdUnitId on
Google's official test ids even in kReleaseMode. Flipping it to false
is the only change needed to go live. AndroidManifest's AdMob
application id is untouched, as it only initializes the SDK.
2026-08-28 19:49:12 +02:00
FreeTLab e9f47d47c2 fix(eq): resync EstadoEcualizador with car/notification-initiated changes
A toggle from the Android Auto notification or a preset picked from the
car's EQ folder mutated PluriWaveAudioHandler state directly, leaving
EstadoEcualizador (and therefore the phone UI) unaware and never
persisting the change, so it was lost on the next app restart.

Forward the handler's ecualizadorActivo flag through ServicioAudio and,
mirroring EstadoRadio's existing playFromMediaId resync, diff it plus
presetActual against the cached values on every estadoStream tick,
adopting and persisting a divergence via ServicioEcualizador.
2026-08-28 17:48:52 +02:00
ShanaiaBot 080d342de0 chore: bump version to 1.3.0+153 [ci skip] 2026-08-28 15:41:41 +02:00
FreeTLab 689f3e8123 chore(release): rebuild to get a fresh version code [version set]
Build & Deploy PluriWave / Análisis de código (push) Successful in 27s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 4m4s
Play Console already holds version code 152 (name 1.3.0, uploaded 16 Aug),
so the bundle this pipeline produced was rejected as a duplicate code.

This empty commit re-triggers the build. The bump step advances the code to
153 (the first free one) while [version set] keeps the 1.3.0 version name,
which is the release name this freemium/IAP work is shipping under.
2026-08-28 15:23:13 +02:00
ShanaiaBot 70ee13d540 chore: bump version to 1.3.0+152 [ci skip] 2026-08-16 00:13:12 +02:00
FreeTLab 9cfa5ac17d fix(iap): address code review defects in freemium/IAP change
Build & Deploy PluriWave / Análisis de código (push) Successful in 42s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 4m23s
Fixes 9 of 10 review findings (10th requires a manual Play Console
step, no code change):

1. app.dart/banner_anuncio_superior.dart: move the top SafeArea inside
   BannerAnuncioSuperior so it only reserves status-bar height when an
   ad actually renders, restoring edge-to-edge layout for premium and
   free-unloaded users.
2. servicio_anuncios.dart: bound every interstitial await (load,
   presentation, and the injected implementation itself) with
   injectable timeouts so a callback that never fires can no longer
   hang a caller.
3. estado_entitlement.dart/hoja_premium.dart: expose a typed
   resultadoUsuario signal for purchase/restore failures and
   restore-found-nothing, with dedicated localized messages
   (compraError, restauracionSinCompras) across all 13 locales --
   never the raw developer/exception string.
4. main.dart/servicio_consentimiento.dart: add a GDPR/UMP consent flow
   (ConsentInformation/ConsentForm) that gates Mobile Ads SDK init on
   canRequestAds(); premium users never see a consent form; failures
   degrade to no ads instead of crashing or blocking startup.
6. servicio_anuncios.dart: track real ad presentation
   (onAdShowedFullScreenContent) so a failed-to-show interstitial no
   longer consumes a session cap slot.
7. banner_anuncio_superior.dart: add an explicit load-attempted guard
   so repeated didChangeDependencies (e.g. entitlement notifyListeners
   during a purchase) can only ever trigger one banner load attempt.
8. servicio_anuncios.dart: make esPremium a required constructor
   parameter, matching the hardened contract already applied to
   EstadoAlarmas/EstadoGrabacion/EstadoRadio.
9. hoja_premium.dart: add a dedicated premiumActivo localized string
   instead of reusing the equalizer's equalizerActive translation,
   across all 13 locales.

All fixes implemented RED-first (failing test before production
code). Full suite: 1261 passed, 2 pre-existing skips, 0 failures.
flutter analyze: 5 pre-existing issues only, 0 new.

[version set]
2026-08-12 16:10:46 +02:00
FreeTLab 94f354a7c1 feat(iap): wire real AdMob app id, banner and interstitial units
App id always uses the real value (SDK init only, no ad-serving risk).
Banner/interstitial pick the real unit id in release builds and Google's
test unit id everywhere else, so debug/profile builds can never serve
(or accidentally tap) a real ad.
2026-08-12 12:53:34 +02:00
FreeTLab d81fabbe27 refactor(iap): make esPremium a required constructor parameter
EstadoAlarmas, EstadoGrabacion and EstadoRadio defaulted `esPremium` to
`() => true`, so any construction site that forgot to wire entitlement
compiled fine and silently ran ungated — failing OPEN to premium and
disabling the paywall with no test able to catch it.

The parameter is now required with no default. Production wiring in
app.dart was already correct and is unchanged; the 184 pre-existing test
call sites now pass `() => true` explicitly, which is exactly the old
implicit default, so every assertion is untouched.

EstadoRadio has no gate of its own but constructs EstadoGrabacion, so it
inherits the same contract.

The one test that existed to pin the old default is renamed to describe
what it still covers (the premium path through iniciar() with no
duracion); its assertions are unchanged.
2026-08-10 22:06:36 +02:00
FreeTLab aa0b242374 feat(iap): add freemium unlock via one-time in-app purchase
Adds a permanent, non-consumable premium unlock (EstadoEntitlement +
PuertoCompras/ServicioComprasPlayBilling) that removes ads and unlocks
alarm vacations, alarms past a 5-alarm free cap, recording start, and
full Android Auto browsing. The phone equalizer stays free for everyone.

- Entitlement is prefs-backed (compra_premium_v1), fail-open, and
  resolvable headlessly via esPremiumPersistido() for the Android Auto
  audio handler, which registers before runApp.
- Android Auto reduced mode keeps the real root folder labels for free
  users; browsing into any of them (and playFromMediaId/playFromSearch/
  skipToNext/skipToPrevious) is blocked at the getChildren/servicio_audio
  choke points, with a locked "Función Premium" item as the backstop.
  Current-station play/pause/stop stays untouched. A free -> premium
  transition actively invalidates the head unit's cached browse tree.
- Ads (top banner + capped interstitial before adding a station or an
  alarm) are gated behind entitlement via ServicioAnuncios, using
  official Google test ad unit IDs pending AdMob provisioning.
- Alarm cap UX shows an explanatory message with a secondary unlock
  action rather than a bare paywall jump; existing data is grandfathered.
- 4 new localization keys translated across all 13 supported locales.

Co-located tests use strict TDD (RED test before implementation) for
every new pure-logic unit; full existing suite passes unchanged.
2026-08-10 20:37:07 +02:00
ShanaiaBot 186ff45105 chore: bump version to 1.2.29+151 [ci skip] 2026-08-07 17:18:26 +02:00
FreeTLab f4a1fac45a merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m30s
2026-08-07 17:17:49 +02:00
FreeTLab ea005434d2 merge: local skips stay local, failed stations keep their metadata 2026-08-07 17:17:48 +02:00
FreeTLab d754e28ddf fix(audio): keep local skips local, and stop a failed station blanking Auto
Three reported suspicions. Two confirmed by reading, one not.

1. CONFIRMED, self-inflicted. Playing a song from the phone and pressing
NEXT jumped to a radio station.

3398d02 taught skipToNext/skipToPrevious to fall back to station skipping
when there is no local queue, so the car's buttons would not be dead for
radio. But queue-less does not mean radio: tapping ONE track goes through
reproducirPistaLocal, which never builds a queue -- only folder playback
sets _colaLocal. That is exactly why the report said "at least the first
time".

emisoraActual cannot tell them apart either: _cambiarFuente fills it in for
every source, so a local MP3 arrives as an Emisora whose url is its
content:// document URI. The media id's scheme is the real discriminator,
the same test that already keeps the recorder off local files. A local
track now skips nowhere, which is the correct behaviour for a single item.

2. CONFIRMED mechanism. A failed station made the app disappear from the
Android Auto pane.

The error path published STATE_ERROR and then cleared everything:
`emisoraActual = null; mediaItem.add(null)`. That leaves the session in an
error state with no metadata at all, and Auto drops a session with nothing
to show -- reported as "if a station fails it seems to crash, and going to
1/3 it fails".

Both are kept now. Nothing outside servicio_audio.dart consumes mediaItem
(verified), so the phone is unaffected, and the car gains two things: the
screen can still name the station that failed instead of going blank, and
previous/next stay usable, so a driver can skip out of a dead station
instead of being stranded -- _saltarEmisora needs emisoraActual to know
where it is in the list. The error state itself is unchanged.

3. NOT CONFIRMED. A local track occasionally jumping to another one mid-play.

An advance requires a genuine `completed` from just_audio, so either the
player reports the end early -- plausible for a content:// SAF source,
whose duration is not always exact -- or something else moved the track.
Reading the code cannot separate those, so nothing was changed on a guess.
The advance now logs the decision with the processing state, position and
duration that caused it, so the next occurrence arrives with its reason
attached.

Tests: 1192 -> 1195.
2026-08-07 17:17:48 +02:00
ShanaiaBot 1da417fdf5 chore: bump version to 1.2.28+150 [ci skip] 2026-08-07 13:06:41 +02:00
FreeTLab 950c9fda58 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 28s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m41s
2026-08-07 13:06:01 +02:00
FreeTLab 0949525859 merge: ship the onboarding and release-notes content 2026-08-07 13:06:00 +02:00
FreeTLab 0ef6ce35b4 fix(assets): declare the content subdirectories so onboarding ships
Audit of the same failure family as the shrunk drawables: references by
NAME that nothing validates at compile time.

The whole onboarding and release-notes feature had never shipped. Reading
the installed APK: ZERO entries under assets/content/, while
assets/icons/alarmas/* was present. pubspec declared `assets/content/`, and
Flutter does not recurse -- naming a directory includes the files sitting
directly in it, never its subdirectories. Every content file lives in one
(onboarding/, updates/<locale>/), so none of them were packaged.

On the device that surfaced on every single launch:

  Unable to load asset: "assets/content/onboarding/en.md"

with the file plainly present on disk. That is why it never looked like a
packaging problem. The tell was already in the pubspec: assets/icons/alarmas/
is listed explicitly, so the rule was known once and not applied here.

All 14 content directories are now declared: onboarding/ plus updates/ for
each of the 13 locales.

The guard is a test that loads every file under assets/content/ through
rootBundle, because that is the only thing that proves an asset is declared
and will ship. A test asserting File.existsSync would have stayed green
through all of this -- the files were never missing, only unpackaged. Run
against the unfixed pubspec it fails 26 of 27; with the fix it passes.

Tests: 1165 -> 1192.
2026-08-07 13:05:59 +02:00
ShanaiaBot dc62ef6adc chore: bump version to 1.2.27+149 [ci skip] 2026-08-07 12:53:35 +02:00
FreeTLab 28f47d6340 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m39s
2026-08-07 12:52:56 +02:00
FreeTLab ea0c6c8a9c merge: keep Dart-named drawables from the resource shrinker 2026-08-07 12:52:55 +02:00
FreeTLab c3cc4120c0 fix(android): stop the resource shrinker from deleting Dart-named drawables
Root cause found, and it is not the stale build cache I claimed earlier.
flutter clean was good hygiene and changed nothing here, because nothing
was cached: the resources were being deliberately removed.

Flutter's own Gradle plugin enables shrinking on every release build --
FlutterPlugin.kt, `releaseBuildType.isMinifyEnabled = true` and
`isShrinkResources = true` -- no matter what app/build.gradle.kts says. The
shrinker keeps what it can see referenced, and it cannot see
`MediaControl.custom(androidIcon: 'drawable/ic_auto_eq_on')`: that is a
string inside Dart, resolved at runtime through getIdentifier. So both
equalizer icons were stripped from every release APK ever built.

The evidence that pins it, from the APK pulled off the device:

  ic_stat_pluriwave   present   <- referenced as R.drawable from Kotlin,
                                   4 call sites in the alarm notifications
  ic_auto_eq_on       absent    <- named only in a Dart string
  ic_auto_eq_off      absent    <- named only in a Dart string

Same folder, same file shape, same commit range. The only difference is
whether a real R.drawable reference exists, which is exactly what the
shrinker looks for.

The consequence was never a blank button. getResourceId returns 0 for an
unresolvable name, PlaybackStateCompat.CustomAction.Builder throws on a 0
icon, and that throw aborts AudioService.setState before the media session
is activated -- so Android Auto held a frozen, inactive session. Dead
playback screen, play that never became pause, the app losing its pane to
any app with a live session, audio playing "as if it were not the app".
One shrunk file, four symptoms, since 31 July (2540556).

Two protections, because they fail differently:
- res/raw/keep.xml with tools:keep is the official mechanism for
  dynamically resolved resources and is what actually binds the shrinker;
- RecursosResueltosPorNombre.kt gives them genuine R.drawable references,
  the same thing that kept ic_stat_pluriwave alive all along.

station_art_* are kept too. They are reached the same way, through
android.resource:// URIs built in Dart, and survived only by luck.

Tests: 1165, unchanged -- this is a build-configuration fix, and no Dart
test can see it. The CI resource guard is what verifies it now.
2026-08-07 12:52:55 +02:00
ShanaiaBot 7a29026992 chore: bump version to 1.2.26+148 [ci skip] 2026-08-07 12:41:03 +02:00
FreeTLab 9914aced92 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 27s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 1m19s
2026-08-07 12:40:26 +02:00
FreeTLab 4cc42af9d1 merge: resource guard inspects the resource table and self-checks 2026-08-07 12:40:25 +02:00
FreeTLab e0fa2d695a fix(ci): inspect the resource table, not zip paths, and self-check first
The previous guard reported "Drawables en el APK: (ninguno)" for a 105MB
release APK. Zero drawables is impossible -- AndroidX alone contributes
dozens -- so the check was wrong, not the build. Release APKs shorten and
rename resource file paths, so `res/drawable/...` simply is not how they
are stored there. The 45MB base.apk taken off the device kept readable
paths because it came from an AAB through bundletool; the CI builds a fat
APK through a different pipeline. Same app, different layout.

Resource NAMES survive in resources.arsc regardless of path shortening, so
that is what gets inspected now.

And the guard checks itself before judging. It looks for a sentinel
resource known to be present (station_art_nova); if the sentinel is not
found, the inspection method is unreliable and the step says so instead of
declaring anything absent. This guard has already lied once, reporting
ic_stat_pluriwave missing when it was verified present, and that lie was
about to send us hunting a build problem that did not exist. A check with
no way to detect its own failure has no business failing a build.

Verified before pushing, all three extracted verbatim from the parsed YAML
and run against real inputs:
  1. real 45MB base.apk    -> sentinel found, ic_stat_pluriwave OK,
                              ic_auto_eq_on/off missing, exit 1
  2. APK absent            -> reports the path and lists what is there,
                              exit 1, no resource accusations
  3. zip without arsc      -> "inspection impossible", exit 1 (checked
                              without a pipe, so the code is the script's)

Scenario 3 is the one the old guard got wrong: it turned an inspection
failure into three false "FALTA" lines.
2026-08-07 12:40:25 +02:00
ShanaiaBot 9d8f426fc8 chore: bump version to 1.2.25+147 [ci skip] 2026-08-07 12:35:43 +02:00
FreeTLab ca5f243524 merge: repair the workflow YAML
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 1m29s
2026-08-07 12:35:02 +02:00
FreeTLab 1e97a94602 fix(ci): repair the workflow YAML broken by an unindented heredoc
The previous commit made build.yml unparseable and no job ran at all:

  yaml: line 183: could not find expected ':'

A `run: |` block is a YAML literal scalar, so every line has to keep the
block's indentation. The python3 fallback I added used a heredoc whose
body sat at column 0, which terminates the scalar -- YAML then tried to
read `import zipfile, sys` as a mapping and gave up. Worse than a broken
check: a broken pipeline.

The fallback is gone rather than re-indented. unzip is present on this
runner, a second code path existed only to guard against a case that was
never observed, and its only contribution was an escaping hazard inside
YAML inside shell.

Verified before pushing this time, which is the actual lesson:
- build.yml now parses (yaml.safe_load), 6 + 15 steps;
- the guard's `run` script was extracted from the parsed YAML and executed
  verbatim against the real 45MB base.apk pulled off the device. It prints
  the drawable inventory, reports ic_stat_pluriwave OK and ic_auto_eq_on /
  ic_auto_eq_off missing, and exits 1 -- matching an independent zipfile
  inspection of the same file.

Two commits in a row shipped a CI change that had never been run. Both
were caught by the user rather than by me.
2026-08-07 12:35:02 +02:00
FreeTLab 107739caa3 merge: incorporate the CI version bump 2026-08-07 12:27:41 +02:00
FreeTLab b3bd71be84 merge: make the APK resource guard trustworthy 2026-08-07 12:27:40 +02:00
FreeTLab 0a47c327f1 fix(ci): stop the resource guard from lying when it cannot inspect the APK
The guard added in the previous commit reported all three drawables as
missing on its first run, including ic_stat_pluriwave -- which is
verifiably present: it was read out of the base.apk pulled off the device
byte by byte. The step also finished in 0s, so it never opened the file at
all. Either the APK is not at the assumed path on this runner or unzip is
unavailable, and the failing pipeline silently produced an empty listing
that every grep then "failed" against.

A guard that lies is worse than no guard: it sends you hunting ghosts,
which is exactly the failure mode this whole episode has been about.

It now verifies its own preconditions before judging anything:
- the APK must exist, and if it does not the step prints where the APKs
  actually are (find over build/app/outputs) instead of guessing;
- it needs unzip or python3, and says so plainly if neither is there;
- an empty listing is treated as "inspection unreliable", not as
  "everything is missing";
- it dumps the real res/drawable inventory before the verdict, so a
  future failure is readable without another round trip.

Matching is now exact (grep -qx) rather than substring.

The logic was run locally against the real 45MB base.apk taken off the
device: ic_stat_pluriwave OK, ic_auto_eq_on and ic_auto_eq_off missing --
which is precisely what an independent zipfile inspection of the same APK
reported yesterday. The check agrees with reality before shipping.
2026-08-07 12:27:40 +02:00
ShanaiaBot 53126bdbe7 chore: bump version to 1.2.24+146 [ci skip] 2026-08-07 11:39:06 +02:00
FreeTLab ec6ccb2db8 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 2m0s
2026-08-07 11:38:27 +02:00
FreeTLab 8e00dc0c7c merge: resource guard in CI and group-aware station skipping 2026-08-07 11:38:27 +02:00
FreeTLab f01c0911f7 fix(auto): guard shipped resources, walk favourite groups when skipping
History review requested by the owner: when and why did the Android Auto
UI stop working.

ANSWER: 31 July, commit 2540556, "give the equalizer actions distinct,
state-aware icons".

  9eff760 (31-07)  androidIcon: 'drawable/ic_stat_pluriwave'  -> in the APK
  2540556 (31-07)  androidIcon: 'drawable/ic_auto_eq_on'      -> NEVER in it

That commit swapped a drawable that shipped for two that the stale CI
resource cache never included. From that moment getResourceId returned 0,
PlaybackStateCompat.CustomAction.Builder threw, and the throw aborted
AudioService.setState before the session was published -- so every Android
Auto symptom chased since is one line of that commit. The bitter part is
that 2540556 was itself a fix for a report about two identical icons.

Three changes.

1. CI guard. The build now unzips the release APK and fails if a drawable
resolved by NAME at runtime is missing. Resolution by name cannot fail at
compile time -- it fails in the car, silently, with id 0. This class of
bug shipped undetected for a week; it cannot ship again.

2. Skipping stations now walks the favourites GROUP first, as requested:
group -> all favourites -> my stations -> catalogue. Two deliberate
exclusions, both tested: `sinAsignarId` is the ABSENCE of a group, not a
group, so those walk all favourites; and a one-member group falls through
too, or both buttons would be dead ends. The group is read from the
FAVOURITE record, never from the playing station -- that one is rebuilt by
emisoraDesdeMediaItem, which carries no group id and would always report
"unfiled".

3. Diagnostics on the station skip. It was reported as doing nothing for
radio, and every early return in that method is silent: an empty list and
a single-entry list look identical from outside. The log now names which
one fired, so the next capture answers it instead of another hypothesis.

Tests: 1161 -> 1165.
2026-08-07 11:38:27 +02:00
ShanaiaBot 62f7804d6d chore: bump version to 1.2.23+145 [ci skip] 2026-08-07 00:25:00 +02:00
FreeTLab 57f89c130f merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m39s
2026-08-07 00:24:18 +02:00
FreeTLab 02cfd48992 merge: clean the CI build so new Android resources ship 2026-08-07 00:24:18 +02:00
FreeTLab 72a291d0c0 fix(ci): clean before building so new Android resources reach the APK
The equalizer drawables were never in the shipped binary. Verified by
pulling base.apk off the device and reading it:

  res/drawable/ic_stat_pluriwave.xml   PRESENT  (added 02-07)
  res/drawable/ic_auto_eq_on.xml       ABSENT   (added 31-07, 2540556)
  res/drawable/ic_auto_eq_off.xml      ABSENT

Neither as a zip entry nor as a name in resources.arsc. Both files are in
git with content and on disk; the older sibling in the same folder is in
the APK. The difference is when they were added.

This runner is self-hosted and the workflow never cleaned, so build/
survives between runs and Gradle's incremental resource merge went stale:
resources present when the cache was built kept working, resources added
afterwards silently never made it in.

The cost was weeks of wrong diagnosis. getResourceId returned 0 for that
icon, PlaybackStateCompat.CustomAction.Builder throws on a 0 icon, and
that throw aborts AudioService.setState BEFORE mediaSession.setActive --
so Android Auto held a frozen, inactive session. On the device that
surfaced as a dead playback screen, a play button that never became
pause, PluriWave losing its pane to whichever app did have an active
session, and audio that played "as if it were not the app". One cause,
four symptoms.

Dart changes always shipped because Dart is recompiled every build, which
is exactly why this hid for so long: every fix appeared to land and
nothing behaved differently.

flutter clean costs build time. It buys the guarantee that what is in git
is what is in the binary, which this project just spent weeks not having.
2026-08-07 00:24:18 +02:00
ShanaiaBot adb2a1d1bc chore: bump version to 1.2.22+144 [ci skip] 2026-08-07 00:19:27 +02:00
FreeTLab 346cd2b6b9 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m37s
2026-08-07 00:18:49 +02:00
FreeTLab e337f6166c merge: reject a local track as a recording source 2026-08-07 00:18:48 +02:00
FreeTLab 54d87190fe fix(grabacion): reject a local track as a recording source
Reported, with this on screen:

  No se pudo iniciar la grabación: Invalid argument(s): Unsupported scheme
  'content' in URI content://com.android.externalstorage.documents/tree/
  primary%3AMusic/document/primary%3AMusic%2F...%2FNew Limit - Smile.mp3

The URI in that message is a local MP3, not a station.
PluriWaveAudioHandler._cambiarFuente sets `emisoraActual` for EVERY source
it plays, so a local track surfaces as an Emisora whose `url` is the SAF
content:// document URI it was opened from. EstadoGrabacion.iniciar only
checked for null, handed that straight to the recorder, and the HTTP
client failed with a message no user can act on.

"It used to work" is exactly right: before local music playback existed,
whatever was playing was always a real station, so the case could not
arise. The recorder never changed.

iniciar() now also requires a real network stream (esEmisoraGrabable) and
falls back to the existing "select a station first" message, which is the
correct guidance here -- recording a local file makes no sense anyway,
it is already on the device. No new l10n key, so no 13-locale churn for a
message that already says the right thing.

Tests: 1158 -> 1161.
2026-08-07 00:18:48 +02:00
ShanaiaBot 968377f1c7 chore: bump version to 1.2.21+143 [ci skip] 2026-08-06 21:48:59 +02:00
FreeTLab e3638ea4a7 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 29s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m38s
2026-08-06 21:48:21 +02:00
FreeTLab a93e5b192b merge: make audio diagnostics visible in release builds 2026-08-06 21:48:20 +02:00
FreeTLab 1d5332453f fix(audio): make the audio diagnostics visible in release builds
Every diagnostic line in the audio path used `dart:developer`'s `log()`.
That function writes to the VM service, which a RELEASE build does not
have — so in the only build that ever runs in a car, all eleven of them
went nowhere. `debugPrint`/`print` do reach logcat in release; `log()`
does not.

That includes the two channels built specifically to end the guessing:
- `registrarErrorAudioService`, which subscribes to
  `AudioService.asyncError` so the plugin's swallowed platform exceptions
  stop vanishing (b0271fa). It moved them from a dropped PublishSubject
  to a dropped log call.
- `_trazarEstadoPublicado`, the published-state trace added in 7054a4c to
  settle why the car's play button never becomes pause.

So "no evidence" was never a quiet app. It was an app writing its
evidence somewhere release builds discard. Several rounds of hypotheses
were argued without data that the app was already producing.

All eleven now use `debugPrint` with a `[PluriWave][Tag]` prefix, so one
filter catches the audio path and the existing alarm lines together:

  adb logcat | grep PluriWave

No behaviour changes. Tests: 1158, unchanged.
2026-08-06 21:48:20 +02:00
ShanaiaBot 42bb2b4a54 chore: bump version to 1.2.20+142 [ci skip] 2026-08-06 19:50:46 +02:00
FreeTLab 490ae29bd4 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 27s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m47s
2026-08-06 19:50:07 +02:00
FreeTLab 7d86ddfae9 merge: duck instead of pause, keep the service foreground, restore local music 2026-08-06 19:50:07 +02:00
FreeTLab 3398d02a43 fix(auto): keep the service alive through interruptions, restore local music
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.
2026-08-06 19:49:57 +02:00
ShanaiaBot 2480c57bfc chore: bump version to 1.2.19+141 [ci skip] 2026-08-06 17:19:36 +02:00
FreeTLab 1d8c9c57bc merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 29s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m31s
2026-08-06 17:18:54 +02:00
FreeTLab c1afe72aec fix(arranque): stop a headless engine from dying before runApp
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 the app was force-killed and reopened.
Never without Android Auto.

The user guessed portrait-only plus a landscape phone made the app "go a
bit crazy". Right file and right trigger, different mechanism -- a broken
layout renders overflow stripes or a red error box, never white. White
means nothing was ever built, so runApp had not run.

Verified in the plugin source: AudioServiceActivity.provideFlutterEngine
returns AudioServicePlugin.getFlutterEngine(context), which CREATES the
engine and executes the Dart entrypoint the first time it is asked. When
the car binds the MediaBrowserService before the app is opened, that
first ask is the service -- so main() runs HEADLESS, with no Activity.

SystemChrome.setPreferredOrientations travels the flutter/platform
channel, whose handler (PlatformPlugin) is installed by the Activity.
Headless there is nobody to answer it, so the call throws
MissingPluginException or never settles. It was the FIRST await in
main(), which made it fatal twice over: registrarFuenteNavegacion sits
below it and never ran, leaving getChildren with 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. That is exactly the
workaround that was reported, and it is what makes the diagnosis fit
every detail rather than most of them.

Three changes, smallest first:
- The Android Auto browse registration moves above every await. It
  depends on nothing, and anything before it is a place to get stuck.
- The orientation call is no longer awaited. It is a display preference,
  never a prerequisite for runApp, and _OrientacionResponsiveApp already
  re-applies it in didChangeDependencies -- the only moment it can take
  effect anyway.
- aplicarPoliticaOrientacion swallows everything and logs, so the
  headless failure can never propagate again.

The policy itself is unchanged and now pure and tested
(orientacionesPara): phones portrait, >=600dp everything.

Tests: 1141 -> 1146.
2026-08-06 17:18:53 +02:00
ShanaiaBot 809b4c6eb4 chore: bump version to 1.2.18+140 [ci skip] 2026-08-06 01:29:21 +02:00
FreeTLab 14985f6417 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m48s
2026-08-06 01:28:43 +02:00
FreeTLab a6cdf0e72c fix(auto): advertise the transport actions Android for Cars requires
Reported: on the Android Auto playback screen the play/pause button stays
on PLAY while audio is audibly playing, and "it used to work, in the
latest versions it doesn't".

Previous rounds looked for a regression in this repo's audio commits and
found none: every playbackState.add site publishes playing:true with a
ready processingState, and AudioService.getPlaybackState maps that to
STATE_PLAYING. That search was aimed at the wrong thing.

The Android for Cars guide ("Enable playback control") is explicit:
"Android Auto and AAOS display playback controls based on the actions
that are enabled in the PlaybackStateCompat object. By default, your app
must support the following actions: ACTION_PLAY, ACTION_PAUSE,
ACTION_STOP, ACTION_PLAY_FROM_MEDIA_ID, ACTION_PLAY_FROM_SEARCH."

systemActions has carried only `seek` + `stop` since e9d1f67, the first
commit of the project -- git log -S confirms it was never once edited. So
the required actions have never been advertised, and no audio commit can
explain a change in behaviour. Android Auto ships as its own app and
updates itself, which is how a working screen breaks with a clean repo
history. That fits the report better than any commit here does.

The phone notification was never affected: it builds its play/pause
button from `controls`, not from these bits, which is exactly why the
symptom is car-only.

Skip actions stay conditional on an active queue on purpose -- the same
guide notes Auto reserves the prev/next slots for them and gives the
space to custom actions when the app does not support them, and that is
the space the equalizer toggle needs.

ACTION_PLAY_FROM_SEARCH is now implemented rather than merely claimed:
advertising it unimplemented would have the car's assistant accept "play
Radio X" and silently do nothing. emisoraParaBusqueda ranks exact name,
then prefix, then substring, then country, accent- and case-insensitive
because voice transcription rarely gets diacritics right; favourites are
searched first so they win a name tie, and a miss plays nothing rather
than something arbitrary.

Still a hypothesis for the play/pause symptom, not a confirmed fix -- it
is documentation-backed and cheap, but only a head unit can confirm it.

Tests: 1132 -> 1141.
2026-08-06 01:28:42 +02:00
ShanaiaBot 924a5cab21 chore: bump version to 1.2.17+139 [ci skip] 2026-08-05 23:08:06 +02:00
FreeTLab 1e7c0daa90 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 30s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m30s
2026-08-05 23:07:20 +02:00
FreeTLab bca0a9bbb7 merge: dart-side snooze anchor guard, Auto progress bar, drop EQ folder 2026-08-05 23:07:19 +02:00
FreeTLab 80538900db fix(alarmas,auto): guard the last unguarded snooze path, surface car progress
Continuation of 7054a4c: the native anchor guard alone did not fix the
reported ~1444-minute snooze, because Dart runs AFTERWARDS on the
pre-notice path and had no guard at all.

1. Snooze from the pre-notice notification, root cause.

app.dart dispatches AFTER the receiver's postponeNext already ran and
after startActivity, and EstadoAlarmas.posponerProximaDesdePreaviso took
whatever occurrence it was handed on faith, then persisted and
rescheduled from it -- the last snooze path in the codebase with no
occurrence guard. The occurrence itself is not trustworthy either:
app.dart falls back to alarma.proximaEjecucion when the native event
carries none, and that field can already point at tomorrow.

_ocurrenciaSonando is generalized into _ocurrenciaValida with a caller-
supplied forward allowance and an externally-proposed occurrence that
still has to survive the same check. The pre-notice path gets a
ventanaPreaviso (30 min, matching AlarmScheduler.PRE_NOTICE_MILLIS) --
unlike the ringing-screen guard, this occurrence legitimately has not
happened yet, which is exactly why the existing helper could not just be
reused here.

Also heals state already poisoned by the missing guard: a snoozeHasta
parked past a 3-hour ceiling (posponerEjecucion clamps to 120 minutes,
so anything beyond that is corruption, not a long real snooze) is
dropped on recalculation. Without it, an alarm poisoned on a build
before this fix keeps reporting tomorrow after updating, and the user
reasonably concludes nothing changed.

2. Android Auto: no progress bar or time labels on a local track.

updatePosition was never set anywhere in the handler, so it sat at its
Duration.zero default while copyWith refreshed updateTime to now on every
push -- the car was told "position 0, as of right now" on every event, a
bar pinned at the start regardless of what was actually playing. Now set
from _player.position on both the player-state and buffered-position
listeners (the latter ticks ~2/s, which is what keeps the car's bar
smooth between player-state events). Also stream the MediaItem's
duration once the source reports it -- Auto draws no bar at all without
one, and radio streams correctly keep reporting none (live audio has no
length).

3. Android Auto: drop the Ecualizador browsable folder.

Owner decision after driving with it: a browsable six-preset list is
more interaction than a driver wants, and on/off from all three player
views (already fixed in 7054a4c to win the custom-action slot) is the
only equalizer control that belongs in the car. Preset selection stays on
the phone. This lands back on the redesign mockup's original rule ("sin
carpeta de ecualizador"), now for a road-tested reason. getChildren keeps
answering the folder's id transitionally, since a head unit can have the
old tree cached for a session or two.

The two "raiz always includes/ends with Ecualizador" tests are replaced,
not regressed -- same move the codebase already made once in the other
direction for the same folder.

Tests: 1127 -> 1132.
2026-08-05 23:07:10 +02:00
ShanaiaBot 61c78b5497 chore: bump version to 1.2.16+138 [ci skip] 2026-08-05 11:56:12 +02:00
ShanaiaBot 41d637b890 chore: bump version to 1.2.15+137 [ci skip] 2026-08-05 10:18:35 +02:00
FreeTLab 2bafc7e5ac merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m44s
2026-08-05 10:17:50 +02:00
FreeTLab c4a39ee8ed merge: native snooze anchor guard and Android Auto EQ slot 2026-08-05 10:17:48 +02:00
FreeTLab 7054a4c871 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 defect a9da855 fixed on the Dart side with
EstadoAlarmas._ocurrenciaSonando, after 9c7cf4e had 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
regression abc6b47 fixed, 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.
2026-08-05 10:17:41 +02:00
ShanaiaBot ddb15623a0 chore: bump version to 1.2.14+136 [ci skip] 2026-08-03 22:05:22 +02:00
FreeTLab 3a4dc3b4b1 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m37s
2026-08-03 22:04:45 +02:00
FreeTLab 04300592e0 fix(alarmas): heal alarms already poisoned by the old Detener anchor
The anchor fix stops NEW damage, but devices that ran the buggy build
still carry a future occurrence in ultimaEjecucionGestionada in
SharedPreferences. _esValida rejects any candidate matching it, so the
affected alarm would keep skipping that day with nothing in the UI to
explain it -- which reads as "still broken" rather than "fixed".

_recalcular now drops an ultimaEjecucionGestionada that is meaningfully
in the future. An occurrence cannot have been handled before it happens,
so such a value is corrupt by definition, and dropping it can only ever
restore a real future ring: the double-fire guard it also feeds needs a
PAST occurrence to do its job, and those are untouched.

Placed in the recalculation that every load and every mutation already
funnels through, so an affected alarm heals on the next app open with no
user action -- no delete-and-recreate.

Tests: 1122 -> 1124, including one proving a genuine past occurrence is
still preserved.
2026-08-03 22:04:37 +02:00
ShanaiaBot cb76f09257 chore: bump version to 1.2.13+135 [ci skip] 2026-08-03 22:00:09 +02:00
FreeTLab df9252a621 merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 26s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m45s
2026-08-03 21:59:30 +02:00
FreeTLab ae3f96c0d1 merge: fix Detener consuming a future alarm occurrence 2026-08-03 21:59:30 +02:00
FreeTLab a9da855601 fix(alarmas): stop Detener from consuming an occurrence that never rang
Reported: an alarm set for Monday 16:20 never rang, and the "next alarm"
banner showed a different alarm (the next morning's) instead. No
vacation range involved, both alarms active.

finalizarEjecucion anchored the completed occurrence to proximaEjecucion
with no check that it was the one actually ringing. On the native-fire
path the fire-time sync advances proximaEjecucion to the NEXT occurrence
before the user can reach the ring screen, so tapping Detener recorded a
FUTURE occurrence in ultimaEjecucionGestionada.
ServicioProgramacionAlarmas._esValida then rejects that occurrence for
real: a Monday-only alarm stopped today simply never rings next Monday,
and every sibling outranks it in the banner because its own
proximaEjecucion is a week out.

Reproduced at its purest in the second test: with nothing ringing at
09:01 on Monday, Detener pushed a 16:20 alarm to the FOLLOWING Monday.

posponerAlarma already had exactly this guard -- 9c7cf4e, "anchor snooze
to the ringing occurrence, never a future one", written after the same
failure showed up as a snooze armed a day out. It was applied to the
snooze path and never to the stop path, which sat ten lines below it in
the same file with the identical hazard.

Both paths now share one _ocurrenciaSonando helper so they cannot drift
apart again, and the reason lives in its doc comment rather than in a
comment on one of the two callers.

Also drops snoozeHasta from the stop path's candidate chain: a pending
snooze target is in the future by definition, and snoozeOrigen already
covers a ring that follows a snooze.

Tests: 1120 -> 1122.
2026-08-03 21:59:19 +02:00
ShanaiaBot 1c2b8e0e15 chore: bump version to 1.2.12+134 [ci skip] 2026-08-03 21:34:48 +02:00
FreeTLab 34d04bbc1e merge: incorporate the CI version bump
Build & Deploy PluriWave / Análisis de código (push) Successful in 31s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 2m24s
2026-08-03 21:34:09 +02:00
FreeTLab e962b8ac58 merge: restore the Android Auto equalizer toggle and add user presets 2026-08-03 21:33:55 +02:00
FreeTLab f2f706b342 fix(auto): restore the equalizer toggle and list the user's own presets
Two Android Auto regressions reported from the car.

1. The on/off equalizer action disappeared from the playback screen.

That was self-inflicted: commit cacd3ec removed it on the theory that a
custom action in `controls` aborts `AudioService.setState` and kills the
media notification. Reading the plugin source refutes it. setState
(AudioService.java:513-520) SPLITS the list -- a control carrying a
customAction goes to `customActions` (PlaybackStateCompat, i.e. the car),
everything else becomes a NotificationCompat.Action in `nativeActions`
(the phone notification). The two never mix. And the throw the theory
depended on cannot happen here: ic_auto_eq_on/ic_auto_eq_off both exist
under res/drawable, and the labels are non-empty in all 13 locales.

The notification outage was already fixed by abc6b47 (transient idle on
a source change, which setState turns into a full stop() at :557).

The action is back, with both state-aware icons. The real invariant --
a custom action's icon must resolve and its label must be non-empty --
is now a test that reads res/drawable and fails on a missing file,
instead of a comment claiming custom actions are forbidden outright.

2. The Ecualizador folder never listed the user's saved presets.

itemsEcualizadorAuto iterated PresetEcualizador.presets, so only the six
factory presets appeared -- the user's own were unreachable from the
car, the surface where a preset picker matters most. They now arrive
through a registered read function (same seam as stations and local
music, re-read per browse so a preset saved on the phone shows up
without an app restart).

presetsEcualizadorAuto is the single source of truth for the ordered
universe, used to BUILD the items and to RESOLVE a tap, so the folder
cannot show an item that resolution then refuses -- which is what the
factory-only default in seleccionarPresetEqPorMediaId would have caused.
A custom preset whose name collides with a factory one is dropped: the
media id is the raw name, so it could only ever resolve to the factory
entry, and an item that applies a preset other than the one it names is
worse than an absent one.

Tests: 1108 -> 1120.
2026-08-03 21:32:09 +02:00
186 changed files with 20221 additions and 948 deletions
+216 -17
View File
@@ -68,7 +68,18 @@ jobs:
echo "keyPassword=$KEYSTORE_PASSWORD" >> android/key.properties
echo "✅ Keystore configurado"
- name: Bump versión patch + commit
# PRO owns the version NAME; every branch advances the build NUMBER.
#
# Previously main also bumped its patch on every push, so main's semver
# raced permanently ahead of PRO's (main hit 1.3.3 while the branch that
# actually ships sat at 1.3.0). That buried the release artifacts under a
# dev branch on builds.freetimelab.es, which sorts by version, and made
# every main<->PRO merge conflict on pubspec.yaml.
#
# The build number still advances everywhere: Google Play requires it to
# be monotonic across the whole app, so two branches must never mint the
# same code.
- name: Bump versión + commit
run: |
BRANCH="${CURRENT_REF#refs/heads/}"
git config user.name "ShanaiaBot"
@@ -77,12 +88,20 @@ jobs:
SEMVER=$(echo "$CURRENT" | cut -d'+' -f1)
BUILD=$(echo "$CURRENT" | cut -d'+' -f2)
NEW_BUILD=$((BUILD + 1))
# If the triggering commit explicitly pins the version name via the
# [version set] marker, ship that semver as-is (a milestone like 1.0.0
# or a major/minor jump the automatic patch bump cannot reach) and only
# advance the build number, which Google Play requires to stay
# monotonic. Otherwise keep the default automatic patch+build bump.
if git log -1 --pretty=%B | grep -q '\[version set\]'; then
# Look for [version set] across EVERY commit this push introduced,
# not just the tip. `git pull` inserts an auto-generated merge commit
# whose message carries no marker, which silently discarded a pinned
# version name and bumped 1.3.0 to 1.3.1 behind our backs.
RANGO="${{ gitea.event.before }}..${{ gitea.sha }}"
if git log "$RANGO" --pretty=%B 2>/dev/null | grep -q '\[version set\]'; then
MARCADOR="si"
else
MARCADOR="no"
fi
if [ "$BRANCH" != "PRO" ] || [ "$MARCADOR" = "si" ]; then
# Non-release branches never touch the name; PRO respects a pin.
NEW_VERSION="${SEMVER}+${NEW_BUILD}"
else
MAJOR=$(echo "$SEMVER" | cut -d. -f1)
@@ -91,6 +110,8 @@ jobs:
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}+${NEW_BUILD}"
fi
echo "rama=${BRANCH} marcador=${MARCADOR} ${CURRENT} -> ${NEW_VERSION}"
sed -i '' "s/^version: .*/version: ${NEW_VERSION}/" pubspec.yaml
git add pubspec.yaml
git commit -m "chore: bump version to ${NEW_VERSION} [ci skip]"
@@ -109,18 +130,175 @@ jobs:
- name: Obtener dependencias
run: flutter pub get
# OBLIGATORIO en este runner autoalojado, no es higiene opcional.
#
# El directorio build/ sobrevive entre ejecuciones y el merge
# incremental de recursos de Gradle se queda rancio: los drawables
# ic_auto_eq_on/ic_auto_eq_off (anadidos el 31-07 en 2540556) NUNCA
# llegaron a entrar en el APK, mientras que ic_stat_pluriwave -- misma
# carpeta, anadido el 02-07 -- si estaba. Verificado extrayendo el
# base.apk instalado en el dispositivo: los ficheros no existen ni como
# entrada del zip ni en resources.arsc.
#
# El coste fue semanas de diagnostico equivocado. Cada setState
# publicaba una CustomAction cuyo icono resolvia a 0, y
# PlaybackStateCompat.CustomAction.Builder lanza en ese caso, abortando
# setState antes de activar la sesion de medios: Android Auto se
# quedaba con la sesion congelada e inactiva. El codigo Dart siempre
# llegaba porque se recompila; el recurso Android no.
- name: Limpiar artefactos de compilacion
run: flutter clean
- name: Reinstalar dependencias tras limpiar
run: flutter pub get
- name: Build APK release
run: flutter build apk --release
# Guardian de recursos: el APK debe contener los drawables que el codigo
# resuelve POR NOMBRE en runtime (getResources().getIdentifier).
#
# Un nombre que no resuelve devuelve id 0, y eso no falla la
# compilacion: falla en el coche. Concretamente
# PlaybackStateCompat.CustomAction.Builder lanza con icono 0, ese throw
# aborta AudioService.setState antes de activar la sesion de medios, y
# Android Auto se queda con la interfaz congelada. Paso exactamente eso
# entre el 31-07 (commit 2540556) y el 07-08 sin que nada lo detectara.
#
# Anadir un drawable nuevo referenciado por nombre => anadirlo aqui.
# Guardian de recursos: el APK debe contener los drawables que el codigo
# resuelve POR NOMBRE en runtime (getResources().getIdentifier).
#
# Un nombre que no resuelve devuelve id 0, y eso no falla la
# compilacion: falla en el coche. PlaybackStateCompat.CustomAction
# .Builder lanza con icono 0, ese throw aborta AudioService.setState
# antes de activar la sesion de medios, y Android Auto se queda con la
# interfaz congelada. Paso exactamente eso desde el 31-07 (commit
# 2540556) sin que nada lo detectara.
#
# La primera version de este paso daba FALSOS POSITIVOS: no comprobaba
# que el APK existiera ni que unzip estuviera disponible, asi que
# cualquier fallo de la tuberia se reportaba como "faltan todos los
# recursos". Un guardian que miente es peor que no tener guardian:
# manda a buscar fantasmas. De ahi que ahora verifique primero sus
# propias herramientas y vuelque el inventario real antes de juzgar.
#
# Anadir un drawable nuevo referenciado por nombre => anadirlo aqui.
# Guardian de recursos: el APK debe contener los drawables que el codigo
# resuelve POR NOMBRE en runtime (getResources().getIdentifier).
#
# Un nombre que no resuelve devuelve id 0. Eso no falla la compilacion:
# falla en el coche. PlaybackStateCompat.CustomAction.Builder lanza con
# icono 0, ese throw aborta AudioService.setState antes de activar la
# sesion de medios, y Android Auto se queda con la interfaz congelada.
# Paso exactamente eso desde el 31-07 (commit 2540556) sin deteccion.
#
# Se inspecciona resources.arsc, NO las rutas del zip: el APK release
# acorta/renombra las rutas de recursos (una version anterior de este
# paso listo "ningun drawable" en un APK de 105MB, que es imposible).
# Los NOMBRES de recurso siguen en la tabla pase lo que pase.
#
# El centinela existe porque este guardian ya mintio una vez: al no
# validar su propio metodo, reporto como ausente hasta un recurso que
# estaba verificado presente. Si el centinela no aparece, la inspeccion
# no es fiable y NO tenemos derecho a declarar nada ausente.
#
# Anadir un drawable nuevo referenciado por nombre => anadirlo aqui.
- name: Verificar recursos criticos en el APK
run: |
set -u
APK=build/app/outputs/flutter-apk/app-release.apk
CENTINELA=station_art_nova
if [ ! -f "$APK" ]; then
echo "El APK no esta donde se esperaba: $APK"
find build/app/outputs -name '*.apk' 2>/dev/null || echo " (nada)"
exit 1
fi
echo "APK: $APK ($(wc -c < "$APK") bytes)"
if ! command -v unzip >/dev/null 2>&1; then
echo "unzip no esta disponible: no se puede inspeccionar el APK."
exit 1
fi
ARSC=$(mktemp)
unzip -p "$APK" resources.arsc > "$ARSC" 2>/dev/null || true
if [ ! -s "$ARSC" ]; then
echo "No se pudo extraer resources.arsc del APK."
exit 1
fi
echo "resources.arsc: $(wc -c < "$ARSC") bytes"
if ! grep -a -q "$CENTINELA" "$ARSC"; then
echo "El centinela '$CENTINELA' no aparece en la tabla de recursos."
echo "La inspeccion no es fiable; no se declara nada ausente."
exit 1
fi
echo "Centinela '$CENTINELA' localizado: la inspeccion es fiable."
FALTAN=0
for RECURSO in ic_auto_eq_on ic_auto_eq_off ic_stat_pluriwave; do
if grep -a -q "$RECURSO" "$ARSC"; then
echo "OK $RECURSO"
else
echo "FALTA $RECURSO"
FALTAN=$((FALTAN + 1))
fi
done
if [ "$FALTAN" -ne 0 ]; then
echo ""
echo "$FALTAN drawable(s) resueltos por nombre NO estan en el APK."
echo "En runtime resolveran a id 0 y tumbaran la sesion de medios."
exit 1
fi
echo "Todos los recursos criticos viajan en el APK."
- name: Build AAB release
run: flutter build appbundle --release
# El nombre lleva RAMA y CÓDIGO DE VERSIÓN, no solo el semver.
#
# Antes, cada build de 1.3.0 se llamaba `pluriwave-v1.3.0.aab` y caía en
# la misma carpeta, así que main y PRO se pisaban y tres builds distintos
# eran indistinguibles una vez descargados: el navegador los guarda como
# "(1)", "(2)"... y ya no se sabe cuál es cuál. Eso costó subir a Play
# Console un código de versión ya usado, dos veces.
#
# Con `pluriwave-PRO-v1.3.0+156.aab` el archivo se identifica solo,
# incluso semanas después y fuera de este repo.
- name: Publicar en ftl-builds (Zimaboard)
run: |
VERSION="${{ steps.version.outputs.version }}"
APK_NOMBRE="pluriwave-v${VERSION}.apk"
AAB_NOMBRE="pluriwave-v${VERSION}.aab"
DESTINO="/opt/ftl-builds/builds/pluriwave/v${VERSION}"
BUILD_NUMBER="${{ steps.version.outputs.build_number }}"
BRANCH="${CURRENT_REF#refs/heads/}"
ETIQUETA="${BRANCH}-v${VERSION}+${BUILD_NUMBER}"
APK_NOMBRE="pluriwave-${ETIQUETA}.apk"
AAB_NOMBRE="pluriwave-${ETIQUETA}.aab"
# La rama va en el NOMBRE DE LA APP, no en una subcarpeta.
#
# El objetivo sigue siendo el de siempre: que main y PRO no se mezclen
# en el portal, que ordena por número de versión y mostraba el build
# de desarrollo como "última versión" por delante del de release.
#
# Pero la primera solución metía la rama como TERCER nivel
# (pluriwave/main/v1.3.3/) y el portal indexa solo DOS —
# <app>/<versión>/<ficheros> —, así que desde el 29-08 ningún build de
# main volvió a aparecer en builds.freetimelab.es aunque el job saliera
# verde: el scp subía bien, a una ruta que el indexador no lee. Nada
# avisaba, y el echo de abajo se comía la rama y mandaba a la carpeta
# antigua, que llevaba congelada desde el +157.
#
# Con la rama en el nombre, PRO conserva la entrada limpia "pluriwave"
# y main tiene la suya, igual que ya conviven radar-foral y
# radar-foral-android.
if [ "$BRANCH" = "PRO" ]; then
APP="pluriwave"
else
APP="pluriwave-$(echo "$BRANCH" | tr '/' '-')"
fi
DESTINO="/opt/ftl-builds/builds/${APP}/v${VERSION}"
SSH_KEY="/Users/freetlab/.openclaw/workspace/.secure/zimaboard_ed25519"
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no ShanaiaBot@192.168.0.33 "mkdir -p ${DESTINO}"
@@ -130,28 +308,46 @@ jobs:
scp -i "$SSH_KEY" -o StrictHostKeyChecking=no \
build/app/outputs/bundle/release/app-release.aab \
"ShanaiaBot@192.168.0.33:${DESTINO}/${AAB_NOMBRE}"
echo "✅ APK: builds.freetimelab.es → pluriwave → v${VERSION}"
echo "✅ AAB: builds.freetimelab.es → pluriwave → v${VERSION}"
# La ruta se imprime desde ${APP}, no a mano: la version anterior tenia
# "pluriwave" escrito a fuego y mandaba a la carpeta equivocada cada
# vez que se compilaba algo que no fuera PRO.
echo "✅ APK: builds.freetimelab.es → ${APP} → v${VERSION} → ${APK_NOMBRE}"
echo "✅ AAB: builds.freetimelab.es → ${APP} → v${VERSION} → ${AAB_NOMBRE}"
# La publicacion automatica en Google Play es OPCIONAL.
#
# Este paso hacia `exit 1` cuando faltaba el secreto, asi que TODA
# compilacion de PRO terminaba en rojo por una funcion que nunca llego a
# activarse: el secreto no se configuro nunca y las subidas a Play se han
# hecho siempre a mano. Un rojo permanente entrena a ignorar los rojos, y
# entonces el dia que falle algo de verdad tampoco se mira.
#
# Ahora se omite con un aviso. El AAB ya esta compilado, firmado y subido
# a ftl-builds por el paso anterior, asi que no se pierde nada. El dia que
# se configure el secreto, los tres pasos se activan solos.
- name: Preparar credenciales de Google Play
id: credenciales_play
if: ${{ gitea.ref == 'refs/heads/PRO' }}
env:
GOOGLE_PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
run: |
if [ -z "$GOOGLE_PLAY_SERVICE_ACCOUNT_JSON" ]; then
echo "ERROR: falta el secreto GOOGLE_PLAY_SERVICE_ACCOUNT_JSON"
exit 1
echo "disponible=no" >> "$GITHUB_OUTPUT"
echo "AVISO: falta el secreto GOOGLE_PLAY_SERVICE_ACCOUNT_JSON."
echo "Se omite la publicacion en Google Play; sube el AAB a mano."
exit 0
fi
mkdir -p fastlane/credentials
printf '%s' "$GOOGLE_PLAY_SERVICE_ACCOUNT_JSON" > fastlane/credentials/google-play-service-account.json
echo "disponible=si" >> "$GITHUB_OUTPUT"
- name: Instalar Fastlane
if: ${{ gitea.ref == 'refs/heads/PRO' }}
if: ${{ gitea.ref == 'refs/heads/PRO' && steps.credenciales_play.outputs.disponible == 'si' }}
run: |
gem list -i fastlane >/dev/null 2>&1 || gem install fastlane --no-document
- name: Publicar AAB en Google Play Internal Testing
if: ${{ gitea.ref == 'refs/heads/PRO' }}
if: ${{ gitea.ref == 'refs/heads/PRO' && steps.credenciales_play.outputs.disponible == 'si' }}
env:
PLAY_JSON_KEY_PATH: fastlane/credentials/google-play-service-account.json
PLAY_AAB_PATH: build/app/outputs/bundle/release/app-release.aab
@@ -169,8 +365,11 @@ jobs:
if [ -z "$BOT_TOKEN" ]; then exit 0; fi
if [ "${{ job.status }}" = "success" ]; then
MSG="✅ *PluriWave* v${VERSION} · rama ${BRANCH} · ${COMMIT}%0AAPK + AAB generados"
if [ "$BRANCH" = "PRO" ]; then
# Solo se anuncia la subida a Play cuando de verdad ocurrio.
if [ "$BRANCH" = "PRO" ] && [ "${{ steps.credenciales_play.outputs.disponible }}" = "si" ]; then
MSG="${MSG}%0APublicado en Google Play · Internal Testing"
elif [ "$BRANCH" = "PRO" ]; then
MSG="${MSG}%0AEn builds.freetimelab.es · sube el AAB a Play a mano"
else
MSG="${MSG}%0APublicado en builds.freetimelab.es"
fi
+9
View File
@@ -137,6 +137,15 @@
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<!-- AdMob application id (iap-freemium-unlock). Real id, provisioned
in the AdMob console. Safe to use in all build modes — this id
only initializes the SDK; it never serves an ad by itself, so it
carries none of the "don't tap your own ads" risk that ad unit
ids do. -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-6038935671414339~4085536467" />
</application>
<queries>
<intent>
@@ -336,19 +336,64 @@ class AlarmScheduler(private val context: Context) {
}
}
/**
* The occurrence a "close this one" action is really acting on, never a
* future one.
*
* Reported on-device: pressing Posponer left the alarm snoozed for ~1444
* minutes (24h04m) instead of the configured few. The chain, all inside
* this file: [onAlarmFired] runs from the receiver BEFORE the ringing
* notification exists, and it persists `snoozeOriginMillis = null` plus a
* `triggerAtMillis` already advanced to TOMORROW by
* [computeNextTriggerMillis]. The snooze anchor was then plain
* `spec.snoozeOriginMillis ?: spec.triggerAtMillis`, so it picked up
* tomorrow. The old clamp (`if (target > now) target else now + minutes`)
* could not catch it: it only rescues anchors in the PAST, and an anchor
* +24h out sails straight through.
*
* [maxAheadMillis] is how far ahead an occurrence may legitimately sit for
* the calling surface: ~0 (just the shared imminence tolerance) for the
* ringing notification, but a full [PRE_NOTICE_MILLIS] for the pre-notice
* notification, whose occurrence has genuinely not happened yet.
*
* Mirrors `EstadoAlarmas._ocurrenciaSonando` on the Dart side, which was
* added in a9da855 for the exact same defect after 9c7cf4e had fixed only
* one of two adjacent callers. The native lane never got that guard.
* `lastHandledAtMillis` is the last fallback because [onAlarmFired] sets
* it to the occurrence that just rang -- note it is NOT purely native
* state (scheduleAlarm takes it from the Dart channel), so `now` has to
* remain the floor.
*/
private fun anchorOccurrenceMillis(
spec: NativeAlarmSpec,
now: Long,
maxAheadMillis: Long = 0L
): Long {
val limit = now + maxAheadMillis + IMMINENT_TOLERANCE_MILLIS
fun usable(candidate: Long?): Long? = candidate?.takeIf { it <= limit }
return usable(spec.snoozeOriginMillis)
?: usable(spec.triggerAtMillis)
?: usable(spec.lastHandledAtMillis)
?: now
}
/**
* Snoozes using the SAME anchor as [postponeNext] (Design 2.2): the
* occurrence time + minutes, clamped to now + minutes when the target is
* already past. Returns the resulting snooze so the caller can report it
* back to Flutter (single source of truth), or null if the spec is gone.
*
* The occurrence comes from [anchorOccurrenceMillis] with no forward
* allowance: this is the RINGING notification's button, so the occurrence
* it closes has already arrived.
*/
fun snooze(id: String, minutes: Int): NativeSnoozeResult? {
cancelAutoSilence(id)
val spec = readSpec(id) ?: return null
val safeMinutes = sanitizeSnoozeMinutes(minutes)
val occurrenceAt = spec.snoozeOriginMillis ?: spec.triggerAtMillis
val target = occurrenceAt + safeMinutes * 60_000L
val now = System.currentTimeMillis()
val occurrenceAt = anchorOccurrenceMillis(spec, now)
val target = occurrenceAt + safeMinutes * 60_000L
val snoozeUntil = if (target > now) target else now + safeMinutes * 60_000L
Log.d(
tag,
@@ -369,12 +414,24 @@ class AlarmScheduler(private val context: Context) {
)
}
/**
* Postpones from the PRE-NOTICE notification, whose occurrence has
* legitimately not arrived yet -- it is armed [PRE_NOTICE_MILLIS] ahead.
* So unlike [snooze] this allows an anchor that far forward, but no
* further: an anchor beyond that window is a spec already advanced to a
* later day, which is exactly the state that produced the reported ~24h
* snooze. See [anchorOccurrenceMillis].
*/
fun postponeNext(id: String, minutes: Int): Long? {
val spec = readSpec(id) ?: return null
val safeMinutes = sanitizeSnoozeMinutes(minutes)
val occurrenceAt = spec.snoozeOriginMillis ?: spec.triggerAtMillis
val target = occurrenceAt + safeMinutes * 60_000L
val now = System.currentTimeMillis()
val occurrenceAt = anchorOccurrenceMillis(
spec,
now,
maxAheadMillis = PRE_NOTICE_MILLIS
)
val target = occurrenceAt + safeMinutes * 60_000L
val snoozeUntil = if (target > now) target else now + safeMinutes * 60_000L
Log.d(
tag,
@@ -10,7 +10,6 @@ import android.content.pm.PackageManager
import android.media.AudioDeviceCallback
import android.media.AudioDeviceInfo
import android.media.AudioManager
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.media.audiofx.Visualizer
import android.app.AlarmManager
@@ -26,6 +25,7 @@ import android.util.Log
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.FileProvider
import com.ryanheise.audioservice.AudioServiceActivity
import es.freetimelab.pluriwave.fileactions.FileActionsHandler
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
@@ -269,10 +269,31 @@ class MainActivity : AudioServiceActivity() {
}
activeInstance = this
// fix/android-auto-musica-local: los cuatro metodos SAF que solo
// necesitan un ContentResolver viven en FileActionsHandler, dentro del
// paquete plugin `packages/pluriwave_file_actions`. Alli
// PluriWaveFileActionsPlugin los registra en TODOS los engines via
// GeneratedPluginRegistrant -- incluido el headless que audio_service
// crea para Android Auto, donde este configureFlutterEngine nunca
// corre.
//
// Este engine SI tiene Activity, asi que instala UN solo handler para
// todo el canal, superconjunto del del plugin: primero delega en el
// handler compartido (misma y unica implementacion) y, si este no
// reconoce el metodo, atiende sus propios metodos ligados a la
// Activity (picker SAF e intents de la carpeta de grabaciones).
//
// El orden esta garantizado: GeneratedPluginRegistrant corre DENTRO
// del constructor de FlutterEngine, y configureFlutterEngine solo
// puede ejecutarse despues, con el engine ya construido. Este handler
// siempre pisa al del plugin en una Activity, nunca al reves.
val fileActionsHandler = FileActionsHandler(applicationContext)
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
fileActionsChannel
).setMethodCallHandler { call, result ->
if (fileActionsHandler.manejar(call, result)) return@setMethodCallHandler
when (call.method) {
"openDirectory" -> {
val path = call.argument<String>("path")
@@ -327,53 +348,11 @@ class MainActivity : AudioServiceActivity() {
pendingMusicFolderResult = null
}
}
"listAudioChildren" -> {
val treeUri = call.argument<String>("treeUri")
val parentDocumentId = call.argument<String>("parentDocumentId") ?: ""
Log.d(
tag,
"file_actions.listAudioChildren treeUri=$treeUri parentDocumentId=$parentDocumentId"
)
if (treeUri.isNullOrBlank()) {
result.success(emptyList<Map<String, Any>>())
} else {
result.success(listAudioChildren(treeUri, parentDocumentId))
}
}
"resolvePlayableUri" -> {
val treeUri = call.argument<String>("treeUri")
val documentId = call.argument<String>("documentId")
Log.d(
tag,
"file_actions.resolvePlayableUri treeUri=$treeUri documentId=$documentId"
)
if (treeUri.isNullOrBlank() || documentId.isNullOrBlank()) {
result.success(null)
} else {
result.success(resolvePlayableUri(treeUri, documentId))
}
}
"hasPersistedPermission" -> {
val treeUri = call.argument<String>("treeUri")
Log.d(tag, "file_actions.hasPersistedPermission treeUri=$treeUri")
result.success(
if (treeUri.isNullOrBlank()) false else hasPersistedPermission(treeUri)
)
}
// ---- android-auto-local-music-phase2 (static review only) ----
"readAudioMetadataBatch" -> {
val treeUri = call.argument<String>("treeUri")
val documentIds = call.argument<List<String>>("documentIds") ?: emptyList()
Log.d(
tag,
"file_actions.readAudioMetadataBatch treeUri=$treeUri count=${documentIds.size}"
)
if (treeUri.isNullOrBlank()) {
result.success(emptyList<Map<String, Any?>>())
} else {
result.success(readAudioMetadataBatch(treeUri, documentIds))
}
}
// listAudioChildren / resolvePlayableUri /
// hasPersistedPermission / readAudioMetadataBatch los
// atiende FileActionsHandler arriba (item 3): no necesitan
// Activity, asi que tienen que poder registrarse tambien en
// un engine que no la tiene.
else -> result.notImplemented()
}
}
@@ -423,241 +402,6 @@ class MainActivity : AudioServiceActivity() {
super.onActivityResult(requestCode, resultCode, data)
}
/**
* Walks ONE level of the SAF tree rooted at [treeUri] (android-auto-local-music,
* static review only — Design "Lazy per-folder enumeration, never an
* eager tree dump"): [parentDocumentId] blank means the tree root
* itself, otherwise the given subfolder's documentId. Filters files to
* audio MIME types at the native layer (lean payload); each returned row
* also carries `mime` so the Dart side can re-validate via
* `esArchivoAudio` (defense-in-depth). Any query failure degrades to an
* empty list rather than throwing.
*/
private fun listAudioChildren(treeUri: String, parentDocumentId: String): List<Map<String, Any>> {
return try {
val parsedTree = Uri.parse(treeUri)
val parentId = parentDocumentId.ifBlank {
DocumentsContract.getTreeDocumentId(parsedTree)
}
val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(parsedTree, parentId)
val projection = arrayOf(
DocumentsContract.Document.COLUMN_DOCUMENT_ID,
DocumentsContract.Document.COLUMN_DISPLAY_NAME,
DocumentsContract.Document.COLUMN_MIME_TYPE
)
val resultado = mutableListOf<Map<String, Any>>()
contentResolver.query(childrenUri, projection, null, null, null)?.use { cursor ->
val idxDocId = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
val idxNombre = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
val idxMime = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_MIME_TYPE)
while (cursor.moveToNext()) {
val documentId = cursor.getString(idxDocId) ?: continue
val nombre = cursor.getString(idxNombre) ?: continue
val mime = cursor.getString(idxMime) ?: ""
val esDirectorio = mime == DocumentsContract.Document.MIME_TYPE_DIR
if (!esDirectorio && !mime.startsWith("audio/")) continue
resultado.add(
mapOf(
"documentId" to documentId,
"nombre" to nombre,
"esDirectorio" to esDirectorio,
"mime" to mime
)
)
}
}
resultado
} catch (error: Throwable) {
Log.e(tag, "file_actions.listAudioChildren failed treeUri=$treeUri parentDocumentId=$parentDocumentId", error)
emptyList()
}
}
/**
* Resolves a leaf [documentId] within [treeUri] to its playable
* `content://` URI (android-auto-local-music, static review only).
* Returns `null` on any failure instead of throwing.
*/
private fun resolvePlayableUri(treeUri: String, documentId: String): String? {
return try {
val parsedTree = Uri.parse(treeUri)
DocumentsContract.buildDocumentUriUsingTree(parsedTree, documentId).toString()
} catch (error: Throwable) {
Log.e(tag, "file_actions.resolvePlayableUri failed treeUri=$treeUri documentId=$documentId", error)
null
}
}
/**
* Checks whether [treeUri]'s read permission is still among
* [android.content.ContentResolver.getPersistedUriPermissions]
* (android-auto-local-music, static review only) — used for cold-start
* / revoked-permission detection (Spec "Permission revoked or never
* granted"). Returns `false` (never throws) on a malformed [treeUri] or
* any other failure.
*/
private fun hasPersistedPermission(treeUri: String): Boolean {
return try {
val parsed = Uri.parse(treeUri)
contentResolver.persistedUriPermissions.any { it.uri == parsed && it.isReadPermission }
} catch (error: Throwable) {
Log.e(tag, "file_actions.hasPersistedPermission failed treeUri=$treeUri", error)
false
}
}
/**
* Batched embedded-metadata extraction (android-auto-local-music-phase2,
* static review only — Design "Interfaces / Contracts"): for each of
* [documentIds], extracts title/artist/bitrate/sample-rate and the
* embedded picture via [extraerMetadatosPista]. Never throws across the
* channel boundary — a malformed [treeUri] (or any other unexpected
* failure) degrades the WHOLE call to `[]`; a per-entry failure is
* already isolated inside [extraerMetadatosPista].
*/
private fun readAudioMetadataBatch(treeUri: String, documentIds: List<String>): List<Map<String, Any?>> {
return try {
val parsedTree = Uri.parse(treeUri)
documentIds.map { documentId -> extraerMetadatosPista(parsedTree, documentId) }
} catch (error: Throwable) {
Log.e(tag, "file_actions.readAudioMetadataBatch failed treeUri=$treeUri", error)
emptyList()
}
}
/**
* Extracts one [documentId]'s embedded metadata via
* [MediaMetadataRetriever] (android-auto-local-music-phase2, static
* review only — mirrors [listAudioChildren]/[resolvePlayableUri]'s
* never-throws shape). `METADATA_KEY_SAMPLERATE` (raw key `38`, no
* public constant below API 31) is gated behind
* `Build.VERSION.SDK_INT >= 31` (Design ADR-5); every other field is
* available since API 10 and read unconditionally. A resolvable
* embedded picture is handed to [cachearArteEmbebido]; art-cache
* failures degrade that single field to `null` without failing the
* whole entry. On ANY failure for this [documentId] (unsupported
* format, permission edge case, corrupt file), the row degrades to an
* all-null-but-`documentId` entry instead of throwing —
* `retriever.release()` always runs via `finally`.
*/
private fun extraerMetadatosPista(parsedTree: Uri, documentId: String): Map<String, Any?> {
val retriever = MediaMetadataRetriever()
return try {
val documentUri = DocumentsContract.buildDocumentUriUsingTree(parsedTree, documentId)
retriever.setDataSource(this, documentUri)
val titulo = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)
val artista = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
val bitrate = retriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE)
?.toIntOrNull()
val sampleRate = if (Build.VERSION.SDK_INT >= 31) {
// METADATA_KEY_SAMPLERATE = 38 (API 31+, Design ADR-5); no
// public constant exists on this minSdk, so the raw key is
// used directly, guarded by the version check above.
retriever.extractMetadata(38)?.toIntOrNull()
} else {
null
}
val artUri = try {
retriever.embeddedPicture?.let { cachearArteEmbebido(documentId, it) }
} catch (error: Throwable) {
Log.e(
tag,
"file_actions.readAudioMetadataBatch embeddedPicture failed documentId=$documentId",
error
)
null
}
mapOf(
"documentId" to documentId,
"titulo" to titulo,
"artista" to artista,
"bitrate" to bitrate,
"sampleRate" to sampleRate,
"artUri" to artUri
)
} catch (error: Throwable) {
Log.e(
tag,
"file_actions.readAudioMetadataBatch entry failed documentId=$documentId",
error
)
mapOf(
"documentId" to documentId,
"titulo" to null,
"artista" to null,
"bitrate" to null,
"sampleRate" to null,
"artUri" to null
)
} finally {
try {
retriever.release()
} catch (_: Throwable) {
// release() failing is not actionable — the retriever is
// being discarded regardless.
}
}
}
/**
* Embedded-art cache write + LRU trim (android-auto-local-music-phase2,
* static review only — Design ADR-1). Writes [picture] bytes to
* `cacheDir/pluriwave_art/<hash(documentId)>` (skips the write when the
* file already exists, so re-parsing the same track reuses it), returns
* the `content://` URI served via the EXISTING
* `${applicationId}.fileprovider` authority
* (`AndroidManifest.xml:97-105`, `pluriwave_file_paths.xml`'s
* `cache-path path="."` — confirmed present, zero manifest changes
* needed) and trims `pluriwave_art/` via [trimArtCache]. `hash` uses
* SHA-256 hex because a raw `documentId` may contain `:`/`/`, which are
* illegal in filenames on most filesystems.
*/
private fun cachearArteEmbebido(documentId: String, picture: ByteArray): String? {
return try {
val artDir = File(cacheDir, "pluriwave_art").apply { mkdirs() }
val artFile = File(artDir, hashDocumentId(documentId))
if (!artFile.exists()) {
artFile.writeBytes(picture)
}
trimArtCache(artDir)
FileProvider.getUriForFile(this, "$packageName.fileprovider", artFile).toString()
} catch (error: Throwable) {
Log.e(tag, "file_actions.cachearArteEmbebido failed documentId=$documentId", error)
null
}
}
private fun hashDocumentId(documentId: String): String {
val digest = java.security.MessageDigest.getInstance("SHA-256")
val bytes = digest.digest(documentId.toByteArray(Charsets.UTF_8))
return bytes.joinToString("") { "%02x".format(it) }
}
/**
* LRU-by-`lastModified` trim of the embedded-art cache dir (Design
* ADR-1): after each write, keeps at most 256 files AND at most 32 MB
* total, deleting the OLDEST-by-mtime entries first. Kept as a
* trivially reviewable loop — these files are native-owned, so
* round-tripping names to Dart to pick deletions would add channel
* chatter with no testability gain (the `delete()` is native
* regardless, per ADR-1's rationale).
*/
private fun trimArtCache(artDir: File) {
val maxArchivos = 256
val maxBytes = 32L * 1024 * 1024
val archivos = artDir.listFiles()?.sortedByDescending { it.lastModified() }?.toMutableList()
?: return
var totalBytes = archivos.sumOf { it.length() }
while (archivos.isNotEmpty() && (archivos.size > maxArchivos || totalBytes > maxBytes)) {
val masViejo = archivos.removeAt(archivos.size - 1)
totalBytes -= masViejo.length()
masViejo.delete()
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
@@ -0,0 +1,44 @@
package es.freetimelab.pluriwave
/**
* Anchors the drawables that only Dart names, so the Android build cannot
* decide they are unused.
*
* These icons are handed to `audio_service` as plain strings
* (`MediaControl.custom(androidIcon: 'drawable/ic_auto_eq_on')`) and resolved
* at runtime through `getResources().getIdentifier(...)`. Nothing on the
* Android side of the build ever mentions them, so as far as the resource
* pipeline is concerned they are dead weight — and they were dropped from
* every release APK.
*
* The damage was not a missing icon. `getResourceId` returns 0 for a name it
* cannot find, `PlaybackStateCompat.CustomAction.Builder` throws on a 0 icon,
* and that throw aborts `AudioService.setState` before the media session is
* ever activated. Android Auto was left holding a frozen, inactive session:
* dead playback screen, a play button that never became pause, the app losing
* its pane to whichever app did have a live session, and audio that played
* "as if it were not the app". One absent file, four symptoms, from 31 July
* (commit 2540556) until this.
*
* Verified rather than assumed. Pulling the installed APK off the device and
* reading its resource table showed `ic_stat_pluriwave` present and both
* equalizer icons absent — and `ic_stat_pluriwave` is the one drawable of the
* three that Kotlin references directly (`R.drawable.ic_stat_pluriwave`, four
* call sites across the alarm notifications). That contrast is the whole
* diagnosis: a real `R.drawable` reference survives, a name that exists only
* inside a Dart string does not.
*
* So this object is not defensive tidiness — it is the reference that was
* missing. Any future drawable that Dart resolves by name must be added here
* AND to the resource guard in `.gitea/workflows/build.yml`, which reads the
* built APK's resource table and fails the build if one of them is gone.
*/
@Suppress("unused")
internal object RecursosResueltosPorNombre {
val anclados: IntArray =
intArrayOf(
R.drawable.ic_auto_eq_on,
R.drawable.ic_auto_eq_off,
R.drawable.ic_stat_pluriwave,
)
}
+33
View File
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Protects the drawables that only Dart names from the resource shrinker.
Flutter's own Gradle plugin turns shrinking on for every release build
(FlutterPlugin.kt: `releaseBuildType.isMinifyEnabled = true` and
`isShrinkResources = true`), regardless of what app/build.gradle.kts says.
The shrinker keeps what it can see referenced — and it cannot see
`MediaControl.custom(androidIcon: 'drawable/ic_auto_eq_on')`, because that
is a string inside Dart, resolved at runtime via
`getResources().getIdentifier(...)`. So it removed both equalizer icons
from every release APK.
The consequence was not a blank button. `getResourceId` returns 0 for a
name it cannot resolve, `PlaybackStateCompat.CustomAction.Builder` throws
on a 0 icon, and that throw aborts `AudioService.setState` before the media
session is activated — leaving Android Auto with a frozen, inactive
session. Dead playback screen, play that never became pause, the app losing
its pane to any app with a live session, and audio playing "as if it were
not the app". One shrunk file, four symptoms, from 31 July (commit 2540556).
Proven, not assumed: the installed APK was pulled off the device and its
resource table read. `ic_stat_pluriwave` was present, both equalizer icons
were not — and `ic_stat_pluriwave` is the only one of the three that Kotlin
references as a real `R.drawable`, from the alarm notifications. A genuine
reference survives shrinking; a name living in a Dart string does not.
ANY new drawable that Dart resolves by name must be listed here, and in the
resource guard in .gitea/workflows/build.yml, which reads the built APK's
resource table and fails the build if one of them went missing.
-->
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/ic_auto_eq_on,@drawable/ic_auto_eq_off,@drawable/ic_stat_pluriwave,@drawable/station_art_*" />
+4
View File
@@ -1,2 +1,6 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
+72 -6
View File
@@ -4,11 +4,15 @@ import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'estado/estado_busqueda.dart';
import 'estado/estado_ecualizador.dart';
import 'estado/estado_entitlement.dart';
import 'estado/estado_grabacion.dart';
import 'estado/estado_radio.dart';
import 'estado/estado_alarmas.dart';
import 'estado/estado_idioma.dart';
import 'estado/estado_navegacion.dart';
import 'servicios/servicio_anuncios.dart';
import 'servicios/servicio_compras.dart';
import 'widgets/banner_anuncio_superior.dart';
import 'l10n/display_names.dart';
import 'l10n/gen/app_localizations.dart';
import 'modelos/alarma_musical.dart';
@@ -31,8 +35,32 @@ import 'servicios/navegacion_auto.dart';
import 'servicios/servicio_alarmas_android.dart';
import 'servicios/servicio_dispositivo_audio.dart';
/// Extracted out of `_PaginaPrincipalState.build` (FIX 1, code review) so
/// the banner + status-bar-inset composition is unit-testable in isolation
/// — `_PaginaPrincipal` itself is library-private and constructs real
/// platform-backed services (see `app_test.dart`'s own comments), so it
/// cannot be safely widget-tested directly. Mirrors this file's existing
/// `@visibleForTesting` top-level extraction convention
/// (`main.dart`'s `orientacionesPara`/`aplicarPoliticaOrientacion`).
///
/// `BannerAnuncioSuperior` owns its OWN top `SafeArea` internally now (see
/// `banner_anuncio_superior.dart`) — this function deliberately does NOT
/// wrap it in one, since `SafeArea` reserves `MediaQuery.padding.top` even
/// around a zero-size collapsed child, which used to leave a permanent
/// blank status-bar-height strip for premium users and for free users
/// before the first ad finished loading.
@visibleForTesting
Widget construirCuerpoPrincipal({required Widget contenido}) {
return Column(
children: [
const BannerAnuncioSuperior(),
Expanded(child: SafeArea(top: false, child: contenido)),
],
);
}
class PluriWaveApp extends StatelessWidget {
const PluriWaveApp({super.key, this.prefs, this.fuenteAuto});
const PluriWaveApp({super.key, this.prefs, this.fuenteAuto, this.compras});
/// Single SharedPreferences instance resolved in main() (S3-R4) and
/// injected into every state/service.
@@ -44,16 +72,31 @@ class PluriWaveApp extends StatelessWidget {
/// [PluriWaveApp] without it.
final FuenteEmisorasAuto? fuenteAuto;
/// Purchase I/O port (iap-freemium-unlock, Design ADR-2). Optional and
/// `null` by default — mirrors [fuenteAuto]'s injection shape, so every
/// pre-existing test that constructs [PluriWaveApp] without it never
/// touches the real `in_app_purchase` plugin channel. `main.dart` wires
/// the real [ServicioComprasPlayBilling].
final PuertoCompras? compras;
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
// iap-freemium-unlock (Design ADR-3): registered FIRST so every
// provider below can read it via `context.read` inside a lazy
// `esPremium` closure — `MultiProvider` nests top-to-bottom, so only
// a provider ABOVE a given one is reachable from its own `create`.
ChangeNotifierProvider(
create: (_) => EstadoEntitlement(prefs: prefs, compras: compras),
),
ChangeNotifierProvider(
create:
(_) => EstadoRadio(
(context) => EstadoRadio(
prefs: prefs,
dispositivoAudio: ServicioDispositivoAudioReal(),
fuenteAuto: fuenteAuto,
esPremium: () => context.read<EstadoEntitlement>().esPremium,
),
),
// Domain notifiers (S4-R1/R2/R3). Created and disposed by EstadoRadio
@@ -69,13 +112,28 @@ class PluriWaveApp extends StatelessWidget {
ListenableProvider<EstadoBusqueda>(
create: (context) => context.read<EstadoRadio>().busqueda,
),
ChangeNotifierProvider(create: (_) => EstadoAlarmas(prefs: prefs)),
ChangeNotifierProvider(
create:
(context) => EstadoAlarmas(
prefs: prefs,
esPremium: () => context.read<EstadoEntitlement>().esPremium,
),
),
ChangeNotifierProvider(
create: (_) => EstadoIdioma(sharedPreferences: prefs),
),
// Design ADR-8: root-to-root navigation state. `_PaginaPrincipal`
// watches this instead of owning `_indice` locally.
ChangeNotifierProvider(create: (_) => EstadoNavegacionRaiz()),
// iap-freemium-unlock (Design "Interfaces / Contracts", ADR-6): a
// plain (non-notifier) `Provider` — session-scoped ad state, never
// rebuilds the widget tree itself.
Provider<ServicioAnuncios>(
create:
(context) => ServicioAnuncios(
esPremium: () => context.read<EstadoEntitlement>().esPremium,
),
),
],
child: Consumer<EstadoIdioma>(
builder:
@@ -218,9 +276,17 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal>
final indice = navegacion.indice;
return PluriWaveScaffold(
body: SafeArea(
top: false,
child: AnimatedSwitcher(
// ad-display spec "Persistent Top Banner, Never Overlapping Content"
// (design.md ADR-6): a `Column` sibling, NEVER a `Stack`/overlay — the
// banner RESERVES its own space above the existing body instead of
// covering any of it. `BannerAnuncioSuperior` itself collapses to
// `SizedBox.shrink()` (zero layout impact) for premium/unloaded, and
// (FIX 1, code review) owns its OWN top `SafeArea` internally — this
// level no longer wraps it in an unconditional `SafeArea`, which used
// to reserve `MediaQuery.padding.top` even for a zero-size collapsed
// child, leaving a permanent blank status-bar-height strip.
body: construirCuerpoPrincipal(
contenido: AnimatedSwitcher(
duration: context.pluriMotion.normal,
switchInCurve: Curves.easeOutCubic,
switchOutCurve: Curves.easeInCubic,
+151 -28
View File
@@ -9,15 +9,31 @@ import '../servicios/servicio_alarmas.dart';
import '../servicios/servicio_alarmas_android.dart';
import '../servicios/servicio_programacion_alarmas.dart';
/// Distinct "limit reached" signal (Design ADR-5, freemium-gating spec
/// "Alarm Count Cap At 5"): kept SEPARATE from [EstadoAlarmas.error], which
/// stays reserved for native scheduling failures — overloading it would
/// surface a free-tier limit as a scheduling failure in `app.dart`'s global
/// snackbar path.
enum ResultadoGuardarAlarma { guardada, limiteAlcanzado }
class EstadoAlarmas extends ChangeNotifier {
EstadoAlarmas({
ServicioAlarmas? servicio,
PuertoAlarmasAndroid? android,
SharedPreferences? prefs,
bool iniciarAutomaticamente = true,
// iap-freemium-unlock (Design ADR-3): entitlement query, mirroring
// `EstadoGrabacion`'s `emisoraActual` callback-injection shape rather
// than a direct `EstadoEntitlement` dependency (this notifier must stay
// constructible with zero widget-tree/Provider context). REQUIRED on
// purpose: an optional parameter with any default lets a forgotten
// wiring compile and silently pick a tier, and no test can catch that.
// Callers must state the entitlement source explicitly.
required bool Function() esPremium,
}) : servicio = servicio ?? ServicioAlarmas(prefs: prefs),
android = android ?? ServicioAlarmasAndroid(),
_prefs = prefs {
_prefs = prefs,
_esPremium = esPremium {
// Decision 2.1 (snooze sync): the native layer reports its own snoozes
// back through alarmFired/snoozed; record them here so the Flutter
// config stays the single source of truth.
@@ -32,8 +48,12 @@ class EstadoAlarmas extends ChangeNotifier {
final ServicioAlarmas servicio;
final PuertoAlarmasAndroid android;
final SharedPreferences? _prefs;
final bool Function() _esPremium;
static const _keyExencionBateriaSolicitada = 'bateria_exencion_solicitada';
/// Free-tier alarm cap (freemium-gating spec "Alarm Count Cap At 5").
static const maxAlarmasFree = 5;
List<AlarmaMusical> _alarmas = [];
List<RangoVacaciones> _vacaciones = [];
List<ExcepcionAlarma> _excepciones = [];
@@ -101,7 +121,26 @@ class EstadoAlarmas extends ChangeNotifier {
}
}
Future<void> guardarAlarma(AlarmaMusical alarma) async {
/// Pure query (freemium-gating spec "Alarm Count Cap At 5"): whether a NEW
/// alarm may be created right now. Counts ALL alarms regardless of
/// `activa` (Spec "6th alarm creation is blocked" — "any enabled state").
/// Always `true` for premium (no cap). Editing an existing id is never
/// subject to this — see [guardarAlarma]'s own new-vs-edit check.
bool puedeCrearAlarma() => _esPremium() || _alarmas.length < maxAlarmasFree;
Future<ResultadoGuardarAlarma> guardarAlarma(AlarmaMusical alarma) async {
// Gate BEFORE any native scheduling attempt (freemium-gating spec "6th
// alarm creation is blocked": "no native scheduling is attempted").
// Editing an alarm that already exists (by id) is NEVER capped — only
// genuinely NEW creation counts against the limit (Spec "Editing an
// existing alarm is unaffected", grandfathering).
final esAlarmaNueva = !_alarmas.any((a) => a.id == alarma.id);
if (esAlarmaNueva && !puedeCrearAlarma()) {
debugPrint(
'[PluriWave][alarmas] guardar bloqueado por limite free id=${alarma.id}',
);
return ResultadoGuardarAlarma.limiteAlcanzado;
}
debugPrint(
'[PluriWave][alarmas] guardar id=${alarma.id} activa=${alarma.activa} hora=${alarma.hora}:${alarma.minuto} tipo=${alarma.tipoProgramacion.name}',
);
@@ -125,6 +164,7 @@ class EstadoAlarmas extends ChangeNotifier {
await _registrarFalloProgramacion(alarma.id);
}
notifyListeners();
return ResultadoGuardarAlarma.guardada;
}
Future<void> refrescarProgramacion() async {
@@ -316,29 +356,74 @@ class EstadoAlarmas extends ChangeNotifier {
notifyListeners();
}
Future<void> posponerAlarma(AlarmaMusical alarma, int minutos) async {
_error = null;
// The snooze anchors to the occurrence that is RINGING — never a future
// one. When the native fire works, the fire-time sync advances
// proximaEjecucion to the NEXT day before the user can even tap snooze,
// so anchoring to proximaEjecucion re-armed "posponer 3" a full day out
// (observed on-device: snooze armed for tomorrow 23:02). The ringing
// occurrence is the newest candidate not meaningfully in the future:
// snoozeOrigen (a re-snooze keeps the original anchor), then
// proximaEjecucion (watchdog path: still today's just-due occurrence),
// then ultimaEjecucionGestionada (native-fire path: the sync recorded
// the ringing occurrence there), then now.
/// The occurrence that is ACTUALLY ringing right now — the anchor both
/// ring-screen actions (Posponer and Detener) must close.
///
/// It is NEVER a future occurrence. When the native fire works, the
/// fire-time sync advances `proximaEjecucion` to the next one before the
/// user can even reach the ring screen, so taking `proximaEjecucion`
/// unguarded closes an occurrence that has not happened yet. For snooze
/// that showed up as "posponer 3" arming a full day out (observed
/// on-device: tomorrow 23:02). For stop it was worse and silent: the
/// future occurrence was recorded in `ultimaEjecucionGestionada`, which
/// `ServicioProgramacionAlarmas._esValida` then rejects for real — so a
/// Monday-only alarm stopped today simply never rang next Monday, and
/// every sibling alarm outranked it in the "next alarm" banner.
///
/// The candidates, newest first, each gated on "not meaningfully in the
/// future": [AlarmaMusical.snoozeOrigen] (a re-snooze keeps the original
/// anchor), then [AlarmaMusical.proximaEjecucion] (watchdog path: still
/// today's just-due occurrence), then
/// [AlarmaMusical.ultimaEjecucionGestionada] (native-fire path: the sync
/// recorded the ringing occurrence there), then now.
///
/// ONE helper for BOTH callers on purpose. This guard was written for
/// `posponerAlarma` alone (`9c7cf4e`) while `finalizarEjecucion` sat ten
/// lines below with the identical hazard and no guard, and it stayed that
/// way until a user lost a whole week of alarms. Do not re-inline it.
DateTime _ocurrenciaSonando(AlarmaMusical? alarma) =>
_ocurrenciaValida(alarma);
/// How far ahead the PRE-NOTICE notification's occurrence may legitimately
/// sit: it is armed exactly this far before the alarm, so between the
/// reminder appearing and the user tapping it, the occurrence has not
/// happened yet and rejecting it would be wrong.
///
/// Mirrors `AlarmScheduler.PRE_NOTICE_MILLIS` (30 min). Both sides must
/// agree or one of them starts discarding perfectly good anchors.
static const ventanaPreaviso = Duration(minutes: 30);
/// [_ocurrenciaSonando] generalized with a forward allowance, and with an
/// externally-supplied [propuesta] taking priority when it survives the
/// same check.
///
/// [propuesta] is what the NATIVE side reported as the occurrence its
/// notification was about. It is trusted first — it is better evidence than
/// anything reconstructed here — but only after being validated, because it
/// can arrive as a fallback the caller invented (`app.dart` substitutes
/// `alarma.proximaEjecucion` when the native event carries no occurrence,
/// and that field may already point at tomorrow).
DateTime _ocurrenciaValida(
AlarmaMusical? alarma, {
DateTime? propuesta,
Duration margen = Duration.zero,
}) {
final ahora = servicio.ahora();
final limite = ahora.add(
ServicioProgramacionAlarmas.toleranciaDisparoInminente,
margen + ServicioProgramacionAlarmas.toleranciaDisparoInminente,
);
DateTime? sonando(DateTime? candidata) =>
candidata != null && !candidata.isAfter(limite) ? candidata : null;
final ejecucion =
sonando(alarma.snoozeOrigen) ??
sonando(alarma.proximaEjecucion) ??
sonando(alarma.ultimaEjecucionGestionada) ??
return sonando(propuesta) ??
sonando(alarma?.snoozeOrigen) ??
sonando(alarma?.proximaEjecucion) ??
sonando(alarma?.ultimaEjecucionGestionada) ??
ahora;
}
Future<void> posponerAlarma(AlarmaMusical alarma, int minutos) async {
_error = null;
final ejecucion = _ocurrenciaSonando(alarma);
debugPrint(
'[PluriWave][alarmas] posponer id=${alarma.id} minutos=$minutos ejecucion=${ejecucion.toIso8601String()}',
);
@@ -364,6 +449,24 @@ class EstadoAlarmas extends ChangeNotifier {
notifyListeners();
}
/// "Posponer" on the PRE-NOTICE notification.
///
/// Reported on-device: this left the alarm snoozed for 1400+ minutes — a
/// whole day — instead of the configured few. The native lane got its guard
/// in 7054a4c, but Dart runs AFTERWARDS on this path (the receiver's
/// `postponeNext` fires, then `startActivity`, then this) and persists +
/// reschedules, so whatever it computes is the value that survives. It was
/// the last snooze path in the codebase with NO occurrence guard at all:
/// it took [ejecucion] on faith and turned it straight into the next alarm.
///
/// And [ejecucion] is not trustworthy: `app.dart` falls back to
/// `alarma.proximaEjecucion` whenever the native event carries no
/// occurrence, and that field can already point at tomorrow.
///
/// Validated through [_ocurrenciaValida] with a [ventanaPreaviso]
/// allowance — unlike the ringing-screen paths this occurrence legitimately
/// has NOT arrived yet, which is exactly why `_ocurrenciaSonando` could not
/// simply be reused here.
Future<void> posponerProximaDesdePreaviso(
AlarmaMusical alarma,
int minutos,
@@ -371,14 +474,23 @@ class EstadoAlarmas extends ChangeNotifier {
) async {
_error = null;
final seguros = _snoozeSeguro(minutos);
final snoozeHasta = ejecucion.add(Duration(minutes: seguros));
final ocurrencia = _ocurrenciaValida(
alarma,
propuesta: ejecucion,
margen: ventanaPreaviso,
);
final snoozeHasta = ocurrencia.add(Duration(minutes: seguros));
debugPrint(
'[PluriWave][alarmas] posponer desde preaviso id=${alarma.id} minutos=$seguros ejecucion=${ejecucion.toIso8601String()} hasta=${snoozeHasta.toIso8601String()}',
'[PluriWave][alarmas] posponer desde preaviso id=${alarma.id} minutos=$seguros propuesta=${ejecucion.toIso8601String()} ocurrencia=${ocurrencia.toIso8601String()} hasta=${snoozeHasta.toIso8601String()}',
);
await android.ocultarNotificacionAlarma(alarma.id);
final config = await servicio.posponerEjecucionHasta(
alarma.id,
ejecucion,
// The VALIDATED occurrence, not the raw parameter: this becomes both
// `snoozeOrigen` and `ultimaEjecucionGestionada`, so passing the
// unchecked value here would poison the very state a9da855/0430059
// exist to keep clean.
ocurrencia,
snoozeHasta,
);
_aplicar(config);
@@ -401,11 +513,11 @@ class EstadoAlarmas extends ChangeNotifier {
debugPrint('[PluriWave][alarmas] finalizar ejecucion id=$alarmaId');
_error = null;
final alarma = _buscarAlarma(alarmaId);
final ejecucion =
alarma?.snoozeOrigen ??
alarma?.proximaEjecucion ??
alarma?.snoozeHasta ??
DateTime.now();
// Same anchor as posponerAlarma, through the same helper: closing a
// future occurrence here marks it handled, and _esValida then skips it
// for real -- the alarm silently never rings that day. See
// [_ocurrenciaSonando].
final ejecucion = _ocurrenciaSonando(alarma);
await android.ocultarNotificacionAlarma(alarmaId);
// Stop/Snooze Result Verification (SS-2a/SS-2b): the Stop path calls the
// id-agnostic fail-safe stop directly (it always targets whatever is
@@ -435,9 +547,20 @@ class EstadoAlarmas extends ChangeNotifier {
notifyListeners();
}
Future<void> crearRangoVacaciones(RangoVacaciones rango) async {
/// Full premium gate (freemium-gating spec "Gated Feature Set (Exactly
/// 4)" — alarm vacations, unlike the alarm cap above, are gated entirely,
/// not counted): returns `false` without persisting anything when the
/// caller is free tier.
Future<bool> crearRangoVacaciones(RangoVacaciones rango) async {
if (!_esPremium()) {
debugPrint(
'[PluriWave][alarmas] crear vacaciones bloqueado (free) id=${rango.id}',
);
return false;
}
final nuevos = [..._vacaciones, rango];
await guardarVacaciones(nuevos);
return true;
}
Future<void> eliminarRangoVacaciones(String id) async {
+113 -1
View File
@@ -37,7 +37,9 @@ class EstadoEcualizador extends ChangeNotifier {
_presetsPersonalizadosService =
presetsPersonalizadosService ?? ServicioPresetsPersonalizados(),
_dispositivoAudio = dispositivoAudio,
_emisoraActualUuid = emisoraActualUuid ?? (() => null);
_emisoraActualUuid = emisoraActualUuid ?? (() => null) {
_escucharCambiosEqDesdeHandler();
}
final ServicioAudio audio;
final ServicioEcualizador servicio;
@@ -84,6 +86,27 @@ class EstadoEcualizador extends ChangeNotifier {
StreamSubscription<DispositivoAudio>? _deviceSub;
Future<void>? _refrescoEnCurso;
/// Catches a car/notification-initiated EQ change that bypasses this
/// class entirely (eq-sync-superficies): `accionEqToggle` calls
/// `PluriWaveAudioHandler.setEcualizadorActivo` directly, and
/// `seleccionarPresetEqPorMediaId` calls `aplicarPreset` directly — both
/// mutate ONLY the handler's own `_ecualizadorActivo`/`_presetActual`
/// fields, never [audio]'s owner ([EstadoEcualizador]). Mirrors the exact
/// shape `EstadoRadio._escucharErroresReproduccion` already uses for the
/// equivalent `playFromMediaId` gap: on every [ServicioAudio.estadoStream]
/// tick (which the handler already re-emits on any EQ change via
/// `_actualizarControlesEq()`, regardless of who triggered it), compare
/// the handler's current EQ state against our cached copy and adopt it on
/// divergence.
///
/// Since eq-estado-unico this is a DISPLAY concern only. The handler owns
/// the flag and persists it itself, so this subscription no longer closes
/// a persistence gap — it just keeps the phone's toggle showing what the
/// engine is really doing. It also cannot be the fix on its own: it exists
/// only while an [EstadoEcualizador] does, and the headless Android Auto
/// engine that produced the bug report never builds one.
StreamSubscription<EstadoReproduccion>? _suscripcionEstadoAudioEq;
PresetEcualizador get presetActual => _presetActual;
PresetEcualizador get presetPrincipal => _presetPrincipal;
bool get activo => _activo;
@@ -337,6 +360,63 @@ class EstadoEcualizador extends ChangeNotifier {
notifyListeners();
}
/// Subscribes to [ServicioAudio.estadoStream] to catch a
/// car/notification-initiated EQ change (see [_suscripcionEstadoAudioEq]
/// doc for the full rationale).
void _escucharCambiosEqDesdeHandler() {
_suscripcionEstadoAudioEq = audio.estadoStream.listen((_) {
unawaited(_resincronizarConHandler());
});
}
/// Compares the handler's live EQ state ([ServicioAudio.ecualizadorActivo],
/// [ServicioAudio.presetActual]) against our cached [_activo]/
/// [_presetActual] and adopts the handler's value on divergence.
///
/// Deliberately never calls back into [audio] here (no
/// `setEcualizadorActivo`/`aplicarPreset`): doing so would re-trigger the
/// handler's own `_actualizarControlesEq()` re-push, which would tick
/// [ServicioAudio.estadoStream] again and re-enter this method forever.
/// Only a local field write and [notifyListeners] happen here, so a
/// divergence is resolved in a single pass.
///
/// It is now a PURE UI ADOPT — it does not persist (eq-estado-unico item
/// B). `PluriWaveAudioHandler` writes its own toggle through the port
/// `registrarHandler` injects, so the value is saved on every engine
/// rather than only on one that happens to have built a widget tree. This
/// method could never have been the owner of that fact: it only runs while
/// an [EstadoEcualizador] exists, and on the headless Android Auto engine
/// behind the bug report none ever does.
///
/// Wrapped in try/catch like every other handler-facing read in this
/// class (e.g. [_sembrarDispositivoActual]): a test double or an
/// unexpected platform state that makes [audio]'s EQ getters unavailable
/// must never crash the stream subscription — it just skips this tick.
Future<void> _resincronizarConHandler() async {
try {
final activoHandler = audio.ecualizadorActivo;
final presetHandler = audio.presetActual;
final activoDiverge = activoHandler != _activo;
final presetDiverge = presetHandler != _presetActual;
if (!activoDiverge && !presetDiverge) return;
if (activoDiverge) {
// Display-only adopt: the handler already persisted this value
// through its own write port before it ever reached us. See the
// doc above.
_activo = activoHandler;
}
if (presetDiverge) {
_presetActual = presetHandler;
}
notifyListeners();
} catch (_) {
// See doc above — never let a resync failure crash the app.
}
}
/// Applies [preset] to the audio engine and tracks it as current
/// WITHOUT persisting it (used when switching stations).
Future<void> aplicarPresetActivo(PresetEcualizador preset) async {
@@ -583,12 +663,29 @@ class EstadoEcualizador extends ChangeNotifier {
/// Each step then re-checks [_activo]: a newer tap that landed mid-flight
/// owns the outcome, and this superseded call must not apply a preset or
/// persist a value the user has already changed their mind about.
///
/// The handler can also REFUSE the change: when the native `setEnabled`
/// throws, `PluriWaveAudioHandler._aplicarEcualizadorActivo` rolls its own
/// flag back and skips its persistence write, so the value we optimistically
/// published never happened. Reading [ServicioAudio.ecualizadorActivo] back
/// (the handler is the single owner of the flag — eq-estado-unico) is how we
/// learn that: on divergence we adopt the handler's real value and return
/// WITHOUT persisting, instead of showing a lie and writing a rejected value
/// to disk that would resurrect it on the next start. The supersede check
/// runs FIRST so a newer tap still owns the outcome; the read-back only
/// speaks for a call nobody overtook.
Future<void> cambiarActivo(bool activo) async {
_activo = activo;
notifyListeners();
await audio.setEcualizadorActivo(activo);
if (_activo != activo) return;
final aceptado = audio.ecualizadorActivo;
if (aceptado != activo) {
_activo = aceptado;
notifyListeners();
return;
}
if (activo) {
await audio.aplicarPreset(_presetActual);
if (_activo != activo) return;
@@ -627,12 +724,21 @@ class EstadoEcualizador extends ChangeNotifier {
/// Replaces the whole EQ configuration (backup import path): persists it,
/// re-applies the preset effective for the current station and notifies.
///
/// [activo] is the imported on/off toggle (S4-R4/eq-export-toggle). When
/// `null` — an old backup with no `ecualizadorActivo` field — the CURRENT
/// toggle is left untouched: an absent flag must never flip the user's live
/// setting to an arbitrary value. When non-null, applies it through
/// [cambiarActivo], the same path a manual toggle uses, so the import
/// persists it AND pushes it to the live audio engine instead of just
/// updating [_activo] in memory.
Future<void> importarConfiguracion({
required PresetEcualizador principal,
required Map<String, PresetEcualizador> porEmisora,
Map<String, PresetEcualizador>? presetsDispositivo,
Map<String, PresetEcualizador>? presetsMatriz,
bool? eqMultiDeviceEnabled,
bool? activo,
}) async {
_presetPrincipal = principal;
_presetsEmisoraMap
@@ -667,12 +773,18 @@ class EstadoEcualizador extends ChangeNotifier {
final presetEfectivoActual =
uuid == null ? _presetPrincipal : _resolverPresetActivo();
await aplicarPresetActivo(presetEfectivoActual);
if (activo != null) {
await cambiarActivo(activo);
}
notifyListeners();
}
@override
void dispose() {
_deviceSub?.cancel();
_suscripcionEstadoAudioEq?.cancel();
super.dispose();
}
}
+193
View File
@@ -0,0 +1,193 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../servicios/servicio_audio.dart' show invalidarArbolAuto;
import '../servicios/servicio_compras.dart';
/// Versioned persistence key (Design ADR-1) for the permanent, non-consumable
/// premium unlock. Older builds that predate this key simply never read it —
/// no migration needed (Rollout "Versioned key ... is ignored by older
/// builds").
const _keyPremium = 'compra_premium_v1';
/// Headless-safe entitlement read (Design ADR-1, Spec "Headless-Safe
/// Entitlement Read"): resolves the persisted premium flag directly from
/// prefs, with NO `BuildContext`/`Provider` dependency. Mirrors
/// `FuenteMusicaLocalAutoImpl._resolverPrefs()`'s
/// inject-or-`getInstance()` convention (`musica_local_auto.dart:163`) —
/// this is what `PluriWaveAudioHandler` calls, since it registers before
/// `runApp` and no widget tree (therefore no `Provider`) exists yet.
///
/// Absent key = free tier (Rollout "Additive and prefs-backed; absent key =
/// free"). Never throws — a `SharedPreferences.getInstance()` failure would
/// propagate here exactly like the persisted read failing, which the caller
/// (Design ADR-2 "fail-open") must treat as "trust the last known state",
/// not this function's job to catch.
Future<bool> esPremiumPersistido({SharedPreferences? prefs}) async {
final resueltas = prefs ?? await SharedPreferences.getInstance();
return resueltas.getBool(_keyPremium) ?? false;
}
/// User-facing, non-error-text outcomes [EstadoEntitlement] can expose (FIX
/// 3, code review): the UI layer (`hoja_premium.dart`) has no BuildContext
/// here, so this file never carries localized/user-facing STRINGS itself —
/// only this typed signal, mapped to a localized message by the widget.
/// Cleared back to `null` once consumed ([EstadoEntitlement.consumirResultadoUsuario]).
enum ResultadoEntitlementUsuario {
/// A purchase or restore attempt failed (network, billing error, product
/// not yet available in the store, etc). This NEVER carries the raw
/// exception/developer string from [EventoCompra.mensaje] — the UI maps
/// this enum value to ONE generic localized message, never the internal
/// diagnostic text.
error,
/// [EstadoEntitlement.restaurar] completed successfully but found nothing
/// to restore. Distinct from [error]: an expected, non-error outcome
/// (Spec "Restore Purchases" — "finds nothing -> stays free tier with a
/// clear non-error result").
restauracionSinCompras,
}
/// Cross-cutting entitlement notifier (Design ADR-1), idiomatic
/// `EstadoIdioma`-shaped `ChangeNotifier`: UI layers `context.watch`/`read`
/// this; headless callers (Android Auto) use [esPremiumPersistido] instead,
/// since no `Provider` exists on that path.
class EstadoEntitlement extends ChangeNotifier {
EstadoEntitlement({SharedPreferences? prefs, PuertoCompras? compras})
: _prefs = prefs,
_compras = compras {
final flujo = _compras;
if (flujo != null) {
_comprasSub = flujo.eventos.listen(_alRecibirEvento);
}
_cargar();
}
/// The single non-consumable product id (Design "Interfaces / Contracts"),
/// re-exported here so UI/paywall code depends on ONE canonical constant
/// rather than reaching into `servicio_compras.dart` for it.
static const idProducto = ServicioComprasPlayBilling.idProducto;
final SharedPreferences? _prefs;
final PuertoCompras? _compras;
StreamSubscription<EventoCompra>? _comprasSub;
bool _esPremium = false;
bool _compraEnCurso = false;
ResultadoEntitlementUsuario? _resultadoUsuario;
bool get esPremium => _esPremium;
bool get compraEnCurso => _compraEnCurso;
/// FIX 3 (code review): the user-facing signal for a failed purchase/
/// restore, or a restore that found nothing. `null` when there is nothing
/// to show — see [consumirResultadoUsuario].
ResultadoEntitlementUsuario? get resultadoUsuario => _resultadoUsuario;
/// Clears [resultadoUsuario] once the UI has consumed/displayed it.
/// A no-op (no extra notification) if there is nothing to clear.
void consumirResultadoUsuario() {
if (_resultadoUsuario == null) return;
_resultadoUsuario = null;
notifyListeners();
}
Future<void> _cargar() async {
final prefs = await _resolverPrefs();
final premium = prefs.getBool(_keyPremium) ?? false;
if (premium != _esPremium) {
_esPremium = premium;
}
notifyListeners();
}
Future<SharedPreferences> _resolverPrefs() async =>
_prefs ?? SharedPreferences.getInstance();
/// Starts the purchase flow (Spec "Successful purchase"). A no-op when
/// already premium (Spec "Already-purchased attempt is idempotent") — no
/// duplicate charge is even attempted.
Future<void> comprar() async {
if (_esPremium) return;
final compras = _compras;
if (compras == null) return;
_compraEnCurso = true;
// FIX 3 (code review): a fresh attempt clears any stale result left over
// from a previous failed attempt, so the UI never shows an outdated
// error/confirmation across two unrelated attempts.
_resultadoUsuario = null;
notifyListeners();
await compras.comprar();
}
/// Re-queries Play Billing for a prior purchase (Spec "Restore Purchases").
Future<void> restaurar() async {
final compras = _compras;
if (compras == null) return;
_compraEnCurso = true;
_resultadoUsuario = null;
notifyListeners();
await compras.restaurar();
}
Future<void> _alRecibirEvento(EventoCompra evento) async {
switch (evento.tipo) {
case TipoEventoCompra.comprada:
case TipoEventoCompra.restaurada:
await _desbloquear();
case TipoEventoCompra.cancelada:
// Spec "Purchase cancelled or failed": a user-INITIATED cancel
// stays free tier with no error surfaced — just stop the in-flight
// spinner. Not a failure, so no [resultadoUsuario] either.
_compraEnCurso = false;
notifyListeners();
case TipoEventoCompra.noEncontrada:
// FIX 3 (code review): "Restore finds nothing" is an expected,
// NON-error outcome (Spec "Restore Purchases") but `hoja_premium.dart`
// had zero feedback for it — the spinner just stopped with no
// confirmation. Distinct signal from [TipoEventoCompra.error].
_compraEnCurso = false;
_resultadoUsuario = ResultadoEntitlementUsuario.restauracionSinCompras;
notifyListeners();
case TipoEventoCompra.error:
// Fail-open (Design ADR-2): an error NEVER writes `false` over an
// already-premium flag, and never invents a `true` for a free user
// either — the persisted flag from `_cargar()` is left untouched.
//
// FIX 3 (code review): [EventoCompra.mensaje] (raw exception/
// developer text, e.g. "Producto no encontrado en Play Console") is
// DELIBERATELY discarded here — only the typed enum crosses into
// [resultadoUsuario], never the raw string. `hoja_premium.dart` maps
// it to ONE generic localized message.
_compraEnCurso = false;
_resultadoUsuario = ResultadoEntitlementUsuario.error;
notifyListeners();
case TipoEventoCompra.pendiente:
_compraEnCurso = true;
notifyListeners();
}
}
Future<void> _desbloquear() async {
final yaEraPremium = _esPremium;
_esPremium = true;
_compraEnCurso = false;
final prefs = await _resolverPrefs();
await prefs.setBool(_keyPremium, true);
notifyListeners();
if (!yaEraPremium) {
// Orchestrator-resolved open question (design.md): actively
// invalidate the Android Auto browse cache on the free -> premium
// transition, rather than waiting for the head unit's own re-bind.
invalidarArbolAuto();
}
}
@override
void dispose() {
_comprasSub?.cancel();
super.dispose();
}
}
+51 -4
View File
@@ -18,14 +18,44 @@ import '../servicios/servicio_grabacion_radio.dart';
/// `EstadoRadio` consumers (S4-R5). Playback orchestration (stop recording on
/// pause/stop/station switch) stays in `EstadoRadio`, which keeps a reference
/// to this notifier.
/// Whether [emisora] is something the recorder can actually capture: a live
/// network stream.
///
/// The recorder opens the URL as an HTTP stream and writes the bytes to disk,
/// so anything else fails inside the HTTP client with a message no user can
/// act on ("Unsupported scheme 'content' in URI content://...").
///
/// This is not hypothetical tidiness. `PluriWaveAudioHandler._cambiarFuente`
/// sets `emisoraActual` for EVERY source it plays, so a local MP3 shows up
/// here as an `Emisora` whose `url` is the `content://` document URI it was
/// opened from. Recording a local file makes no sense anyway — it is already
/// on the device.
bool esEmisoraGrabable(Emisora emisora) {
final esquema = Uri.tryParse(emisora.url)?.scheme.toLowerCase();
return esquema == 'http' || esquema == 'https';
}
/// Distinct outcome signal for [EstadoGrabacion.iniciar] (freemium-gating
/// spec "Recording Start Gated"): [requierePremium] is NOT surfaced through
/// [EstadoGrabacion.iniciar]'s existing `alError` sink — the caller must
/// react by opening the paywall, a different UI than a plain error snackbar.
enum ResultadoIniciarGrabacion { iniciada, requierePremium, error }
class EstadoGrabacion extends ChangeNotifier {
EstadoGrabacion({
ServicioGrabacionRadio? servicio,
Emisora? Function()? emisoraActual,
void Function(String mensaje)? alError,
// iap-freemium-unlock (Design ADR-3): entitlement query, mirroring
// [_emisoraActual]'s callback-injection shape. REQUIRED on purpose: an
// optional parameter with any default lets a forgotten wiring compile
// and silently pick a tier, and no test can catch that. Callers must
// state the entitlement source explicitly.
required bool Function() esPremium,
}) : servicio = servicio ?? ServicioGrabacionRadio(),
_emisoraActual = emisoraActual ?? (() => null),
_alError = alError {
_alError = alError,
_esPremium = esPremium {
_suscripcion = this.servicio.estadoStream.listen((estado) {
if (estado.tipo == EstadoGrabacionRadioTipo.error &&
estado.error != null) {
@@ -48,6 +78,8 @@ class EstadoGrabacion extends ChangeNotifier {
/// User-visible error sink (EstadoRadio routes it to its snackbar stream).
final void Function(String mensaje)? _alError;
final bool Function() _esPremium;
StreamSubscription<EstadoGrabacionRadio>? _suscripcion;
AppLocalizations? _l10n;
@@ -70,16 +102,31 @@ class EstadoGrabacion extends ChangeNotifier {
int get maxBytes => servicio.maxBytes;
File? get ultimoArchivo => servicio.ultimoArchivo;
Future<void> iniciar({Duration? duracion}) async {
Future<ResultadoIniciarGrabacion> iniciar({Duration? duracion}) async {
// Freemium gate (freemium-gating spec "Free user starts a new
// recording"): the AUTHORITATIVE check, before touching the service at
// all. Management of already-existing recordings is untouched — this
// method only governs STARTING a new one.
if (!_esPremium()) {
return ResultadoIniciarGrabacion.requierePremium;
}
final actual = _emisoraActual();
if (actual == null) {
// `emisoraActual` is set by `_cambiarFuente` for EVERY source, local
// tracks included -- a local file becomes an `Emisora` whose `url` is the
// SAF `content://` URI it was opened from. Handing that to the recorder
// produced "Unsupported scheme 'content' in URI content://..." on screen,
// and it started happening only once local music playback existed: before
// that, whatever was playing was always a real station.
if (actual == null || !esEmisoraGrabable(actual)) {
_alError?.call(_textos.recordingSelectStationFirst);
return;
return ResultadoIniciarGrabacion.error;
}
try {
await servicio.iniciar(actual, duracion: duracion);
return ResultadoIniciarGrabacion.iniciada;
} catch (e) {
_alError?.call(_textos.recordingStartError(e.toString()));
return ResultadoIniciarGrabacion.error;
}
}
+48 -32
View File
@@ -47,6 +47,11 @@ class EstadoRadio extends ChangeNotifier {
Future<File> Function()? resolverArchivoCustom,
FuenteEmisorasAuto? fuenteAuto,
bool iniciarAutomaticamente = true,
// iap-freemium-unlock (Design ADR-3): threaded straight through to the
// internal `EstadoGrabacion` below — `EstadoRadio` itself has no gated
// behavior of its own, but it owns that notifier's construction, so it
// inherits the same "required, never defaulted" entitlement contract.
required bool Function() esPremium,
}) : audio = audio ?? ServicioAudio(),
favoritos = favoritos ?? ServicioFavoritos(),
radio = radio ?? ServicioRadio(),
@@ -66,6 +71,7 @@ class EstadoRadio extends ChangeNotifier {
servicio: servicioGrabacion ?? ServicioGrabacionRadio(prefs: prefs),
emisoraActual: () => emisoraActual,
alError: _errorController.add,
esPremium: esPremium,
);
busqueda = EstadoBusqueda(
radio: this.radio,
@@ -332,24 +338,6 @@ class EstadoRadio extends ChangeNotifier {
}
}
/// Best-effort remembers [emisora] as the last used station (issue 4) so
/// [_restaurarUltimaEmisora] can bring it back after a restart. Fire-and-
/// forget, same treatment [reproducir] already gives other non-critical
/// side effects (e.g. `radio.registrarClick`) — a failed write here must
/// never block or fail actual playback.
Future<void> _persistirUltimaEmisora(Emisora emisora) async {
try {
final prefs = await _resolverPrefs();
await prefs.setString(_keyUltimaEmisora, jsonEncode(emisora.toMap()));
} catch (e) {
registrarSaltoPersistencia(
subsistema: 'ultima_emisora',
detalle: 'persistir ${emisora.uuid}',
razon: e.toString(),
);
}
}
/// Escucha el stream de estado del audio y gestiona errores de reproducción.
void _escucharErroresReproduccion() {
_suscripcionEstadoAudio = audio.estadoStream.listen((estado) {
@@ -369,9 +357,12 @@ class EstadoRadio extends ChangeNotifier {
final actual = audio.emisoraActual;
if (actual != null && actual.uuid != _emisoraSeleccionada?.uuid) {
_emisoraSeleccionada = actual;
// Issue 4: an Android-Auto-initiated selection is a real station
// change too — remember it the same way `reproducir` does.
unawaited(_persistirUltimaEmisora(actual));
// Issue 4's write used to live here as well. It is gone: the handler
// persists every station itself from `_cambiarFuente`, which is the
// same source change that moved `audio.emisoraActual` and is the
// reason this branch runs at all. Writing again here would make the
// key's final value depend on how two independent fire-and-forget
// chains interleave on a fast station switch.
}
notifyListeners();
});
@@ -582,10 +573,13 @@ class EstadoRadio extends ChangeNotifier {
}
_emisoraSeleccionada = emisora;
notifyListeners();
// Issue 4: remembers the station the user just picked so it survives a
// restart — fire-and-forget, same treatment as `radio.registrarClick`
// below (a persistence failure here must never block playback).
unawaited(_persistirUltimaEmisora(emisora));
// Issue 4's `ultima_emisora_v1` write used to be here. It now happens
// once, inside the handler's `_cambiarFuente`, which `audio.reproducir`
// below reaches for this very station — see
// [GuardarUltimaEmisoraPersistida]. Persisting here as well would have
// left the key with TWO fire-and-forget writers whose relative order
// decides the value after a fast A -> B switch, and this one cannot see
// the revision guard that already cancels a superseded change.
try {
await audio.reproducir(emisora);
if (revision != _revisionReproduccion) return;
@@ -801,9 +795,10 @@ class EstadoRadio extends ChangeNotifier {
static const _keyAlarmasConfig = 'alarmas_musicales_v1';
/// Genera el JSON de toda la configuración (v3 — portabilidad completa
/// con presets por dispositivo y matriz multi-device).
/// La forma del sobre v3 vive en [ServicioExportImport] (S4-R4).
/// Genera el JSON de toda la configuración (v4 — portabilidad completa
/// con presets por dispositivo, matriz multi-device y el toggle
/// on/off del ecualizador).
/// La forma del sobre vive en [ServicioExportImport] (S4-R4).
Future<Map<String, dynamic>> exportarConfig() async {
final favs = await favoritos.obtenerTodos();
final grupos = await favoritos.obtenerGrupos();
@@ -831,6 +826,8 @@ class EstadoRadio extends ChangeNotifier {
presetsPorDispositivo: ecualizador.presetsDispositivo,
presetsMatriz: ecualizador.presetsMatriz,
eqMultiDeviceEnabled: ecualizador.eqMultiDeviceEnabled,
// v4 extension — equalizer global on/off toggle.
ecualizadorActivo: ecualizador.activo,
);
}
@@ -844,10 +841,11 @@ class EstadoRadio extends ChangeNotifier {
/// Importa configuración desde un JSON exportado previamente.
/// Soporta v1 (sin grupos, sin alarmas), v2 (portabilidad completa),
/// y v3 (+ presets por dispositivo, presets matriz, toggle multi-device).
/// v3 (+ presets por dispositivo, presets matriz, toggle multi-device)
/// y v4 (+ toggle on/off del ecualizador).
Future<void> importarConfig(Map<String, dynamic> data) async {
final version = data['version'] as int? ?? 1;
if (version > 3) throw Exception(_textos.unsupportedConfigVersion);
if (version > 4) throw Exception(_textos.unsupportedConfigVersion);
final prefs = await _resolverPrefs();
@@ -867,7 +865,12 @@ class EstadoRadio extends ChangeNotifier {
final favRaw = data['favoritos'] as List? ?? [];
for (final raw in favRaw) {
final emisora = Emisora.fromMap(Map<String, dynamic>.from(raw as Map));
await favoritos.agregar(emisora);
// `restaurarFavorito`, NO `agregar`: `agregar` es la primitiva de
// «marcar como favorita» y fuerza `sin_asignar` + un `orden` al final,
// que es justo lo que la copia trae y hay que conservar. Con `agregar`
// los grupos restaurados arriba volvían como cascarones vacíos y todas
// las emisoras aterrizaban en «Sin asignar».
await favoritos.restaurarFavorito(emisora);
}
// ── Emisoras custom ───────────────────────────────────────────────────
@@ -926,12 +929,20 @@ class EstadoRadio extends ChangeNotifier {
eqMultiDeviceEnabled = data['eqMultiDeviceEnabled'] as bool?;
}
// v4 extension: equalizer on/off toggle. Read unconditionally — the key
// is simply absent on any pre-v4 backup, which resolves to `null` and
// leaves the user's CURRENT toggle untouched (see
// `EstadoEcualizador.importarConfiguracion` doc): an old backup must
// never flip a live setting it never carried.
final ecualizadorActivo = data['ecualizadorActivo'] as bool?;
await ecualizador.importarConfiguracion(
principal: presetPrincipal,
porEmisora: presetsPorEmisora,
presetsDispositivo: presetsDispositivo,
presetsMatriz: presetsMatriz,
eqMultiDeviceEnabled: eqMultiDeviceEnabled,
activo: ecualizadorActivo,
);
// ── Alarmas (v2) ──────────────────────────────────────────────────────
@@ -939,7 +950,12 @@ class EstadoRadio extends ChangeNotifier {
final alarmasData = data['alarmas'];
if (alarmasData is Map<String, dynamic>) {
// Escribimos el bloque JSON tal como estaba en el dispositivo origen.
// ServicioAlarmas lo leerá con su propio fromJson al siguiente acceso.
// EstadoAlarmas es un ChangeNotifier independiente y de larga vida
// que ya cargó sus alarmas en memoria: NO relee este storage por sí
// solo. El llamador (pantalla_ajustes_backup.dart) es responsable de
// invocar `EstadoAlarmas.cargarPersistidasSinRecalcular()` seguido
// de `refrescarProgramacion()` tras un import exitoso; EstadoRadio
// se mantiene deliberadamente sin depender de EstadoAlarmas.
await prefs.setString(_keyAlarmasConfig, jsonEncode(alarmasData));
}
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "إصلاح",
"alarmDiagnosticsIntentUnavailable": "تعذّر فتح شاشة الإعدادات هذه على هذا الهاتف. حاول البحث عنها يدويًا في الإعدادات.",
"alarmDiagnosticsUnavailableHint": "لم نتمكّن بعد من التحقق من إعدادات المنبه الخاصة بك.",
"autoEqDisableOption": "تعطيل"
"autoEqDisableOption": "تعطيل",
"funcionPremium": "ميزة مميزة",
"limiteAlarmasAlcanzado": "لقد وصلت إلى الحد المجاني وهو 5 منبهات.",
"desbloquearPremium": "فتح النسخة المميزة",
"restaurarCompras": "استعادة المشتريات",
"compraError": "تعذّر إتمام عملية الشراء. حاول مرة أخرى.",
"restauracionSinCompras": "لم نجد أي عملية شراء سابقة في هذا الحساب.",
"premiumActivo": "النسخة المميزة مفعّلة",
"premiumHojaTitulo": "افتح PluriWave Premium",
"premiumBeneficioSinAnuncios": "بدون إعلانات في التطبيق بالكامل",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "تسجيل المحطات",
"premiumBeneficioVacaciones": "فترات إجازة للمنبهات",
"premiumBeneficioAlarmasIlimitadas": "منبهات غير محدودة (تسمح الخطة المجانية بحتى 5)",
"premiumPagoUnico": "دفعة واحدة، للأبد. ليس اشتراكًا.",
"premiumAhoraNo": "ليس الآن",
"autoErrorEmisoraPremium": "هذه المحطة ضمن Premium. افتح PluriWave على هاتفك لفتحها.",
"autoErrorBusquedaSinResultados": "لم نعثر على تلك المحطة. جرّب اسمًا آخر.",
"autoCarpetaEscuchar": "الاستماع",
"autoCarpetaFavoritos": "المفضلة",
"autoCarpetaTodas": "كل المحطات",
"autoCarpetaMisEmisoras": "محطاتي",
"autoCarpetaMusicaLocal": "الموسيقى المحلية",
"autoMusicaLocalNoDisponible": "افتح PluriWave على هاتفك لقراءة موسيقاك",
"autoCargarMas": "المزيد…",
"autoOrdenarPorCalidad": "الترتيب حسب الجودة",
"autoReproducirCarpeta": "تشغيل المجلد",
"autoReproducirAleatorio": "تشغيل عشوائي",
"autoPistaSinNombre": "مقطع بلا اسم"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "সমাধান করুন",
"alarmDiagnosticsIntentUnavailable": "এই ফোনে সেই সেটিংস স্ক্রিনটি খোলা যায়নি। সেটিংসে ম্যানুয়ালি খুঁজে দেখার চেষ্টা করুন।",
"alarmDiagnosticsUnavailableHint": "আমরা এখনও আপনার অ্যালার্ম সেটিংস পরীক্ষা করতে পারিনি।",
"autoEqDisableOption": "বন্ধ করুন"
"autoEqDisableOption": "বন্ধ করুন",
"funcionPremium": "প্রিমিয়াম বৈশিষ্ট্য",
"limiteAlarmasAlcanzado": "আপনি বিনামূল্যে ৫টি অ্যালার্মের সীমায় পৌঁছেছেন।",
"desbloquearPremium": "প্রিমিয়াম আনলক করুন",
"restaurarCompras": "কেনাকাটা পুনরুদ্ধার করুন",
"compraError": "কেনাকাটা সম্পূর্ণ করা যায়নি। আবার চেষ্টা করুন।",
"restauracionSinCompras": "এই অ্যাকাউন্টে আমরা আগের কোনো কেনাকাটা খুঁজে পাইনি।",
"premiumActivo": "প্রিমিয়াম সক্রিয়",
"premiumHojaTitulo": "PluriWave Premium আনলক করুন",
"premiumBeneficioSinAnuncios": "পুরো অ্যাপে কোনো বিজ্ঞাপন নেই",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "স্টেশন রেকর্ডিং",
"premiumBeneficioVacaciones": "অ্যালার্মের জন্য ছুটির সময়কাল",
"premiumBeneficioAlarmasIlimitadas": "সীমাহীন অ্যালার্ম (ফ্রি প্ল্যানে সর্বোচ্চ ৫টি অনুমোদিত)",
"premiumPagoUnico": "একবারের পেমেন্ট, চিরকালের জন্য। এটি সাবস্ক্রিপশন নয়।",
"premiumAhoraNo": "এখন নয়",
"autoErrorEmisoraPremium": "এই স্টেশনটি Premium। আনলক করতে ফোনে PluriWave খুলুন।",
"autoErrorBusquedaSinResultados": "সেই স্টেশনটি খুঁজে পাওয়া যায়নি। অন্য নাম চেষ্টা করুন।",
"autoCarpetaEscuchar": "শুনুন",
"autoCarpetaFavoritos": "প্রিয়",
"autoCarpetaTodas": "সব স্টেশন",
"autoCarpetaMisEmisoras": "আমার স্টেশন",
"autoCarpetaMusicaLocal": "স্থানীয় সঙ্গীত",
"autoMusicaLocalNoDisponible": "আপনার গান পড়তে ফোনে PluriWave খুলুন",
"autoCargarMas": "আরও…",
"autoOrdenarPorCalidad": "মান অনুসারে সাজান",
"autoReproducirCarpeta": "ফোল্ডার চালান",
"autoReproducirAleatorio": "এলোমেলোভাবে চালান",
"autoPistaSinNombre": "নামহীন ট্র্যাক"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Beheben",
"alarmDiagnosticsIntentUnavailable": "Diese Einstellungsseite konnte auf diesem Telefon nicht geöffnet werden. Suche sie manuell in den Einstellungen.",
"alarmDiagnosticsUnavailableHint": "Wir konnten deine Alarmeinstellungen noch nicht prüfen.",
"autoEqDisableOption": "Deaktivieren"
"autoEqDisableOption": "Deaktivieren",
"funcionPremium": "Premium-Funktion",
"limiteAlarmasAlcanzado": "Du hast das kostenlose Limit von 5 Weckern erreicht.",
"desbloquearPremium": "Premium freischalten",
"restaurarCompras": "Käufe wiederherstellen",
"compraError": "Der Kauf konnte nicht abgeschlossen werden. Bitte versuche es erneut.",
"restauracionSinCompras": "Wir haben auf diesem Konto keinen früheren Kauf gefunden.",
"premiumActivo": "Premium aktiv",
"premiumHojaTitulo": "PluriWave Premium freischalten",
"premiumBeneficioSinAnuncios": "Keine Werbung in der gesamten App",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Sender aufnehmen",
"premiumBeneficioVacaciones": "Urlaubszeiträume für Wecker",
"premiumBeneficioAlarmasIlimitadas": "Unbegrenzte Wecker (die kostenlose Version erlaubt bis zu 5)",
"premiumPagoUnico": "Einmalzahlung, für immer. Kein Abonnement.",
"premiumAhoraNo": "Nicht jetzt",
"autoErrorEmisoraPremium": "Dieser Sender ist Premium. Öffne PluriWave auf dem Handy, um ihn freizuschalten.",
"autoErrorBusquedaSinResultados": "Wir haben diesen Sender nicht gefunden. Versuch es mit einem anderen Namen.",
"autoCarpetaEscuchar": "Hören",
"autoCarpetaFavoritos": "Favoriten",
"autoCarpetaTodas": "Alle Sender",
"autoCarpetaMisEmisoras": "Meine Sender",
"autoCarpetaMusicaLocal": "Lokale Musik",
"autoMusicaLocalNoDisponible": "Öffne PluriWave auf dem Handy, um deine Musik zu lesen",
"autoCargarMas": "Mehr…",
"autoOrdenarPorCalidad": "Nach Qualität sortieren",
"autoReproducirCarpeta": "Ordner abspielen",
"autoReproducirAleatorio": "Zufallswiedergabe",
"autoPistaSinNombre": "Unbenannter Titel"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Fix this",
"alarmDiagnosticsIntentUnavailable": "Couldn't open that settings screen on this phone. Try looking for it manually in Settings.",
"alarmDiagnosticsUnavailableHint": "We couldn't check your alarm settings yet.",
"autoEqDisableOption": "Disable"
"autoEqDisableOption": "Disable",
"funcionPremium": "Premium Feature",
"limiteAlarmasAlcanzado": "You've reached the free 5-alarm limit.",
"desbloquearPremium": "Unlock Premium",
"restaurarCompras": "Restore purchases",
"compraError": "We couldn't complete the purchase. Please try again.",
"restauracionSinCompras": "We didn't find any previous purchase on this account.",
"premiumActivo": "Premium active",
"premiumHojaTitulo": "Unlock PluriWave Premium",
"premiumBeneficioSinAnuncios": "No ads anywhere in the app",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Station recording",
"premiumBeneficioVacaciones": "Vacation ranges for alarms",
"premiumBeneficioAlarmasIlimitadas": "Unlimited alarms (the free plan allows up to 5)",
"premiumPagoUnico": "One-time purchase, forever. Not a subscription.",
"premiumAhoraNo": "Not now",
"autoErrorEmisoraPremium": "This station is Premium. Open PluriWave on your phone to unlock it.",
"autoErrorBusquedaSinResultados": "We couldn't find that station. Try another name.",
"autoCarpetaEscuchar": "Listen",
"autoCarpetaFavoritos": "Favorites",
"autoCarpetaTodas": "All stations",
"autoCarpetaMisEmisoras": "My stations",
"autoCarpetaMusicaLocal": "Local music",
"autoMusicaLocalNoDisponible": "Open PluriWave on your phone to read your music",
"autoCargarMas": "More…",
"autoOrdenarPorCalidad": "Sort by quality",
"autoReproducirCarpeta": "Play folder",
"autoReproducirAleatorio": "Shuffle play",
"autoPistaSinNombre": "Untitled track"
}
+29 -1
View File
@@ -856,5 +856,33 @@
"alarmDiagnosticsFixAction": "Solucionar",
"alarmDiagnosticsIntentUnavailable": "No se pudo abrir esa pantalla de ajustes en este teléfono. Buscala manualmente en Ajustes.",
"alarmDiagnosticsUnavailableHint": "Todavía no pudimos revisar tus ajustes de alarma.",
"autoEqDisableOption": "Desactivar"
"autoEqDisableOption": "Desactivar",
"funcionPremium": "Función Premium",
"limiteAlarmasAlcanzado": "Has alcanzado el límite de 5 alarmas gratuitas.",
"desbloquearPremium": "Desbloquear Premium",
"restaurarCompras": "Restaurar compras",
"compraError": "No se ha podido completar la compra. Inténtalo de nuevo.",
"restauracionSinCompras": "No hemos encontrado ninguna compra anterior en esta cuenta.",
"premiumActivo": "Premium activo",
"premiumHojaTitulo": "Desbloquea PluriWave Premium",
"premiumBeneficioSinAnuncios": "Sin publicidad en toda la app",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Grabación de emisoras",
"premiumBeneficioVacaciones": "Rangos de vacaciones para las alarmas",
"premiumBeneficioAlarmasIlimitadas": "Alarmas ilimitadas (el plan gratuito permite hasta 5)",
"premiumPagoUnico": "Pago único, para siempre. No es una suscripción.",
"premiumAhoraNo": "Ahora no",
"autoErrorEmisoraPremium": "Esta emisora es Premium. Abre PluriWave en el móvil para desbloquearla.",
"autoErrorBusquedaSinResultados": "No hemos encontrado esa emisora. Prueba con otro nombre.",
"autoCarpetaEscuchar": "Escuchar",
"autoCarpetaFavoritos": "Favoritos",
"autoCarpetaTodas": "Todas las emisoras",
"autoCarpetaMisEmisoras": "Mis emisoras",
"autoCarpetaMusicaLocal": "Música Local",
"autoMusicaLocalNoDisponible": "Abre PluriWave en el móvil para leer tu música",
"autoCargarMas": "Más…",
"autoOrdenarPorCalidad": "Ordenar por calidad",
"autoReproducirCarpeta": "Reproducir carpeta",
"autoReproducirAleatorio": "Reproducir aleatorio",
"autoPistaSinNombre": "Pista sin nombre"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Corriger",
"alarmDiagnosticsIntentUnavailable": "Impossible d'ouvrir cet écran de paramètres sur ce téléphone. Essayez de le trouver manuellement dans les Paramètres.",
"alarmDiagnosticsUnavailableHint": "Nous n'avons pas encore pu vérifier vos paramètres d'alarme.",
"autoEqDisableOption": "Désactiver"
"autoEqDisableOption": "Désactiver",
"funcionPremium": "Fonctionnalité Premium",
"limiteAlarmasAlcanzado": "Vous avez atteint la limite gratuite de 5 alarmes.",
"desbloquearPremium": "Débloquer Premium",
"restaurarCompras": "Restaurer les achats",
"compraError": "Impossible de finaliser l'achat. Veuillez réessayer.",
"restauracionSinCompras": "Nous n'avons trouvé aucun achat antérieur sur ce compte.",
"premiumActivo": "Premium actif",
"premiumHojaTitulo": "Débloquer PluriWave Premium",
"premiumBeneficioSinAnuncios": "Aucune publicité dans toute l'application",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Enregistrement des stations",
"premiumBeneficioVacaciones": "Périodes de vacances pour les alarmes",
"premiumBeneficioAlarmasIlimitadas": "Alarmes illimitées (la version gratuite en autorise jusqu'à 5)",
"premiumPagoUnico": "Achat unique, pour toujours. Ce n'est pas un abonnement.",
"premiumAhoraNo": "Plus tard",
"autoErrorEmisoraPremium": "Cette station est Premium. Ouvre PluriWave sur ton téléphone pour la débloquer.",
"autoErrorBusquedaSinResultados": "Nous n'avons pas trouvé cette station. Essaie un autre nom.",
"autoCarpetaEscuchar": "Écouter",
"autoCarpetaFavoritos": "Favoris",
"autoCarpetaTodas": "Toutes les stations",
"autoCarpetaMisEmisoras": "Mes stations",
"autoCarpetaMusicaLocal": "Musique locale",
"autoMusicaLocalNoDisponible": "Ouvrez PluriWave sur votre téléphone pour lire votre musique",
"autoCargarMas": "Plus…",
"autoOrdenarPorCalidad": "Trier par qualité",
"autoReproducirCarpeta": "Lire le dossier",
"autoReproducirAleatorio": "Lecture aléatoire",
"autoPistaSinNombre": "Piste sans nom"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "ठीक करें",
"alarmDiagnosticsIntentUnavailable": "इस फ़ोन पर वह सेटिंग्स स्क्रीन नहीं खोली जा सकी। कृपया सेटिंग्स में इसे खुद ढूंढने की कोशिश करें।",
"alarmDiagnosticsUnavailableHint": "हम अभी तक आपकी अलार्म सेटिंग्स जांच नहीं पाए हैं।",
"autoEqDisableOption": "बंद करें"
"autoEqDisableOption": "बंद करें",
"funcionPremium": "प्रीमियम सुविधा",
"limiteAlarmasAlcanzado": "आप मुफ़्त 5 अलार्म की सीमा तक पहुँच गए हैं।",
"desbloquearPremium": "प्रीमियम अनलॉक करें",
"restaurarCompras": "खरीदारी पुनर्स्थापित करें",
"compraError": "खरीद पूरी नहीं हो सकी। कृपया फिर से प्रयास करें।",
"restauracionSinCompras": "इस खाते में हमें कोई पिछली खरीद नहीं मिली।",
"premiumActivo": "प्रीमियम सक्रिय",
"premiumHojaTitulo": "PluriWave Premium अनलॉक करें",
"premiumBeneficioSinAnuncios": "पूरे ऐप में कोई विज्ञापन नहीं",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "स्टेशन रिकॉर्डिंग",
"premiumBeneficioVacaciones": "अलार्म के लिए छुट्टी की अवधि",
"premiumBeneficioAlarmasIlimitadas": "असीमित अलार्म (मुफ़्त प्लान में अधिकतम 5 की अनुमति है)",
"premiumPagoUnico": "एकमुश्त भुगतान, हमेशा के लिए। यह सदस्यता नहीं है।",
"premiumAhoraNo": "अभी नहीं",
"autoErrorEmisoraPremium": "यह स्टेशन Premium है। इसे अनलॉक करने के लिए फ़ोन पर PluriWave खोलें।",
"autoErrorBusquedaSinResultados": "वह स्टेशन नहीं मिला। कोई दूसरा नाम आज़माएँ।",
"autoCarpetaEscuchar": "सुनें",
"autoCarpetaFavoritos": "पसंदीदा",
"autoCarpetaTodas": "सभी स्टेशन",
"autoCarpetaMisEmisoras": "मेरे स्टेशन",
"autoCarpetaMusicaLocal": "लोकल संगीत",
"autoMusicaLocalNoDisponible": "अपना संगीत पढ़ने के लिए फ़ोन पर PluriWave खोलें",
"autoCargarMas": "और…",
"autoOrdenarPorCalidad": "गुणवत्ता के अनुसार क्रमबद्ध करें",
"autoReproducirCarpeta": "फ़ोल्डर चलाएँ",
"autoReproducirAleatorio": "शफ़ल चलाएँ",
"autoPistaSinNombre": "बिना नाम का ट्रैक"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Perbaiki",
"alarmDiagnosticsIntentUnavailable": "Tidak bisa membuka layar pengaturan itu di ponsel ini. Coba cari secara manual di Pengaturan.",
"alarmDiagnosticsUnavailableHint": "Kami belum bisa memeriksa pengaturan alarmmu.",
"autoEqDisableOption": "Nonaktifkan"
"autoEqDisableOption": "Nonaktifkan",
"funcionPremium": "Fitur Premium",
"limiteAlarmasAlcanzado": "Anda telah mencapai batas gratis 5 alarm.",
"desbloquearPremium": "Buka Premium",
"restaurarCompras": "Pulihkan pembelian",
"compraError": "Pembelian tidak dapat diselesaikan. Silakan coba lagi.",
"restauracionSinCompras": "Kami tidak menemukan pembelian sebelumnya di akun ini.",
"premiumActivo": "Premium aktif",
"premiumHojaTitulo": "Buka PluriWave Premium",
"premiumBeneficioSinAnuncios": "Tanpa iklan di seluruh aplikasi",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Perekaman stasiun",
"premiumBeneficioVacaciones": "Rentang liburan untuk alarm",
"premiumBeneficioAlarmasIlimitadas": "Alarm tanpa batas (paket gratis mengizinkan hingga 5)",
"premiumPagoUnico": "Pembelian sekali bayar, untuk selamanya. Bukan langganan.",
"premiumAhoraNo": "Nanti saja",
"autoErrorEmisoraPremium": "Stasiun ini Premium. Buka PluriWave di ponsel untuk membukanya.",
"autoErrorBusquedaSinResultados": "Kami tidak menemukan stasiun itu. Coba nama lain.",
"autoCarpetaEscuchar": "Dengarkan",
"autoCarpetaFavoritos": "Favorit",
"autoCarpetaTodas": "Semua stasiun",
"autoCarpetaMisEmisoras": "Stasiun saya",
"autoCarpetaMusicaLocal": "Musik lokal",
"autoMusicaLocalNoDisponible": "Buka PluriWave di ponsel untuk membaca musik Anda",
"autoCargarMas": "Lainnya…",
"autoOrdenarPorCalidad": "Urutkan menurut kualitas",
"autoReproducirCarpeta": "Putar folder",
"autoReproducirAleatorio": "Putar acak",
"autoPistaSinNombre": "Trek tanpa nama"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Risolvi",
"alarmDiagnosticsIntentUnavailable": "Non è stato possibile aprire questa schermata delle impostazioni su questo telefono. Prova a cercarla manualmente nelle Impostazioni.",
"alarmDiagnosticsUnavailableHint": "Non abbiamo ancora potuto controllare le impostazioni della sveglia.",
"autoEqDisableOption": "Disattiva"
"autoEqDisableOption": "Disattiva",
"funcionPremium": "Funzione Premium",
"limiteAlarmasAlcanzado": "Hai raggiunto il limite gratuito di 5 sveglie.",
"desbloquearPremium": "Sblocca Premium",
"restaurarCompras": "Ripristina acquisti",
"compraError": "Non è stato possibile completare l'acquisto. Riprova.",
"restauracionSinCompras": "Non abbiamo trovato acquisti precedenti su questo account.",
"premiumActivo": "Premium attivo",
"premiumHojaTitulo": "Sblocca PluriWave Premium",
"premiumBeneficioSinAnuncios": "Nessuna pubblicità in tutta l'app",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Registrazione delle stazioni",
"premiumBeneficioVacaciones": "Intervalli di vacanza per le sveglie",
"premiumBeneficioAlarmasIlimitadas": "Sveglie illimitate (il piano gratuito ne consente fino a 5)",
"premiumPagoUnico": "Acquisto unico, per sempre. Non è un abbonamento.",
"premiumAhoraNo": "Non ora",
"autoErrorEmisoraPremium": "Questa stazione è Premium. Apri PluriWave sul telefono per sbloccarla.",
"autoErrorBusquedaSinResultados": "Non abbiamo trovato quella stazione. Prova con un altro nome.",
"autoCarpetaEscuchar": "Ascolta",
"autoCarpetaFavoritos": "Preferiti",
"autoCarpetaTodas": "Tutte le emittenti",
"autoCarpetaMisEmisoras": "Le mie emittenti",
"autoCarpetaMusicaLocal": "Musica locale",
"autoMusicaLocalNoDisponible": "Apri PluriWave sul telefono per leggere la tua musica",
"autoCargarMas": "Altro…",
"autoOrdenarPorCalidad": "Ordina per qualità",
"autoReproducirCarpeta": "Riproduci cartella",
"autoReproducirAleatorio": "Riproduzione casuale",
"autoPistaSinNombre": "Traccia senza nome"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "修正する",
"alarmDiagnosticsIntentUnavailable": "この端末では設定画面を開けませんでした。設定アプリ内で手動で探してみてください。",
"alarmDiagnosticsUnavailableHint": "アラームの設定をまだ確認できていません。",
"autoEqDisableOption": "無効化"
"autoEqDisableOption": "無効化",
"funcionPremium": "プレミアム機能",
"limiteAlarmasAlcanzado": "無料プランのアラーム上限(5件)に達しました。",
"desbloquearPremium": "プレミアムを解除",
"restaurarCompras": "購入を復元",
"compraError": "購入を完了できませんでした。もう一度お試しください。",
"restauracionSinCompras": "このアカウントでは以前の購入が見つかりませんでした。",
"premiumActivo": "プレミアム有効",
"premiumHojaTitulo": "PluriWave Premiumのロックを解除",
"premiumBeneficioSinAnuncios": "アプリ全体で広告なし",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "放送局の録音",
"premiumBeneficioVacaciones": "アラームの休暇期間設定",
"premiumBeneficioAlarmasIlimitadas": "アラーム数無制限(無料プランは5個まで)",
"premiumPagoUnico": "買い切りの一度きりの支払いで永久に使用可能。サブスクリプションではありません。",
"premiumAhoraNo": "後で",
"autoErrorEmisoraPremium": "この放送局は Premium です。スマートフォンで PluriWave を開いてロックを解除してください。",
"autoErrorBusquedaSinResultados": "その放送局は見つかりませんでした。別の名前をお試しください。",
"autoCarpetaEscuchar": "聴く",
"autoCarpetaFavoritos": "お気に入り",
"autoCarpetaTodas": "すべての局",
"autoCarpetaMisEmisoras": "マイ局",
"autoCarpetaMusicaLocal": "ローカルの音楽",
"autoMusicaLocalNoDisponible": "音楽を読み込むにはスマートフォンで PluriWave を開いてください",
"autoCargarMas": "もっと見る…",
"autoOrdenarPorCalidad": "音質順に並べ替え",
"autoReproducirCarpeta": "フォルダを再生",
"autoReproducirAleatorio": "シャッフル再生",
"autoPistaSinNombre": "名称未設定のトラック"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Resolver",
"alarmDiagnosticsIntentUnavailable": "Não foi possível abrir essa tela de configurações neste telefone. Tente procurá-la manualmente nas Configurações.",
"alarmDiagnosticsUnavailableHint": "Ainda não conseguimos verificar as configurações do seu alarme.",
"autoEqDisableOption": "Desativar"
"autoEqDisableOption": "Desativar",
"funcionPremium": "Recurso Premium",
"limiteAlarmasAlcanzado": "Você atingiu o limite gratuito de 5 alarmes.",
"desbloquearPremium": "Desbloquear Premium",
"restaurarCompras": "Restaurar compras",
"compraError": "Não foi possível concluir a compra. Tente novamente.",
"restauracionSinCompras": "Não encontramos nenhuma compra anterior nesta conta.",
"premiumActivo": "Premium ativo",
"premiumHojaTitulo": "Desbloqueie o PluriWave Premium",
"premiumBeneficioSinAnuncios": "Sem anúncios em todo o app",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Gravação de emissoras",
"premiumBeneficioVacaciones": "Períodos de férias para os alarmes",
"premiumBeneficioAlarmasIlimitadas": "Alarmes ilimitados (o plano gratuito permite até 5)",
"premiumPagoUnico": "Pagamento único, para sempre. Não é uma assinatura.",
"premiumAhoraNo": "Agora não",
"autoErrorEmisoraPremium": "Esta estação é Premium. Abra o PluriWave no telemóvel para a desbloquear.",
"autoErrorBusquedaSinResultados": "Não encontrámos essa estação. Tente outro nome.",
"autoCarpetaEscuchar": "Ouvir",
"autoCarpetaFavoritos": "Favoritos",
"autoCarpetaTodas": "Todas as estações",
"autoCarpetaMisEmisoras": "As minhas estações",
"autoCarpetaMusicaLocal": "Música local",
"autoMusicaLocalNoDisponible": "Abra o PluriWave no telemóvel para ler a sua música",
"autoCargarMas": "Mais…",
"autoOrdenarPorCalidad": "Ordenar por qualidade",
"autoReproducirCarpeta": "Reproduzir pasta",
"autoReproducirAleatorio": "Reprodução aleatória",
"autoPistaSinNombre": "Faixa sem nome"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "Исправить",
"alarmDiagnosticsIntentUnavailable": "Не удалось открыть этот экран настроек на этом телефоне. Попробуйте найти его вручную в Настройках.",
"alarmDiagnosticsUnavailableHint": "Мы пока не смогли проверить настройки вашего будильника.",
"autoEqDisableOption": "Отключить"
"autoEqDisableOption": "Отключить",
"funcionPremium": "Премиум-функция",
"limiteAlarmasAlcanzado": "Вы достигли бесплатного лимита в 5 будильников.",
"desbloquearPremium": "Разблокировать Премиум",
"restaurarCompras": "Восстановить покупки",
"compraError": "Не удалось завершить покупку. Попробуйте ещё раз.",
"restauracionSinCompras": "Мы не нашли предыдущих покупок на этом аккаунте.",
"premiumActivo": "Премиум активен",
"premiumHojaTitulo": "Разблокировать PluriWave Premium",
"premiumBeneficioSinAnuncios": "Никакой рекламы во всём приложении",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "Запись радиостанций",
"premiumBeneficioVacaciones": "Периоды отпуска для будильников",
"premiumBeneficioAlarmasIlimitadas": "Неограниченное количество будильников (бесплатный план позволяет до 5)",
"premiumPagoUnico": "Единоразовая покупка, навсегда. Это не подписка.",
"premiumAhoraNo": "Не сейчас",
"autoErrorEmisoraPremium": "Эта станция доступна в Premium. Откройте PluriWave на телефоне, чтобы разблокировать её.",
"autoErrorBusquedaSinResultados": "Мы не нашли такую станцию. Попробуйте другое название.",
"autoCarpetaEscuchar": "Слушать",
"autoCarpetaFavoritos": "Избранное",
"autoCarpetaTodas": "Все станции",
"autoCarpetaMisEmisoras": "Мои станции",
"autoCarpetaMusicaLocal": "Локальная музыка",
"autoMusicaLocalNoDisponible": "Откройте PluriWave на телефоне, чтобы прочитать вашу музыку",
"autoCargarMas": "Ещё…",
"autoOrdenarPorCalidad": "Сортировать по качеству",
"autoReproducirCarpeta": "Воспроизвести папку",
"autoReproducirAleatorio": "Случайное воспроизведение",
"autoPistaSinNombre": "Трек без названия"
}
+29 -1
View File
@@ -897,5 +897,33 @@
"alarmDiagnosticsFixAction": "解决",
"alarmDiagnosticsIntentUnavailable": "无法在此手机上打开该设置界面。请尝试在设置中手动查找。",
"alarmDiagnosticsUnavailableHint": "我们还无法检查你的闹钟设置。",
"autoEqDisableOption": "关闭"
"autoEqDisableOption": "关闭",
"funcionPremium": "高级功能",
"limiteAlarmasAlcanzado": "您已达到免费版 5 个闹钟的上限。",
"desbloquearPremium": "解锁高级版",
"restaurarCompras": "恢复购买",
"compraError": "无法完成购买,请重试。",
"restauracionSinCompras": "未在此账户中找到以前的购买记录。",
"premiumActivo": "高级版已解锁",
"premiumHojaTitulo": "解锁 PluriWave Premium",
"premiumBeneficioSinAnuncios": "全应用无广告",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "电台录音",
"premiumBeneficioVacaciones": "闹钟的假期时间段",
"premiumBeneficioAlarmasIlimitadas": "无限闹钟(免费版最多支持5个)",
"premiumPagoUnico": "一次性付费,永久使用,不是订阅。",
"premiumAhoraNo": "以后再说",
"autoErrorEmisoraPremium": "该电台属于 Premium 内容。请在手机上打开 PluriWave 解锁。",
"autoErrorBusquedaSinResultados": "没有找到该电台。请换个名称再试。",
"autoCarpetaEscuchar": "收听",
"autoCarpetaFavoritos": "收藏",
"autoCarpetaTodas": "全部电台",
"autoCarpetaMisEmisoras": "我的电台",
"autoCarpetaMusicaLocal": "本地音乐",
"autoMusicaLocalNoDisponible": "请在手机上打开 PluriWave 以读取您的音乐",
"autoCargarMas": "更多…",
"autoOrdenarPorCalidad": "按音质排序",
"autoReproducirCarpeta": "播放文件夹",
"autoReproducirAleatorio": "随机播放",
"autoPistaSinNombre": "未命名曲目"
}
+168
View File
@@ -3325,6 +3325,174 @@ abstract class AppLocalizations {
/// In es, this message translates to:
/// **'Desactivar'**
String get autoEqDisableOption;
/// No description provided for @funcionPremium.
///
/// In es, this message translates to:
/// **'Función Premium'**
String get funcionPremium;
/// No description provided for @limiteAlarmasAlcanzado.
///
/// In es, this message translates to:
/// **'Has alcanzado el límite de 5 alarmas gratuitas.'**
String get limiteAlarmasAlcanzado;
/// No description provided for @desbloquearPremium.
///
/// In es, this message translates to:
/// **'Desbloquear Premium'**
String get desbloquearPremium;
/// No description provided for @restaurarCompras.
///
/// In es, this message translates to:
/// **'Restaurar compras'**
String get restaurarCompras;
/// No description provided for @compraError.
///
/// In es, this message translates to:
/// **'No se ha podido completar la compra. Inténtalo de nuevo.'**
String get compraError;
/// No description provided for @restauracionSinCompras.
///
/// In es, this message translates to:
/// **'No hemos encontrado ninguna compra anterior en esta cuenta.'**
String get restauracionSinCompras;
/// No description provided for @premiumActivo.
///
/// In es, this message translates to:
/// **'Premium activo'**
String get premiumActivo;
/// No description provided for @premiumHojaTitulo.
///
/// In es, this message translates to:
/// **'Desbloquea PluriWave Premium'**
String get premiumHojaTitulo;
/// No description provided for @premiumBeneficioSinAnuncios.
///
/// In es, this message translates to:
/// **'Sin publicidad en toda la app'**
String get premiumBeneficioSinAnuncios;
/// No description provided for @premiumBeneficioAndroidAuto.
///
/// In es, this message translates to:
/// **'Android Auto'**
String get premiumBeneficioAndroidAuto;
/// No description provided for @premiumBeneficioGrabacion.
///
/// In es, this message translates to:
/// **'Grabación de emisoras'**
String get premiumBeneficioGrabacion;
/// No description provided for @premiumBeneficioVacaciones.
///
/// In es, this message translates to:
/// **'Rangos de vacaciones para las alarmas'**
String get premiumBeneficioVacaciones;
/// No description provided for @premiumBeneficioAlarmasIlimitadas.
///
/// In es, this message translates to:
/// **'Alarmas ilimitadas (el plan gratuito permite hasta 5)'**
String get premiumBeneficioAlarmasIlimitadas;
/// No description provided for @premiumPagoUnico.
///
/// In es, this message translates to:
/// **'Pago único, para siempre. No es una suscripción.'**
String get premiumPagoUnico;
/// No description provided for @premiumAhoraNo.
///
/// In es, this message translates to:
/// **'Ahora no'**
String get premiumAhoraNo;
/// No description provided for @autoErrorEmisoraPremium.
///
/// In es, this message translates to:
/// **'Esta emisora es Premium. Abre PluriWave en el móvil para desbloquearla.'**
String get autoErrorEmisoraPremium;
/// No description provided for @autoErrorBusquedaSinResultados.
///
/// In es, this message translates to:
/// **'No hemos encontrado esa emisora. Prueba con otro nombre.'**
String get autoErrorBusquedaSinResultados;
/// No description provided for @autoCarpetaEscuchar.
///
/// In es, this message translates to:
/// **'Escuchar'**
String get autoCarpetaEscuchar;
/// No description provided for @autoCarpetaFavoritos.
///
/// In es, this message translates to:
/// **'Favoritos'**
String get autoCarpetaFavoritos;
/// No description provided for @autoCarpetaTodas.
///
/// In es, this message translates to:
/// **'Todas las emisoras'**
String get autoCarpetaTodas;
/// No description provided for @autoCarpetaMisEmisoras.
///
/// In es, this message translates to:
/// **'Mis emisoras'**
String get autoCarpetaMisEmisoras;
/// No description provided for @autoCarpetaMusicaLocal.
///
/// In es, this message translates to:
/// **'Música Local'**
String get autoCarpetaMusicaLocal;
/// No description provided for @autoMusicaLocalNoDisponible.
///
/// In es, this message translates to:
/// **'Abre PluriWave en el móvil para leer tu música'**
String get autoMusicaLocalNoDisponible;
/// No description provided for @autoCargarMas.
///
/// In es, this message translates to:
/// **'Más…'**
String get autoCargarMas;
/// No description provided for @autoOrdenarPorCalidad.
///
/// In es, this message translates to:
/// **'Ordenar por calidad'**
String get autoOrdenarPorCalidad;
/// No description provided for @autoReproducirCarpeta.
///
/// In es, this message translates to:
/// **'Reproducir carpeta'**
String get autoReproducirCarpeta;
/// No description provided for @autoReproducirAleatorio.
///
/// In es, this message translates to:
/// **'Reproducir aleatorio'**
String get autoReproducirAleatorio;
/// No description provided for @autoPistaSinNombre.
///
/// In es, this message translates to:
/// **'Pista sin nombre'**
String get autoPistaSinNombre;
}
class _AppLocalizationsDelegate
+90
View File
@@ -1840,4 +1840,94 @@ class AppLocalizationsAr extends AppLocalizations {
@override
String get autoEqDisableOption => 'تعطيل';
@override
String get funcionPremium => 'ميزة مميزة';
@override
String get limiteAlarmasAlcanzado =>
'لقد وصلت إلى الحد المجاني وهو 5 منبهات.';
@override
String get desbloquearPremium => 'فتح النسخة المميزة';
@override
String get restaurarCompras => 'استعادة المشتريات';
@override
String get compraError => 'تعذّر إتمام عملية الشراء. حاول مرة أخرى.';
@override
String get restauracionSinCompras =>
'لم نجد أي عملية شراء سابقة في هذا الحساب.';
@override
String get premiumActivo => 'النسخة المميزة مفعّلة';
@override
String get premiumHojaTitulo => 'افتح PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => 'بدون إعلانات في التطبيق بالكامل';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'تسجيل المحطات';
@override
String get premiumBeneficioVacaciones => 'فترات إجازة للمنبهات';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'منبهات غير محدودة (تسمح الخطة المجانية بحتى 5)';
@override
String get premiumPagoUnico => 'دفعة واحدة، للأبد. ليس اشتراكًا.';
@override
String get premiumAhoraNo => 'ليس الآن';
@override
String get autoErrorEmisoraPremium =>
'هذه المحطة ضمن Premium. افتح PluriWave على هاتفك لفتحها.';
@override
String get autoErrorBusquedaSinResultados =>
'لم نعثر على تلك المحطة. جرّب اسمًا آخر.';
@override
String get autoCarpetaEscuchar => 'الاستماع';
@override
String get autoCarpetaFavoritos => 'المفضلة';
@override
String get autoCarpetaTodas => 'كل المحطات';
@override
String get autoCarpetaMisEmisoras => 'محطاتي';
@override
String get autoCarpetaMusicaLocal => 'الموسيقى المحلية';
@override
String get autoMusicaLocalNoDisponible =>
'افتح PluriWave على هاتفك لقراءة موسيقاك';
@override
String get autoCargarMas => 'المزيد…';
@override
String get autoOrdenarPorCalidad => 'الترتيب حسب الجودة';
@override
String get autoReproducirCarpeta => 'تشغيل المجلد';
@override
String get autoReproducirAleatorio => 'تشغيل عشوائي';
@override
String get autoPistaSinNombre => 'مقطع بلا اسم';
}
+91
View File
@@ -1851,4 +1851,95 @@ class AppLocalizationsBn extends AppLocalizations {
@override
String get autoEqDisableOption => 'বন্ধ করুন';
@override
String get funcionPremium => 'প্রিমিয়াম বৈশিষ্ট্য';
@override
String get limiteAlarmasAlcanzado =>
'আপনি বিনামূল্যে ৫টি অ্যালার্মের সীমায় পৌঁছেছেন।';
@override
String get desbloquearPremium => 'প্রিমিয়াম আনলক করুন';
@override
String get restaurarCompras => 'কেনাকাটা পুনরুদ্ধার করুন';
@override
String get compraError => 'কেনাকাটা সম্পূর্ণ করা যায়নি। আবার চেষ্টা করুন।';
@override
String get restauracionSinCompras =>
'এই অ্যাকাউন্টে আমরা আগের কোনো কেনাকাটা খুঁজে পাইনি।';
@override
String get premiumActivo => 'প্রিমিয়াম সক্রিয়';
@override
String get premiumHojaTitulo => 'PluriWave Premium আনলক করুন';
@override
String get premiumBeneficioSinAnuncios => 'পুরো অ্যাপে কোনো বিজ্ঞাপন নেই';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'স্টেশন রেকর্ডিং';
@override
String get premiumBeneficioVacaciones => 'অ্যালার্মের জন্য ছুটির সময়কাল';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'সীমাহীন অ্যালার্ম (ফ্রি প্ল্যানে সর্বোচ্চ ৫টি অনুমোদিত)';
@override
String get premiumPagoUnico =>
'একবারের পেমেন্ট, চিরকালের জন্য। এটি সাবস্ক্রিপশন নয়।';
@override
String get premiumAhoraNo => 'এখন নয়';
@override
String get autoErrorEmisoraPremium =>
'এই স্টেশনটি Premium। আনলক করতে ফোনে PluriWave খুলুন।';
@override
String get autoErrorBusquedaSinResultados =>
'সেই স্টেশনটি খুঁজে পাওয়া যায়নি। অন্য নাম চেষ্টা করুন।';
@override
String get autoCarpetaEscuchar => 'শুনুন';
@override
String get autoCarpetaFavoritos => 'প্রিয়';
@override
String get autoCarpetaTodas => 'সব স্টেশন';
@override
String get autoCarpetaMisEmisoras => 'আমার স্টেশন';
@override
String get autoCarpetaMusicaLocal => 'স্থানীয় সঙ্গীত';
@override
String get autoMusicaLocalNoDisponible =>
'আপনার গান পড়তে ফোনে PluriWave খুলুন';
@override
String get autoCargarMas => 'আরও…';
@override
String get autoOrdenarPorCalidad => 'মান অনুসারে সাজান';
@override
String get autoReproducirCarpeta => 'ফোল্ডার চালান';
@override
String get autoReproducirAleatorio => 'এলোমেলোভাবে চালান';
@override
String get autoPistaSinNombre => 'নামহীন ট্র্যাক';
}
+91
View File
@@ -1864,4 +1864,95 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get autoEqDisableOption => 'Deaktivieren';
@override
String get funcionPremium => 'Premium-Funktion';
@override
String get limiteAlarmasAlcanzado =>
'Du hast das kostenlose Limit von 5 Weckern erreicht.';
@override
String get desbloquearPremium => 'Premium freischalten';
@override
String get restaurarCompras => 'Käufe wiederherstellen';
@override
String get compraError =>
'Der Kauf konnte nicht abgeschlossen werden. Bitte versuche es erneut.';
@override
String get restauracionSinCompras =>
'Wir haben auf diesem Konto keinen früheren Kauf gefunden.';
@override
String get premiumActivo => 'Premium aktiv';
@override
String get premiumHojaTitulo => 'PluriWave Premium freischalten';
@override
String get premiumBeneficioSinAnuncios => 'Keine Werbung in der gesamten App';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Sender aufnehmen';
@override
String get premiumBeneficioVacaciones => 'Urlaubszeiträume für Wecker';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Unbegrenzte Wecker (die kostenlose Version erlaubt bis zu 5)';
@override
String get premiumPagoUnico => 'Einmalzahlung, für immer. Kein Abonnement.';
@override
String get premiumAhoraNo => 'Nicht jetzt';
@override
String get autoErrorEmisoraPremium =>
'Dieser Sender ist Premium. Öffne PluriWave auf dem Handy, um ihn freizuschalten.';
@override
String get autoErrorBusquedaSinResultados =>
'Wir haben diesen Sender nicht gefunden. Versuch es mit einem anderen Namen.';
@override
String get autoCarpetaEscuchar => 'Hören';
@override
String get autoCarpetaFavoritos => 'Favoriten';
@override
String get autoCarpetaTodas => 'Alle Sender';
@override
String get autoCarpetaMisEmisoras => 'Meine Sender';
@override
String get autoCarpetaMusicaLocal => 'Lokale Musik';
@override
String get autoMusicaLocalNoDisponible =>
'Öffne PluriWave auf dem Handy, um deine Musik zu lesen';
@override
String get autoCargarMas => 'Mehr…';
@override
String get autoOrdenarPorCalidad => 'Nach Qualität sortieren';
@override
String get autoReproducirCarpeta => 'Ordner abspielen';
@override
String get autoReproducirAleatorio => 'Zufallswiedergabe';
@override
String get autoPistaSinNombre => 'Unbenannter Titel';
}
+92
View File
@@ -1843,4 +1843,96 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get autoEqDisableOption => 'Disable';
@override
String get funcionPremium => 'Premium Feature';
@override
String get limiteAlarmasAlcanzado =>
'You\'ve reached the free 5-alarm limit.';
@override
String get desbloquearPremium => 'Unlock Premium';
@override
String get restaurarCompras => 'Restore purchases';
@override
String get compraError =>
'We couldn\'t complete the purchase. Please try again.';
@override
String get restauracionSinCompras =>
'We didn\'t find any previous purchase on this account.';
@override
String get premiumActivo => 'Premium active';
@override
String get premiumHojaTitulo => 'Unlock PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => 'No ads anywhere in the app';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Station recording';
@override
String get premiumBeneficioVacaciones => 'Vacation ranges for alarms';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Unlimited alarms (the free plan allows up to 5)';
@override
String get premiumPagoUnico =>
'One-time purchase, forever. Not a subscription.';
@override
String get premiumAhoraNo => 'Not now';
@override
String get autoErrorEmisoraPremium =>
'This station is Premium. Open PluriWave on your phone to unlock it.';
@override
String get autoErrorBusquedaSinResultados =>
'We couldn\'t find that station. Try another name.';
@override
String get autoCarpetaEscuchar => 'Listen';
@override
String get autoCarpetaFavoritos => 'Favorites';
@override
String get autoCarpetaTodas => 'All stations';
@override
String get autoCarpetaMisEmisoras => 'My stations';
@override
String get autoCarpetaMusicaLocal => 'Local music';
@override
String get autoMusicaLocalNoDisponible =>
'Open PluriWave on your phone to read your music';
@override
String get autoCargarMas => 'More…';
@override
String get autoOrdenarPorCalidad => 'Sort by quality';
@override
String get autoReproducirCarpeta => 'Play folder';
@override
String get autoReproducirAleatorio => 'Shuffle play';
@override
String get autoPistaSinNombre => 'Untitled track';
}
+93
View File
@@ -1857,4 +1857,97 @@ class AppLocalizationsEs extends AppLocalizations {
@override
String get autoEqDisableOption => 'Desactivar';
@override
String get funcionPremium => 'Función Premium';
@override
String get limiteAlarmasAlcanzado =>
'Has alcanzado el límite de 5 alarmas gratuitas.';
@override
String get desbloquearPremium => 'Desbloquear Premium';
@override
String get restaurarCompras => 'Restaurar compras';
@override
String get compraError =>
'No se ha podido completar la compra. Inténtalo de nuevo.';
@override
String get restauracionSinCompras =>
'No hemos encontrado ninguna compra anterior en esta cuenta.';
@override
String get premiumActivo => 'Premium activo';
@override
String get premiumHojaTitulo => 'Desbloquea PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => 'Sin publicidad en toda la app';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Grabación de emisoras';
@override
String get premiumBeneficioVacaciones =>
'Rangos de vacaciones para las alarmas';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Alarmas ilimitadas (el plan gratuito permite hasta 5)';
@override
String get premiumPagoUnico =>
'Pago único, para siempre. No es una suscripción.';
@override
String get premiumAhoraNo => 'Ahora no';
@override
String get autoErrorEmisoraPremium =>
'Esta emisora es Premium. Abre PluriWave en el móvil para desbloquearla.';
@override
String get autoErrorBusquedaSinResultados =>
'No hemos encontrado esa emisora. Prueba con otro nombre.';
@override
String get autoCarpetaEscuchar => 'Escuchar';
@override
String get autoCarpetaFavoritos => 'Favoritos';
@override
String get autoCarpetaTodas => 'Todas las emisoras';
@override
String get autoCarpetaMisEmisoras => 'Mis emisoras';
@override
String get autoCarpetaMusicaLocal => 'Música Local';
@override
String get autoMusicaLocalNoDisponible =>
'Abre PluriWave en el móvil para leer tu música';
@override
String get autoCargarMas => 'Más…';
@override
String get autoOrdenarPorCalidad => 'Ordenar por calidad';
@override
String get autoReproducirCarpeta => 'Reproducir carpeta';
@override
String get autoReproducirAleatorio => 'Reproducir aleatorio';
@override
String get autoPistaSinNombre => 'Pista sin nombre';
}
+94
View File
@@ -1870,4 +1870,98 @@ class AppLocalizationsFr extends AppLocalizations {
@override
String get autoEqDisableOption => 'Désactiver';
@override
String get funcionPremium => 'Fonctionnalité Premium';
@override
String get limiteAlarmasAlcanzado =>
'Vous avez atteint la limite gratuite de 5 alarmes.';
@override
String get desbloquearPremium => 'Débloquer Premium';
@override
String get restaurarCompras => 'Restaurer les achats';
@override
String get compraError =>
'Impossible de finaliser l\'achat. Veuillez réessayer.';
@override
String get restauracionSinCompras =>
'Nous n\'avons trouvé aucun achat antérieur sur ce compte.';
@override
String get premiumActivo => 'Premium actif';
@override
String get premiumHojaTitulo => 'Débloquer PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios =>
'Aucune publicité dans toute l\'application';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Enregistrement des stations';
@override
String get premiumBeneficioVacaciones =>
'Périodes de vacances pour les alarmes';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Alarmes illimitées (la version gratuite en autorise jusqu\'à 5)';
@override
String get premiumPagoUnico =>
'Achat unique, pour toujours. Ce n\'est pas un abonnement.';
@override
String get premiumAhoraNo => 'Plus tard';
@override
String get autoErrorEmisoraPremium =>
'Cette station est Premium. Ouvre PluriWave sur ton téléphone pour la débloquer.';
@override
String get autoErrorBusquedaSinResultados =>
'Nous n\'avons pas trouvé cette station. Essaie un autre nom.';
@override
String get autoCarpetaEscuchar => 'Écouter';
@override
String get autoCarpetaFavoritos => 'Favoris';
@override
String get autoCarpetaTodas => 'Toutes les stations';
@override
String get autoCarpetaMisEmisoras => 'Mes stations';
@override
String get autoCarpetaMusicaLocal => 'Musique locale';
@override
String get autoMusicaLocalNoDisponible =>
'Ouvrez PluriWave sur votre téléphone pour lire votre musique';
@override
String get autoCargarMas => 'Plus…';
@override
String get autoOrdenarPorCalidad => 'Trier par qualité';
@override
String get autoReproducirCarpeta => 'Lire le dossier';
@override
String get autoReproducirAleatorio => 'Lecture aléatoire';
@override
String get autoPistaSinNombre => 'Piste sans nom';
}
+91
View File
@@ -1844,4 +1844,95 @@ class AppLocalizationsHi extends AppLocalizations {
@override
String get autoEqDisableOption => 'बंद करें';
@override
String get funcionPremium => 'प्रीमियम सुविधा';
@override
String get limiteAlarmasAlcanzado =>
'आप मुफ़्त 5 अलार्म की सीमा तक पहुँच गए हैं।';
@override
String get desbloquearPremium => 'प्रीमियम अनलॉक करें';
@override
String get restaurarCompras => 'खरीदारी पुनर्स्थापित करें';
@override
String get compraError => 'खरीद पूरी नहीं हो सकी। कृपया फिर से प्रयास करें।';
@override
String get restauracionSinCompras =>
'इस खाते में हमें कोई पिछली खरीद नहीं मिली।';
@override
String get premiumActivo => 'प्रीमियम सक्रिय';
@override
String get premiumHojaTitulo => 'PluriWave Premium अनलॉक करें';
@override
String get premiumBeneficioSinAnuncios => 'पूरे ऐप में कोई विज्ञापन नहीं';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'स्टेशन रिकॉर्डिंग';
@override
String get premiumBeneficioVacaciones => 'अलार्म के लिए छुट्टी की अवधि';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'असीमित अलार्म (मुफ़्त प्लान में अधिकतम 5 की अनुमति है)';
@override
String get premiumPagoUnico =>
'एकमुश्त भुगतान, हमेशा के लिए। यह सदस्यता नहीं है।';
@override
String get premiumAhoraNo => 'अभी नहीं';
@override
String get autoErrorEmisoraPremium =>
'यह स्टेशन Premium है। इसे अनलॉक करने के लिए फ़ोन पर PluriWave खोलें।';
@override
String get autoErrorBusquedaSinResultados =>
'वह स्टेशन नहीं मिला। कोई दूसरा नाम आज़माएँ।';
@override
String get autoCarpetaEscuchar => 'सुनें';
@override
String get autoCarpetaFavoritos => 'पसंदीदा';
@override
String get autoCarpetaTodas => 'सभी स्टेशन';
@override
String get autoCarpetaMisEmisoras => 'मेरे स्टेशन';
@override
String get autoCarpetaMusicaLocal => 'लोकल संगीत';
@override
String get autoMusicaLocalNoDisponible =>
'अपना संगीत पढ़ने के लिए फ़ोन पर PluriWave खोलें';
@override
String get autoCargarMas => 'और…';
@override
String get autoOrdenarPorCalidad => 'गुणवत्ता के अनुसार क्रमबद्ध करें';
@override
String get autoReproducirCarpeta => 'फ़ोल्डर चलाएँ';
@override
String get autoReproducirAleatorio => 'शफ़ल चलाएँ';
@override
String get autoPistaSinNombre => 'बिना नाम का ट्रैक';
}
+92
View File
@@ -1854,4 +1854,96 @@ class AppLocalizationsId extends AppLocalizations {
@override
String get autoEqDisableOption => 'Nonaktifkan';
@override
String get funcionPremium => 'Fitur Premium';
@override
String get limiteAlarmasAlcanzado =>
'Anda telah mencapai batas gratis 5 alarm.';
@override
String get desbloquearPremium => 'Buka Premium';
@override
String get restaurarCompras => 'Pulihkan pembelian';
@override
String get compraError =>
'Pembelian tidak dapat diselesaikan. Silakan coba lagi.';
@override
String get restauracionSinCompras =>
'Kami tidak menemukan pembelian sebelumnya di akun ini.';
@override
String get premiumActivo => 'Premium aktif';
@override
String get premiumHojaTitulo => 'Buka PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => 'Tanpa iklan di seluruh aplikasi';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Perekaman stasiun';
@override
String get premiumBeneficioVacaciones => 'Rentang liburan untuk alarm';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Alarm tanpa batas (paket gratis mengizinkan hingga 5)';
@override
String get premiumPagoUnico =>
'Pembelian sekali bayar, untuk selamanya. Bukan langganan.';
@override
String get premiumAhoraNo => 'Nanti saja';
@override
String get autoErrorEmisoraPremium =>
'Stasiun ini Premium. Buka PluriWave di ponsel untuk membukanya.';
@override
String get autoErrorBusquedaSinResultados =>
'Kami tidak menemukan stasiun itu. Coba nama lain.';
@override
String get autoCarpetaEscuchar => 'Dengarkan';
@override
String get autoCarpetaFavoritos => 'Favorit';
@override
String get autoCarpetaTodas => 'Semua stasiun';
@override
String get autoCarpetaMisEmisoras => 'Stasiun saya';
@override
String get autoCarpetaMusicaLocal => 'Musik lokal';
@override
String get autoMusicaLocalNoDisponible =>
'Buka PluriWave di ponsel untuk membaca musik Anda';
@override
String get autoCargarMas => 'Lainnya…';
@override
String get autoOrdenarPorCalidad => 'Urutkan menurut kualitas';
@override
String get autoReproducirCarpeta => 'Putar folder';
@override
String get autoReproducirAleatorio => 'Putar acak';
@override
String get autoPistaSinNombre => 'Trek tanpa nama';
}
+94
View File
@@ -1867,4 +1867,98 @@ class AppLocalizationsIt extends AppLocalizations {
@override
String get autoEqDisableOption => 'Disattiva';
@override
String get funcionPremium => 'Funzione Premium';
@override
String get limiteAlarmasAlcanzado =>
'Hai raggiunto il limite gratuito di 5 sveglie.';
@override
String get desbloquearPremium => 'Sblocca Premium';
@override
String get restaurarCompras => 'Ripristina acquisti';
@override
String get compraError =>
'Non è stato possibile completare l\'acquisto. Riprova.';
@override
String get restauracionSinCompras =>
'Non abbiamo trovato acquisti precedenti su questo account.';
@override
String get premiumActivo => 'Premium attivo';
@override
String get premiumHojaTitulo => 'Sblocca PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios =>
'Nessuna pubblicità in tutta l\'app';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Registrazione delle stazioni';
@override
String get premiumBeneficioVacaciones =>
'Intervalli di vacanza per le sveglie';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Sveglie illimitate (il piano gratuito ne consente fino a 5)';
@override
String get premiumPagoUnico =>
'Acquisto unico, per sempre. Non è un abbonamento.';
@override
String get premiumAhoraNo => 'Non ora';
@override
String get autoErrorEmisoraPremium =>
'Questa stazione è Premium. Apri PluriWave sul telefono per sbloccarla.';
@override
String get autoErrorBusquedaSinResultados =>
'Non abbiamo trovato quella stazione. Prova con un altro nome.';
@override
String get autoCarpetaEscuchar => 'Ascolta';
@override
String get autoCarpetaFavoritos => 'Preferiti';
@override
String get autoCarpetaTodas => 'Tutte le emittenti';
@override
String get autoCarpetaMisEmisoras => 'Le mie emittenti';
@override
String get autoCarpetaMusicaLocal => 'Musica locale';
@override
String get autoMusicaLocalNoDisponible =>
'Apri PluriWave sul telefono per leggere la tua musica';
@override
String get autoCargarMas => 'Altro…';
@override
String get autoOrdenarPorCalidad => 'Ordina per qualità';
@override
String get autoReproducirCarpeta => 'Riproduci cartella';
@override
String get autoReproducirAleatorio => 'Riproduzione casuale';
@override
String get autoPistaSinNombre => 'Traccia senza nome';
}
+86
View File
@@ -1791,4 +1791,90 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get autoEqDisableOption => '無効化';
@override
String get funcionPremium => 'プレミアム機能';
@override
String get limiteAlarmasAlcanzado => '無料プランのアラーム上限(5件)に達しました。';
@override
String get desbloquearPremium => 'プレミアムを解除';
@override
String get restaurarCompras => '購入を復元';
@override
String get compraError => '購入を完了できませんでした。もう一度お試しください。';
@override
String get restauracionSinCompras => 'このアカウントでは以前の購入が見つかりませんでした。';
@override
String get premiumActivo => 'プレミアム有効';
@override
String get premiumHojaTitulo => 'PluriWave Premiumのロックを解除';
@override
String get premiumBeneficioSinAnuncios => 'アプリ全体で広告なし';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => '放送局の録音';
@override
String get premiumBeneficioVacaciones => 'アラームの休暇期間設定';
@override
String get premiumBeneficioAlarmasIlimitadas => 'アラーム数無制限(無料プランは5個まで)';
@override
String get premiumPagoUnico => '買い切りの一度きりの支払いで永久に使用可能。サブスクリプションではありません。';
@override
String get premiumAhoraNo => '後で';
@override
String get autoErrorEmisoraPremium =>
'この放送局は Premium です。スマートフォンで PluriWave を開いてロックを解除してください。';
@override
String get autoErrorBusquedaSinResultados => 'その放送局は見つかりませんでした。別の名前をお試しください。';
@override
String get autoCarpetaEscuchar => '聴く';
@override
String get autoCarpetaFavoritos => 'お気に入り';
@override
String get autoCarpetaTodas => 'すべての局';
@override
String get autoCarpetaMisEmisoras => 'マイ局';
@override
String get autoCarpetaMusicaLocal => 'ローカルの音楽';
@override
String get autoMusicaLocalNoDisponible =>
'音楽を読み込むにはスマートフォンで PluriWave を開いてください';
@override
String get autoCargarMas => 'もっと見る…';
@override
String get autoOrdenarPorCalidad => '音質順に並べ替え';
@override
String get autoReproducirCarpeta => 'フォルダを再生';
@override
String get autoReproducirAleatorio => 'シャッフル再生';
@override
String get autoPistaSinNombre => '名称未設定のトラック';
}
+92
View File
@@ -1854,4 +1854,96 @@ class AppLocalizationsPt extends AppLocalizations {
@override
String get autoEqDisableOption => 'Desativar';
@override
String get funcionPremium => 'Recurso Premium';
@override
String get limiteAlarmasAlcanzado =>
'Você atingiu o limite gratuito de 5 alarmes.';
@override
String get desbloquearPremium => 'Desbloquear Premium';
@override
String get restaurarCompras => 'Restaurar compras';
@override
String get compraError =>
'Não foi possível concluir a compra. Tente novamente.';
@override
String get restauracionSinCompras =>
'Não encontramos nenhuma compra anterior nesta conta.';
@override
String get premiumActivo => 'Premium ativo';
@override
String get premiumHojaTitulo => 'Desbloqueie o PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => 'Sem anúncios em todo o app';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Gravação de emissoras';
@override
String get premiumBeneficioVacaciones => 'Períodos de férias para os alarmes';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Alarmes ilimitados (o plano gratuito permite até 5)';
@override
String get premiumPagoUnico =>
'Pagamento único, para sempre. Não é uma assinatura.';
@override
String get premiumAhoraNo => 'Agora não';
@override
String get autoErrorEmisoraPremium =>
'Esta estação é Premium. Abra o PluriWave no telemóvel para a desbloquear.';
@override
String get autoErrorBusquedaSinResultados =>
'Não encontrámos essa estação. Tente outro nome.';
@override
String get autoCarpetaEscuchar => 'Ouvir';
@override
String get autoCarpetaFavoritos => 'Favoritos';
@override
String get autoCarpetaTodas => 'Todas as estações';
@override
String get autoCarpetaMisEmisoras => 'As minhas estações';
@override
String get autoCarpetaMusicaLocal => 'Música local';
@override
String get autoMusicaLocalNoDisponible =>
'Abra o PluriWave no telemóvel para ler a sua música';
@override
String get autoCargarMas => 'Mais…';
@override
String get autoOrdenarPorCalidad => 'Ordenar por qualidade';
@override
String get autoReproducirCarpeta => 'Reproduzir pasta';
@override
String get autoReproducirAleatorio => 'Reprodução aleatória';
@override
String get autoPistaSinNombre => 'Faixa sem nome';
}
+92
View File
@@ -1861,4 +1861,96 @@ class AppLocalizationsRu extends AppLocalizations {
@override
String get autoEqDisableOption => 'Отключить';
@override
String get funcionPremium => 'Премиум-функция';
@override
String get limiteAlarmasAlcanzado =>
'Вы достигли бесплатного лимита в 5 будильников.';
@override
String get desbloquearPremium => 'Разблокировать Премиум';
@override
String get restaurarCompras => 'Восстановить покупки';
@override
String get compraError => 'Не удалось завершить покупку. Попробуйте ещё раз.';
@override
String get restauracionSinCompras =>
'Мы не нашли предыдущих покупок на этом аккаунте.';
@override
String get premiumActivo => 'Премиум активен';
@override
String get premiumHojaTitulo => 'Разблокировать PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios =>
'Никакой рекламы во всём приложении';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => 'Запись радиостанций';
@override
String get premiumBeneficioVacaciones => 'Периоды отпуска для будильников';
@override
String get premiumBeneficioAlarmasIlimitadas =>
'Неограниченное количество будильников (бесплатный план позволяет до 5)';
@override
String get premiumPagoUnico =>
'Единоразовая покупка, навсегда. Это не подписка.';
@override
String get premiumAhoraNo => 'Не сейчас';
@override
String get autoErrorEmisoraPremium =>
'Эта станция доступна в Premium. Откройте PluriWave на телефоне, чтобы разблокировать её.';
@override
String get autoErrorBusquedaSinResultados =>
'Мы не нашли такую станцию. Попробуйте другое название.';
@override
String get autoCarpetaEscuchar => 'Слушать';
@override
String get autoCarpetaFavoritos => 'Избранное';
@override
String get autoCarpetaTodas => 'Все станции';
@override
String get autoCarpetaMisEmisoras => 'Мои станции';
@override
String get autoCarpetaMusicaLocal => 'Локальная музыка';
@override
String get autoMusicaLocalNoDisponible =>
'Откройте PluriWave на телефоне, чтобы прочитать вашу музыку';
@override
String get autoCargarMas => 'Ещё…';
@override
String get autoOrdenarPorCalidad => 'Сортировать по качеству';
@override
String get autoReproducirCarpeta => 'Воспроизвести папку';
@override
String get autoReproducirAleatorio => 'Случайное воспроизведение';
@override
String get autoPistaSinNombre => 'Трек без названия';
}
+85
View File
@@ -1776,4 +1776,89 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get autoEqDisableOption => '关闭';
@override
String get funcionPremium => '高级功能';
@override
String get limiteAlarmasAlcanzado => '您已达到免费版 5 个闹钟的上限。';
@override
String get desbloquearPremium => '解锁高级版';
@override
String get restaurarCompras => '恢复购买';
@override
String get compraError => '无法完成购买,请重试。';
@override
String get restauracionSinCompras => '未在此账户中找到以前的购买记录。';
@override
String get premiumActivo => '高级版已解锁';
@override
String get premiumHojaTitulo => '解锁 PluriWave Premium';
@override
String get premiumBeneficioSinAnuncios => '全应用无广告';
@override
String get premiumBeneficioAndroidAuto => 'Android Auto';
@override
String get premiumBeneficioGrabacion => '电台录音';
@override
String get premiumBeneficioVacaciones => '闹钟的假期时间段';
@override
String get premiumBeneficioAlarmasIlimitadas => '无限闹钟(免费版最多支持5个)';
@override
String get premiumPagoUnico => '一次性付费,永久使用,不是订阅。';
@override
String get premiumAhoraNo => '以后再说';
@override
String get autoErrorEmisoraPremium =>
'该电台属于 Premium 内容。请在手机上打开 PluriWave 解锁。';
@override
String get autoErrorBusquedaSinResultados => '没有找到该电台。请换个名称再试。';
@override
String get autoCarpetaEscuchar => '收听';
@override
String get autoCarpetaFavoritos => '收藏';
@override
String get autoCarpetaTodas => '全部电台';
@override
String get autoCarpetaMisEmisoras => '我的电台';
@override
String get autoCarpetaMusicaLocal => '本地音乐';
@override
String get autoMusicaLocalNoDisponible => '请在手机上打开 PluriWave 以读取您的音乐';
@override
String get autoCargarMas => '更多…';
@override
String get autoOrdenarPorCalidad => '按音质排序';
@override
String get autoReproducirCarpeta => '播放文件夹';
@override
String get autoReproducirAleatorio => '随机播放';
@override
String get autoPistaSinNombre => '未命名曲目';
}
+291 -40
View File
@@ -1,16 +1,25 @@
import 'dart:async';
import 'dart:developer' as developer;
import 'dart:ui' as ui;
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'app.dart';
import 'estado/estado_entitlement.dart';
import 'servicios/arranque_audio.dart';
import 'servicios/contexto_reproduccion.dart';
import 'servicios/emisoras_destacadas.dart';
import 'servicios/musica_local_auto.dart';
import 'servicios/navegacion_auto.dart';
import 'servicios/servicio_audio.dart';
import 'servicios/servicio_audio_session.dart';
import 'servicios/servicio_compras.dart';
import 'servicios/servicio_consentimiento.dart';
import 'servicios/servicio_ecualizador.dart';
import 'servicios/servicio_presets_personalizados.dart';
import 'tema/pluriwave_tokens.dart';
const _anchoMinimoLandscape = 600.0;
@@ -24,36 +33,138 @@ const androidNotificationIconResource = 'drawable/ic_stat_pluriwave';
const configuracionAudioService = AudioServiceConfig(
androidNotificationChannelId: 'es.freetimelab.pluriwave.audio',
androidNotificationChannelName: 'PluriWave Radio',
androidNotificationOngoing: true,
androidStopForegroundOnPause: true,
// Paired with `androidStopForegroundOnPause: false` below, and required to
// be: the plugin asserts `androidNotificationOngoing` implies
// `androidStopForegroundOnPause`. Nothing is lost by turning it off —
// while the service is in the foreground the OS forces the notification to
// be ongoing anyway, which is now the whole time playback is alive.
androidNotificationOngoing: false,
// The service stays in the FOREGROUND while paused.
//
// With `true`, a pause called `stopForeground(...)`, and a service that is
// not in the foreground is a service Android may kill at will. In the car
// that is exactly what happened: an interruption paused playback, the
// service dropped out of the foreground, Android reclaimed it, and
// PluriWave disappeared from the Android Auto pane — another media app
// took the slot. Ducking (see `ServicioAudioSession.configurar`) removes
// most pauses, but a real pause must not be a death sentence either.
//
// The plugin's own doc for this flag says it outright: «while in this
// lower priority state, the operating system will also be able to kill
// your service at any time to reclaim resources».
//
// Cost of `false`: the notification is not swipe-dismissible while paused,
// only after Stop. That is how every serious media app behaves, and Stop
// still tears everything down.
androidStopForegroundOnPause: false,
notificationColor: PluriWaveTokens.brand,
androidNotificationIcon: androidNotificationIconResource,
);
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await _aplicarPoliticaOrientacion();
// Android Auto browse source: registered FIRST, before any await at all.
// It depends on nothing, and everything below it is a potential place to
// get stuck — so nothing may sit between engine start and this line.
//
// Reported: with Android Auto connected, the car screen sometimes came up
// black and the app then opened WHITE on the phone until it was
// force-killed. `AudioServiceActivity.provideFlutterEngine` returns the
// engine from `AudioServicePlugin.getFlutterEngine`, which CREATES the
// engine and runs `main()` headlessly the first time — with no Activity —
// when the car binds the MediaBrowserService before the app is opened.
// `_aplicarPoliticaOrientacion` used to be the first `await` here, and
// `SystemChrome.setPreferredOrientations` travels the `flutter/platform`
// channel, whose handler (`PlatformPlugin`) is installed by the Activity.
// Headless there is nobody to answer it, so `main()` died or hung on line
// one: the browse source below 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,
// and only a force-kill (which disposes the engine) recovered it.
final fuenteAuto = FuenteEmisorasAutoLocal();
registrarFuenteNavegacion(fuenteAuto);
// Local music registers HERE, above every await, alongside the station
// source — not after `SharedPreferences.getInstance()` where it used to
// sit.
//
// Regression this fixes, self-inflicted by the reordering above: the root
// menu decides whether to offer "Música Local" with
// `fuenteLocal != null && await fuenteLocal.estadoCarpeta() != noConfigurada`.
// Moving ONLY the station source above the awaits meant the car could get
// a root response in the window before this line ran, find a null source,
// and be told there is no local music — and Android Auto caches the browse
// root, so it stayed missing for the whole session. Before the reorder
// both registrations sat together after the await, so the window did not
// exist.
//
// `FuenteMusicaLocalAutoImpl` needs no prefs to be CONSTRUCTED: it
// resolves them lazily per call (`_resolverPrefs`, falling back to
// `getInstance()`), the same convention `ServicioAlarmas` uses. So there
// was never a reason for it to wait on that await.
registrarFuenteMusicaLocal(FuenteMusicaLocalAutoImpl());
// Cosmetic, and deliberately NOT awaited: a display preference must never
// gate `runApp`. `OrientacionResponsiveApp.didChangeDependencies` applies
// it again as soon as a real view exists, which is the only moment it can
// actually take effect anyway.
unawaited(aplicarPoliticaOrientacion());
// iap-freemium-unlock: neither SDK init call blocks `runApp` — a purchase
// stream subscription and an ad-SDK warm-up are both safe to finish late
// (mirrors `aplicarPoliticaOrientacion`'s "cosmetic, never gates startup"
// rule immediately above).
//
// FIX 4 (code review): the Mobile Ads SDK is only initialized AFTER the
// GDPR/UMP consent flow resolves that ads may actually be requested
// (`ConsentInformation.canRequestAds()`) — serving personalized ads to
// EEA/UK users with no CMP violates Google's EU User Consent Policy.
// Premium users never even reach the consent form (`resolverConsentimientoAnuncios`
// short-circuits for them — they get zero ads regardless). This whole
// chain is deliberately `unawaited`: consent/ads are exactly as
// "cosmetic, never gates startup" as `aplicarPoliticaOrientacion` above,
// and any failure inside it degrades to "no ads", never a crash or a
// blocked UI.
unawaited(
esPremiumPersistido()
.then(
(premium) => resolverConsentimientoAnuncios(
esPremium: premium,
consentimiento: ServicioConsentimientoUmp(),
),
)
.then((puedeSolicitarAnuncios) async {
if (puedeSolicitarAnuncios) {
await MobileAds.instance.initialize();
}
}),
);
final compras = ServicioComprasPlayBilling();
// S3-R4: single SharedPreferences instance resolved once at startup and
// injected into every state/service below.
final prefs = await SharedPreferences.getInstance();
// Android Auto browse source (Design "getChildren data source, cold-start
// safe") — registered BEFORE the AudioService.init await below (Design
// "Reorder handler-independent startup work before the init await"):
// neither this nor the local-music registration depends on the
// AudioHandler, so browse sources exist for the car even while the
// MediaBrowser handshake (no native timeout, see arranque_audio.dart) is
// still pending.
final fuenteAuto = FuenteEmisorasAutoLocal();
registrarFuenteNavegacion(fuenteAuto);
// User-saved EQ presets for the car's Ecualizador folder, same
// injectable-prefs DI convention and same pre-init placement as the two
// registrations above (neither depends on the AudioHandler). Passed as a
// read function, not the service, so the folder re-reads on every browse:
// a preset saved on the phone appears in the car without an app restart.
final presetsPersonalizados = ServicioPresetsPersonalizados(prefs: prefs);
registrarFuentePresetsPersonalizados(presetsPersonalizados.listar);
// Local-music browse source (Design "getChildren data source
// registration"), same injectable-prefs DI convention as every other
// startup service — required so `_fuenteMusicaLocalGlobal` is ever
// non-null; without this registration the local-music root would stay
// permanently hidden (`hayCarpetaConfigurada()` has no fuente to ask).
registrarFuenteMusicaLocal(FuenteMusicaLocalAutoImpl(prefs: prefs));
// eq-estado-unico items A/B: the handler's own link to the equalizer's
// persisted on/off flag. `ServicioEcualizador` needs nothing but the
// `prefs` instance resolved just above — no widget tree, no Provider — so
// it is available on EVERY engine, including the headless one Android Auto
// starts. Before this, the persisted value only reached the handler
// through `EstadoEcualizador.cargarPersistido()`, which that engine never
// runs: the handler played with the equalizer forced on while disk and the
// phone UI both said off, and a toggle made in the car was lost on
// restart. Passed as two narrow function ports, mirroring the
// read-function convention used for the preset folder right above.
final ecualizador = ServicioEcualizador(prefs: prefs);
// Silent-error channel (fix/notificacion-media): `AudioService.asyncError`
// had ZERO subscribers app-wide, and a `PublishSubject` with no listeners
@@ -83,7 +194,33 @@ Future<void> main() async {
// radio; headphones unplugged pauses it. Shared by both the on-time and
// degraded/late-completion paths below.
void conectarHandler(PluriWaveAudioHandler handler) {
registrarHandler(handler);
registrarHandler(
handler,
leerEqActivoPersistido: ecualizador.leerActivo,
guardarEqActivoPersistido: ecualizador.guardarActivo,
// The PRESET's half of the same seam. Without it the handler enabled
// the equalizer with its hardcoded FLAT preset on any engine where the
// phone UI never ran — i.e. every headless Android Auto bind. There is
// no write port: `EstadoEcualizador` still owns saving presets (a car
// preset choice goes through it), so the handler only ever reads.
leerPresetPersistido: ecualizador.leerPresetPrincipal,
// Skip context («in which list am I»). Bound here, on the audio
// bootstrap path of EVERY engine, precisely because the headless
// Android Auto engine builds no widget tree and therefore no
// `EstadoRadio`: a context only the phone UI could write would be a
// context the car could never have.
leerContextoSalto: contextoSaltoPersistido,
guardarContextoSalto: guardarContextoSalto,
// Last played station (`ultima_emisora_v1`). Bound here for the SAME
// reason as the skip context: `EstadoRadio` — which used to be its only
// writer — belongs to the widget tree, and the Android Auto engine
// builds none, so a session that happened only in the car never updated
// the key and the head unit was offered whatever the PHONE last played.
// The write port is now the key's single writer; the read port feeds the
// cold-start metadata seed and the bare-`play()` resume.
leerUltimaEmisora: ultimaEmisoraPersistida,
guardarUltimaEmisora: guardarUltimaEmisoraPersistida,
);
// The handler is the only thing this app ever tears down
// (`onTaskRemoved`), so the asyncError subscription's `cancel` travels
// with it and can never leak — same "register from main.dart" convention
@@ -93,8 +230,8 @@ Future<void> main() async {
unawaited(sesionAudio.configurar());
}
Widget construirApp() => _OrientacionResponsiveApp(
child: PluriWaveApp(prefs: prefs, fuenteAuto: fuenteAuto),
Widget construirApp() => OrientacionResponsiveApp(
child: PluriWaveApp(prefs: prefs, fuenteAuto: fuenteAuto, compras: compras),
);
final resultado = await esperarArranqueAudio(handlerFuturo);
@@ -122,37 +259,130 @@ Future<void> main() async {
}
}
Future<void> _aplicarPoliticaOrientacion([ui.Display? display]) async {
final vista =
WidgetsBinding.instance.platformDispatcher.views.isNotEmpty
? WidgetsBinding.instance.platformDispatcher.views.first
: null;
final displayActivo = display ?? vista?.display;
if (displayActivo == null) return;
/// Which orientations a display [anchoLogico] dp wide may use: phones stay
/// portrait, tablets get everything. Pure, so the policy is testable without
/// a platform channel.
@visibleForTesting
List<DeviceOrientation> orientacionesPara(double anchoLogico) =>
anchoLogico < _anchoMinimoLandscape
? const [DeviceOrientation.portraitUp]
: DeviceOrientation.values;
final anchoLogico = displayActivo.size.width / displayActivo.devicePixelRatio;
if (anchoLogico < _anchoMinimoLandscape) {
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
return;
/// Applies [orientacionesPara] to the active display.
///
/// NEVER throws and never blocks a caller that matters. This runs on the
/// headless engine Android Auto starts (see `main`), where the
/// `flutter/platform` channel has no handler because there is no Activity to
/// install `PlatformPlugin` — so the call can fail with a
/// `MissingPluginException` or simply never be answered. Before this guard
/// that outcome killed `main()` outright, taking the Android Auto browse
/// registration and `runApp` with it.
///
/// [aplicar] is injectable so the swallow-everything contract is testable
/// without a real platform channel.
@visibleForTesting
Future<void> aplicarPoliticaOrientacion({
ui.Display? display,
Future<void> Function(List<DeviceOrientation>)? aplicar,
}) async {
try {
final vista =
WidgetsBinding.instance.platformDispatcher.views.isNotEmpty
? WidgetsBinding.instance.platformDispatcher.views.first
: null;
final displayActivo = display ?? vista?.display;
if (displayActivo == null) return;
final anchoLogico =
displayActivo.size.width / displayActivo.devicePixelRatio;
await (aplicar ?? SystemChrome.setPreferredOrientations)(
orientacionesPara(anchoLogico),
);
} catch (e) {
// Deliberately broad: a cosmetic preference is never worth a failed
// startup, and headless is exactly where this fails.
developer.log(
'[PluriWave] no se pudo aplicar la política de orientación: $e',
name: 'Arranque',
level: 900,
);
}
await SystemChrome.setPreferredOrientations(DeviceOrientation.values);
}
class _OrientacionResponsiveApp extends StatefulWidget {
const _OrientacionResponsiveApp({required this.child});
/// Whether the Android Auto browse tree must be invalidated right now
/// (fix/android-auto-musica-local, item 4 — CORRECTED trigger).
///
/// The trigger used to be `View.maybeOf(context) != null` inside
/// `didChangeDependencies`, latched once, on the premise that «a View means
/// there is an Activity». That premise is FALSE: `runApp` unconditionally
/// wraps the tree in a `View` built from
/// `platformDispatcher.implicitView` and throws a `StateError` when there is
/// none (`flutter/lib/src/widgets/binding.dart`, `wrapWithDefaultView`). So
/// on the headless `audio_service` engine — which demonstrably reaches
/// `runApp`, see [aplicarPoliticaOrientacion] — the View is ALREADY there at
/// the first `didChangeDependencies`. The one-shot latch was spent at the
/// exact moment it could accomplish nothing (`_childrenSubjects` still
/// empty, so `notificarHijosCambiaron` is a silent no-op) and could never
/// fire again, because `didChangeDependencies` does not re-run when an
/// Activity later attaches to that same cached engine.
///
/// Two conditions replace it, both required:
///
/// * [estado] is [AppLifecycleState.resumed] — the only state that genuinely
/// means «an Activity is attached and in the foreground». It reaches Dart
/// exclusively through `SystemChannels.lifecycle` (or
/// `PlatformDispatcher.initialLifecycleState`, which buffers the same
/// messages), and on Android only `LifecycleChannel.appIsResumed()` sends
/// it, driven by the Activity's own `onResume`.
/// `AudioServicePlugin.getFlutterEngine` builds its engine from the
/// APPLICATION context and runs the Dart entrypoint immediately, with no
/// Activity and no `FlutterActivityAndFragmentDelegate`, so nothing sends
/// it on the headless engine.
/// * [hayCocheSuscrito] — a head unit has actually subscribed to at least
/// one browse id (`hayCocheSuscritoAlArbol`). This is what makes the latch
/// worth spending, and it is also the belt to `resumed`'s braces: even if
/// a lifecycle event did somehow arrive during a headless cold start,
/// nothing has subscribed yet, so the latch survives for the moment an
/// Activity really does attach.
///
/// [yaInvalidado] keeps it one-shot: an app foregrounded twenty times must
/// not send twenty `notifyChildrenChanged` storms to the car.
///
/// Pure, so the whole policy is testable without an engine.
@visibleForTesting
bool debeInvalidarArbolAutoAlReanudar({
required AppLifecycleState estado,
required bool hayCocheSuscrito,
required bool yaInvalidado,
}) =>
!yaInvalidado && hayCocheSuscrito && estado == AppLifecycleState.resumed;
/// Root wrapper that keeps the orientation policy applied and owns the
/// Android Auto browse-tree recovery hook.
///
/// Public only so a test can mount it and drive real lifecycle events
/// through [debeInvalidarArbolAutoAlReanudar]'s call site — the previous
/// trigger shipped broken precisely because nothing could reach it.
@visibleForTesting
class OrientacionResponsiveApp extends StatefulWidget {
const OrientacionResponsiveApp({super.key, required this.child});
final Widget child;
@override
State<_OrientacionResponsiveApp> createState() =>
State<OrientacionResponsiveApp> createState() =>
_OrientacionResponsiveAppState();
}
class _OrientacionResponsiveAppState extends State<_OrientacionResponsiveApp>
class _OrientacionResponsiveAppState extends State<OrientacionResponsiveApp>
with WidgetsBindingObserver {
ui.Display? _display;
/// fix/android-auto-musica-local, item 4: la invalidación del árbol del
/// coche se dispara UNA sola vez. Ver
/// [debeInvalidarArbolAutoAlReanudar].
bool _arbolAutoInvalidado = false;
@override
void initState() {
super.initState();
@@ -163,12 +393,33 @@ class _OrientacionResponsiveAppState extends State<_OrientacionResponsiveApp>
void didChangeDependencies() {
super.didChangeDependencies();
_display = View.maybeOf(context)?.display;
unawaited(_aplicarPoliticaOrientacion(_display));
unawaited(aplicarPoliticaOrientacion(display: _display));
}
/// `resumed` es lo único que significa de verdad «ya hay Activity
/// adjunta», y con ella el handler nativo de `pluriwave/file_actions` que
/// `MainActivity.configureFlutterEngine` instala. Si el coche había
/// navegado la raíz ANTES (arranque headless), la cacheó sin poder
/// resolver la música local; Android Auto no vuelve a preguntar por su
/// cuenta, así que se lo decimos aquí. Ver
/// [debeInvalidarArbolAutoAlReanudar] para las tres condiciones.
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (!debeInvalidarArbolAutoAlReanudar(
estado: state,
hayCocheSuscrito: hayCocheSuscritoAlArbol(),
yaInvalidado: _arbolAutoInvalidado,
)) {
return;
}
_arbolAutoInvalidado = true;
invalidarArbolAuto();
}
@override
void didChangeMetrics() {
unawaited(_aplicarPoliticaOrientacion(_display));
unawaited(aplicarPoliticaOrientacion(display: _display));
}
@override
@@ -6,12 +6,45 @@ import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:share_plus/share_plus.dart' show Share, XFile;
import '../../estado/estado_alarmas.dart';
import '../../estado/estado_radio.dart';
import '../../l10n/gen/app_localizations.dart';
import '../../widgets/pluri_glass_surface.dart';
import '../../widgets/pluri_layout.dart';
import '../../widgets/pluri_push_scaffold.dart';
/// Applies a successfully-parsed backup to BOTH independent notifiers that
/// own pieces of it (fix/import-alarmas-y-paywall).
///
/// `EstadoRadio.importarConfig` writes the raw alarm/vacation/exception JSON
/// block straight to SharedPreferences, but `EstadoAlarmas` is a separate
/// long-lived `ChangeNotifier` that loaded its alarms into memory at
/// construction and never re-reads storage on its own — `EstadoRadio` stays
/// deliberately free of a dependency on it. Without the two calls below the
/// imported block is invisible to the running app: the UI keeps showing the
/// pre-import alarms, a later edit would persist that stale in-memory list
/// OVER the imported one, and the imported alarms would never be
/// (re)scheduled with the Android native layer even after a restart.
///
/// Extracted as a top-level function (rather than inlined in `_importar`)
/// so this exact production sequence — not a reimplementation of it — is
/// directly unit-testable without depending on the `file_picker` platform
/// channel or the confirmation dialog.
Future<void> aplicarImportacionConfig(
EstadoRadio estado,
EstadoAlarmas alarmas,
Map<String, dynamic> json,
) async {
await estado.importarConfig(json);
// Re-reads from storage — clears ServicioAlarmas' in-memory cache so the
// just-imported alarms/vacations/exceptions (same JSON block, same
// notifier) replace the stale ones.
await alarmas.cargarPersistidasSinRecalcular();
// Recomputes next-run times against the (now fresh) imported data and
// re-syncs every alarm with the Android native scheduler.
await alarmas.refrescarProgramacion();
}
/// APLICACIÓN group · "Copia de seguridad" (design ADR-3). Body moved
/// verbatim from the former `_SeccionBackup` in `pantalla_ajustes.dart` —
/// only the panel header's icon and title were removed (the pushed screen's
@@ -102,8 +135,9 @@ class _CuerpoBackup extends StatelessWidget {
if (confirmar != true) return;
if (context.mounted) {
final estado = context.read<EstadoRadio>();
final alarmas = context.read<EstadoAlarmas>();
final messenger = ScaffoldMessenger.of(context);
await estado.importarConfig(json);
await aplicarImportacionConfig(estado, alarmas, json);
messenger.showSnackBar(
SnackBar(content: Text(l10n.backupImportSuccess)),
);
@@ -6,6 +6,7 @@ import '../../estado/estado_radio.dart';
import '../../l10n/display_names.dart';
import '../../l10n/gen/app_localizations.dart';
import '../../modelos/emisora.dart';
import '../../servicios/servicio_anuncios.dart';
import '../../widgets/pluri_glass_surface.dart';
import '../../widgets/pluri_layout.dart';
import '../../widgets/pluri_push_scaffold.dart';
@@ -105,6 +106,11 @@ class _CuerpoEmisorasPersonalizadas extends StatelessWidget {
}
Future<void> _mostrarFormularioAnadir(BuildContext context) async {
// ad-display spec "Interstitial Before Manual Station Add" (design.md
// ADR-6): fires on the CTA tap, before the form even opens — a no-op
// for premium (ServicioAnuncios' own entitlement gate).
await context.read<ServicioAnuncios>().intentarInterstitial();
if (!context.mounted) return;
await showModalBottomSheet(
context: context,
isScrollControlled: true,
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../../l10n/gen/app_localizations.dart';
import '../../servicios/musica_local_auto.dart';
import '../../servicios/servicio_audio.dart' show invalidarArbolAuto;
import '../../widgets/pluri_glass_surface.dart';
import '../../widgets/pluri_layout.dart';
import '../../widgets/pluri_push_scaffold.dart';
@@ -54,6 +55,15 @@ class _CuerpoMusicaLocalState extends State<_CuerpoMusicaLocal> {
final uri = await _fuente.elegirCarpeta();
if (uri == null) return; // Cancelled — no snackbar, matches the SAF
// picker's own "nothing changed" affordance.
// fix/android-auto-musica-local, item 4: acaba de aparecer música
// local donde antes no había. Android Auto cachea la raíz y no
// vuelve a preguntar por su cuenta, así que sin esto el coche seguía
// sin ofrecer «Música Local» hasta el siguiente re-bind — que puede
// no llegar en toda la sesión. Fuera del `context.mounted` de abajo:
// el árbol del coche no depende de que esta pantalla siga viva.
invalidarArbolAuto();
if (!context.mounted) return;
setState(() {
_carpetaActual = Future.value(uri);
+17
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../estado/estado_ecualizador.dart';
import '../estado/estado_entitlement.dart';
import '../estado/estado_grabacion.dart';
import '../estado/estado_idioma.dart';
import '../estado/estado_radio.dart';
@@ -10,6 +11,7 @@ import '../l10n/gen/app_localizations.dart';
import '../modelos/archivo_grabacion.dart';
import '../modelos/emisora.dart';
import '../tema/pluriwave_tokens.dart';
import '../widgets/hoja_premium.dart';
import '../widgets/pluri_layout.dart';
import '../widgets/pluri_push_scaffold.dart';
import '../widgets/pluri_root_header.dart';
@@ -99,6 +101,9 @@ class _AjustesContent extends StatelessWidget {
final idioma = context.select<EstadoIdioma, Locale?>(
(e) => e.localeSeleccionado,
);
final esPremium = context.select<EstadoEntitlement, bool>(
(e) => e.esPremium,
);
return Column(
children: [
@@ -256,6 +261,18 @@ class _AjustesContent extends StatelessWidget {
GrupoAjustes(
titulo: l10n.settingsGroupApplicationTitle,
filas: [
// freemium-gating spec "Settings always shows a premium row":
// a persistent buy row (free tier) or a premium-active state
// with restore access (premium tier) — both open the same
// paywall sheet, which adapts its own body to the tier.
FilaAjuste(
key: const ValueKey('ajustes-fila-premium'),
icon: Icons.workspace_premium_rounded,
iconColor: PluriWaveTokens.brand,
titulo: l10n.funcionPremium,
valor: esPremium ? l10n.equalizerActive : null,
onTap: () => mostrarHojaPremium(context),
),
FilaAjuste(
icon: Icons.language_rounded,
titulo: l10n.languageSectionTitle,
+61 -2
View File
@@ -9,10 +9,12 @@ import '../l10n/app_localizations_ext.dart';
import '../l10n/gen/app_localizations.dart';
import '../modelos/alarma_musical.dart';
import '../modelos/emisora.dart';
import '../servicios/servicio_anuncios.dart';
import '../servicios/servicio_programacion_alarmas.dart';
import '../tema/pluriwave_theme.dart';
import '../tema/pluriwave_tokens.dart';
import '../widgets/editor_hora_inline.dart';
import '../widgets/hoja_premium.dart';
import '../widgets/pluri_glass_surface.dart';
import '../widgets/pluri_layout.dart';
import '../widgets/pluri_push_scaffold.dart';
@@ -105,6 +107,21 @@ class PantallaAlarmas extends StatelessWidget {
BuildContext context, {
AlarmaMusical? alarma,
}) async {
// ADR-6 ordering (design.md): for a genuinely NEW alarm (no [alarma]),
// the cap-check + maybe-interstitial happen HERE, before the editor
// ever opens — "puedeCrearAlarma -> if false, show the limit message
// and no ad; if true, maybe-interstitial, then open the editor".
// Editing an existing alarm skips both checks entirely: it is never
// capped and never triggers the interstitial.
if (alarma == null) {
final estado = context.read<EstadoAlarmas>();
if (!estado.puedeCrearAlarma()) {
_mostrarLimiteAlarmas(context);
return;
}
await context.read<ServicioAnuncios>().intentarInterstitial();
if (!context.mounted) return;
}
await showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
@@ -113,6 +130,22 @@ class PantallaAlarmas extends StatelessWidget {
builder: (_) => _EditorAlarmaSheet(alarma: alarma),
);
}
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
/// explanatory message with a SECONDARY unlock action — never a direct
/// paywall navigation as the sole response to hitting the cap.
void _mostrarLimiteAlarmas(BuildContext context) {
final l10n = AppLocalizations.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(l10n.limiteAlarmasAlcanzado),
action: SnackBarAction(
label: l10n.desbloquearPremium,
onPressed: () => mostrarHojaPremium(context),
),
),
);
}
}
class _PanelProximaAlarma extends StatelessWidget {
@@ -1186,8 +1219,34 @@ class _EditorAlarmaSheetState extends State<_EditorAlarmaSheet> {
sonidoInterno: _sonidoInterno,
activa: true,
);
await estado.guardarAlarma(alarma);
if (mounted) Navigator.pop(context);
// The cap-check + interstitial already ran in `PantallaAlarmas
// ._abrirEditor` BEFORE this sheet ever opened (ADR-6 ordering: "then
// open the editor"). This is only the defense-in-depth backstop against
// the state-layer choke point — e.g. a 2nd device created alarms while
// this sheet was open — the true authority is `guardarAlarma` itself.
final resultado = await estado.guardarAlarma(alarma);
if (!mounted) return;
if (resultado == ResultadoGuardarAlarma.limiteAlcanzado) {
_mostrarLimiteAlarmas(context);
return;
}
Navigator.pop(context);
}
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
/// explanatory message with a SECONDARY unlock action — never a direct
/// paywall navigation as the sole response to hitting the cap.
void _mostrarLimiteAlarmas(BuildContext context) {
final l10n = AppLocalizations.of(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(l10n.limiteAlarmasAlcanzado),
action: SnackBarAction(
label: l10n.desbloquearPremium,
onPressed: () => mostrarHojaPremium(context),
),
),
);
}
List<Emisora> _favoritasConSeleccion(List<Emisora> favoritas) {
+6
View File
@@ -6,6 +6,7 @@ import '../l10n/display_names.dart';
import '../l10n/gen/app_localizations.dart';
import '../modelos/emisora.dart';
import '../modelos/grupo_favoritos.dart';
import '../servicios/servicio_anuncios.dart';
import '../tema/pluriwave_tokens.dart';
import '../widgets/fila_emisora_plana.dart';
import '../widgets/pluri_icon.dart';
@@ -38,6 +39,11 @@ class _PantallaFavoritosState extends State<PantallaFavoritos> {
String? _grupoSeleccionadoId;
Future<void> _abrirFormularioEmisoraPersonalizada() async {
// ad-display spec "Interstitial Before Manual Station Add" (design.md
// ADR-6): fires on the CTA tap, before the form even opens — a no-op
// for premium (ServicioAnuncios' own entitlement gate).
await context.read<ServicioAnuncios>().intentarInterstitial();
if (!mounted) return;
await showModalBottomSheet(
context: context,
isScrollControlled: true,
+42 -10
View File
@@ -17,6 +17,7 @@ import '../tema/pluri_animate.dart';
import '../tema/pluriwave_theme.dart';
import '../tema/pluriwave_tokens.dart';
import '../widgets/ecualizador_widget.dart';
import '../widgets/hoja_premium.dart';
import '../widgets/pluri_glass_surface.dart';
import '../widgets/pluri_premium_widgets.dart';
import '../widgets/pluri_push_scaffold.dart';
@@ -597,6 +598,28 @@ class _GrabacionWidget extends StatelessWidget {
}
}
/// Freemium gate choke point at the UI layer (freemium-gating spec "Free
/// user starts a new recording"): all 3 record-start call sites route
/// through here. [ctx] is the picker sheet/dialog's own (short-lived)
/// context — closed FIRST (matching the pre-existing pop-then-done shape).
/// [contextExterno] is the screen's own longer-lived context, used ONLY to
/// react to the AUTHORITATIVE [EstadoGrabacion.iniciar] result: a
/// free-tier block opens the paywall there instead of a plain error, since
/// [ctx] is already gone by then.
Future<void> _iniciarGrabacionYCerrar(
BuildContext ctx,
BuildContext contextExterno,
EstadoGrabacion grabacion, {
Duration? duracion,
}) async {
final resultado = await grabacion.iniciar(duracion: duracion);
if (ctx.mounted) Navigator.pop(ctx);
if (resultado == ResultadoIniciarGrabacion.requierePremium &&
contextExterno.mounted) {
await mostrarHojaPremium(contextExterno);
}
}
void _mostrarDialogoGrabacion(BuildContext context) {
final grabacion = context.read<EstadoGrabacion>();
showModalBottomSheet(
@@ -626,10 +649,12 @@ class _GrabacionWidget extends StatelessWidget {
size: 18,
),
label: Text(AppLocalizations.of(ctx).indefiniteOption),
onPressed: () {
grabacion.iniciar();
Navigator.pop(ctx);
},
onPressed:
() => _iniciarGrabacionYCerrar(
ctx,
context,
grabacion,
),
),
for (final opcion in _opciones)
ActionChip(
@@ -642,10 +667,13 @@ class _GrabacionWidget extends StatelessWidget {
opcion.duracion.inSeconds,
),
),
onPressed: () {
grabacion.iniciar(duracion: opcion.duracion);
Navigator.pop(ctx);
},
onPressed:
() => _iniciarGrabacionYCerrar(
ctx,
context,
grabacion,
duracion: opcion.duracion,
),
),
ActionChip(
avatar: const Icon(Icons.tune_rounded, size: 18),
@@ -718,8 +746,12 @@ class _GrabacionWidget extends StatelessWidget {
seconds: segundos,
);
if (duracion <= Duration.zero) return;
grabacion.iniciar(duracion: duracion);
Navigator.pop(ctx);
_iniciarGrabacionYCerrar(
ctx,
context,
grabacion,
duracion: duracion,
);
},
child: Text(AppLocalizations.of(ctx).recordAction),
),
+9 -1
View File
@@ -8,6 +8,7 @@ import '../l10n/gen/app_localizations.dart';
import '../modelos/alarma_musical.dart';
import '../tema/pluriwave_theme.dart';
import '../tema/pluriwave_tokens.dart';
import '../widgets/hoja_premium.dart';
import '../widgets/pluri_glass_surface.dart';
import '../widgets/pluri_layout.dart';
import '../widgets/pluri_push_scaffold.dart';
@@ -927,7 +928,14 @@ class _EditorVacacionesSheetState extends State<_EditorVacacionesSheet> {
fin: _fin,
nombre: nombre,
);
await estado.crearRangoVacaciones(rango);
// freemium-gating spec "Gated Feature Set": vacation creation is
// fully gated (unlike the alarm cap, there is no free allowance) —
// `crearRangoVacaciones` is the authoritative choke point.
final creada = await estado.crearRangoVacaciones(rango);
if (!creada) {
if (mounted) await mostrarHojaPremium(context);
return;
}
}
if (mounted) Navigator.pop(context);
}
+22 -15
View File
@@ -1,16 +1,21 @@
import 'dart:async';
import 'dart:developer' as developer;
import 'package:flutter/material.dart';
import '../tema/pluriwave_tokens.dart';
/// Timeout applied to the `AudioService.init` MediaBrowser handshake (Design
/// "Timeout without re-init"): the vendored `audio_service` plugin's
/// self-bind has no native timeout and an unhandled `onConnectionSuspended`
/// case, so under bind contention (Android Auto cold start) the handshake
/// can hang forever. Top-level const so tests can reference the production
/// value without duplicating it.
/// "Timeout without re-init"): the `audio_service` plugin's self-bind has no
/// native timeout and an unhandled `onConnectionSuspended` case, so under
/// bind contention (Android Auto cold start) the handshake can hang forever.
/// Top-level const so tests can reference the production value without
/// duplicating it.
///
/// This doc called the plugin "vendored". It is not: `pubspec.lock` pins the
/// hosted pub.dev `audio_service` 0.18.18 and `pubspec.yaml` declares no
/// `dependency_overrides`. Anyone reading the sentence above would go looking
/// for a local copy to patch, and there is none — the behaviour described is
/// upstream's, so the workaround has to live here.
const timeoutArranqueAudio = Duration(seconds: 8);
/// Outcome of racing an `AudioService.init` future against
@@ -94,16 +99,18 @@ StreamSubscription<Object> observarErroresAudio(
);
}
/// Default [observarErroresAudio] logger: one `[PluriWave]`-prefixed
/// `developer.log` line per swallowed plugin exception, at the same
/// `level: 900` (SEVERE) that `servicio_audio.dart`'s existing error lines
/// use, so a single logcat/DevTools filter catches both.
/// Default [observarErroresAudio] logger: one line per swallowed plugin
/// exception.
///
/// Uses [debugPrint], NOT `dart:developer`'s `log`. That distinction is the
/// whole reason this channel existed for weeks without ever producing a
/// single line of evidence: `log()` writes to the VM service, which a
/// RELEASE build does not have, so every exception this was built to catch
/// was still being thrown away — just one layer further down than before.
/// `debugPrint` reaches logcat in release, which is the only build that ever
/// runs in the car.
void registrarErrorAudioService(Object error) {
developer.log(
'[PluriWave] AudioService.asyncError: $error',
name: 'ArranqueAudio',
level: 900,
);
debugPrint('[PluriWave][ArranqueAudio] AudioService.asyncError: $error');
}
/// Minimal branded bootstrap widget for the degraded path (Design "still
+6 -6
View File
@@ -6,8 +6,10 @@ import '../modelos/pista_local.dart';
/// instance rather than mutating in place, mirroring how
/// `ControladorReconexion` was extracted from `PluriWaveAudioHandler`
/// (`controlador_reconexion.dart`) so this stays fully unit-testable without
/// the handler (which cannot be instantiated in unit tests — see this
/// module's sibling test file's doc comment).
/// the handler. (That last clause used to read "which cannot be instantiated
/// in unit tests"; it can — see `construirControlesTransporte`'s doc in
/// `servicio_audio.dart`. Keeping the queue logic out of the handler is
/// still worth it, but for design reasons, not for that one.)
class ColaLocal {
const ColaLocal({required this.pistas, this.indice = 0});
@@ -97,7 +99,5 @@ DecisionAvanceCola decidirAvanceCola({
/// distinct `ColaLocal` during the async URI-resolve gap is correctly
/// detected as stale and aborts the advance, instead of silently racing an
/// external play/stop.
bool avanceEsValido(
ColaLocal? colaLocalActual,
ColaLocal? siguienteEsperado,
) => identical(colaLocalActual, siguienteEsperado);
bool avanceEsValido(ColaLocal? colaLocalActual, ColaLocal? siguienteEsperado) =>
identical(colaLocalActual, siguienteEsperado);
+278
View File
@@ -0,0 +1,278 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../modelos/emisora.dart';
import '../modelos/grupo_favoritos.dart';
/// The skip context's persistence key.
///
/// Same headless-safe shape as `emisoras_destacadas.dart`: this file imports
/// nothing but `shared_preferences` and the models, never `EstadoRadio` nor
/// anything that drags a `ChangeNotifier` graph in. Android Auto starts the
/// engine WITHOUT an Activity, so there is no widget tree and `EstadoRadio` is
/// never constructed there — a context only that class could write would be a
/// context the car can never have.
///
/// `contexto_reproduccion_test.dart` pins the literal so a rename fails loudly
/// instead of silently leaving every driver context-less after an update.
const claveContextoSalto = 'contexto_salto_v1';
/// Which LIST the driver is walking with the car's previous/next buttons.
///
/// The type is the durable part; the members are not. A group's contents
/// change between sessions (the phone renames it, empties it, deletes it), so
/// remembering the members would be remembering something that expires —
/// [resolverListaContexto] re-resolves against the LIVE lists every time.
enum TipoContextoSalto {
/// One favourites group. The only type that carries [ContextoSalto.grupoFavoritosId].
grupoFavoritos,
favoritos,
misEmisoras,
/// The `populares` catalogue snapshot.
todas,
/// The free tier's curated set (`emisorasDestacadas`). The ONLY type that
/// carries [ContextoSalto.uuidsOrdenados] — see that field.
destacadas,
}
/// The remembered playback context: the smallest thing that still identifies
/// the list on the other side of a process restart.
class ContextoSalto {
/// One favourites group, named by its stable id.
const ContextoSalto.grupo(String grupoId)
: tipo = TipoContextoSalto.grupoFavoritos,
grupoFavoritosId = grupoId,
uuidsOrdenados = const [];
const ContextoSalto.favoritos()
: tipo = TipoContextoSalto.favoritos,
grupoFavoritosId = null,
uuidsOrdenados = const [];
const ContextoSalto.misEmisoras()
: tipo = TipoContextoSalto.misEmisoras,
grupoFavoritosId = null,
uuidsOrdenados = const [];
const ContextoSalto.todas()
: tipo = TipoContextoSalto.todas,
grupoFavoritosId = null,
uuidsOrdenados = const [];
/// The free tier's set, FROZEN in [uuids] order.
const ContextoSalto.destacadas(List<String> uuids)
: tipo = TipoContextoSalto.destacadas,
grupoFavoritosId = null,
uuidsOrdenados = uuids;
final TipoContextoSalto tipo;
/// Set only for [TipoContextoSalto.grupoFavoritos].
final String? grupoFavoritosId;
/// The frozen order, set only for [TipoContextoSalto.destacadas].
///
/// Every other type resolves against a list that HAS a stable, user-owned
/// order (the favourites' `orden` column, the custom-stations file, the
/// catalogue snapshot), so freezing it would only mean ignoring a reorder
/// the user just made on the phone. The free set is the exception:
/// `resolverEmisorasDestacadas` rebuilds it as `[última reproducida,
/// ...curadas]`, so it REORDERS ITSELF as the driver skips, and `previous`
/// stops being the inverse of `next`. Freezing that order is the fix.
final List<String> uuidsOrdenados;
Map<String, dynamic> aMapa() => {
'tipo': tipo.name,
if (grupoFavoritosId != null) 'grupoId': grupoFavoritosId,
if (uuidsOrdenados.isNotEmpty) 'uuids': uuidsOrdenados,
};
/// Parses a persisted map, or `null` when it is unusable.
///
/// Tolerant on purpose: this payload survives app updates, backups and
/// hand-edited preference files, and it is read from a steering-wheel
/// button. An unreadable context must mean "derive it again", never a
/// crash.
static ContextoSalto? desdeMapa(Map<String, dynamic> mapa) {
final tipoRaw = mapa['tipo'];
if (tipoRaw is! String) return null;
final tipo = TipoContextoSalto.values
.where((t) => t.name == tipoRaw)
.firstOrNull;
if (tipo == null) return null;
switch (tipo) {
case TipoContextoSalto.grupoFavoritos:
final grupoId = mapa['grupoId'];
// A group context with no group is not a context.
if (grupoId is! String || grupoId.isEmpty) return null;
return ContextoSalto.grupo(grupoId);
case TipoContextoSalto.favoritos:
return const ContextoSalto.favoritos();
case TipoContextoSalto.misEmisoras:
return const ContextoSalto.misEmisoras();
case TipoContextoSalto.todas:
return const ContextoSalto.todas();
case TipoContextoSalto.destacadas:
final uuids = mapa['uuids'];
if (uuids is! List) return null;
return ContextoSalto.destacadas(uuids.whereType<String>().toList());
}
}
@override
bool operator ==(Object other) =>
other is ContextoSalto &&
other.tipo == tipo &&
other.grupoFavoritosId == grupoFavoritosId &&
_mismosUuids(other.uuidsOrdenados, uuidsOrdenados);
@override
int get hashCode => Object.hash(
tipo,
grupoFavoritosId,
Object.hashAll(uuidsOrdenados),
);
@override
String toString() =>
'ContextoSalto(${tipo.name}, grupo=$grupoFavoritosId, '
'uuids=${uuidsOrdenados.length})';
static bool _mismosUuids(List<String> a, List<String> b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++) {
if (a[i] != b[i]) return false;
}
return true;
}
}
/// Persists [contexto]. Never throws — a failed write costs the driver a
/// re-derivation, an exception would cost them the station change.
Future<void> guardarContextoSalto(
ContextoSalto contexto, {
SharedPreferences? prefs,
}) async {
try {
final resueltas = prefs ?? await SharedPreferences.getInstance();
await resueltas.setString(claveContextoSalto, jsonEncode(contexto.aMapa()));
} catch (_) {
// Deliberately swallowed — see the doc above.
}
}
/// Reads the persisted context, or `null` when there is none, the payload is
/// unreadable, or prefs themselves fail.
///
/// Follows the same inject-or-`getInstance()` convention as
/// `esPremiumPersistido` and `resolverEmisorasDestacadas`, so a test pins
/// prefs without a platform channel.
Future<ContextoSalto?> contextoSaltoPersistido({
SharedPreferences? prefs,
}) async {
try {
final resueltas = prefs ?? await SharedPreferences.getInstance();
final raw = resueltas.getString(claveContextoSalto);
if (raw == null) return null;
final decodificado = jsonDecode(raw);
if (decodificado is! Map) return null;
return ContextoSalto.desdeMapa(Map<String, dynamic>.from(decodificado));
} catch (_) {
return null;
}
}
/// The LIVE, ordered list a remembered [contexto] resolves to right now, or an
/// empty list when it no longer resolves at all.
///
/// Pure — no handler, no prefs — so every degradation rule below is testable
/// on its own. An empty result means "this memory has expired": the caller
/// derives a fresh context instead (and, failing that, leaves playback alone —
/// never jumps somewhere arbitrary mid-drive).
///
/// Degradation rules, all of them deliberate. The group chain is the owner's,
/// decided from real use in the car:
/// * remembered group ALIVE -> it is walked, even when the playing station
/// has LEFT it (the caller then takes the group's first station) and even
/// when it is down to a single member (skipping there simply leaves the
/// driver where they are — a one-station group is still a group).
/// * remembered group DELETED, or alive but EMPTY -> widen to all
/// favourites, whether or not the playing station is still one of them:
/// "if the whole group is gone, pick a station from the favourites".
/// * no favourites left -> empty, i.e. the no-stations behaviour.
/// * every OTHER context type still expires when the playing station left
/// its list (unfavourited, removed from the catalogue snapshot) — the
/// owner's decision was about the group chain only.
/// * [TipoContextoSalto.destacadas] alone honours
/// [ContextoSalto.uuidsOrdenados] — see that field for why.
List<Emisora> resolverListaContexto({
required ContextoSalto contexto,
required Emisora actual,
required List<Emisora> favoritos,
required List<Emisora> misEmisoras,
required List<Emisora> todas,
required List<Emisora> destacadas,
required List<GrupoFavoritos> grupos,
}) {
bool contiene(List<Emisora> lista) =>
lista.any((e) => e.uuid == actual.uuid);
switch (contexto.tipo) {
case TipoContextoSalto.grupoFavoritos:
final grupoId = contexto.grupoFavoritosId;
if (grupoId == null || grupoId == GrupoFavoritos.sinAsignarId) {
return const [];
}
final existe = grupos.any((g) => g.id == grupoId);
final miembros =
favoritos.where((e) => e.grupoFavoritosId == grupoId).toList();
if (existe && miembros.isNotEmpty) {
// A surviving group is honoured as-is. The station does NOT have to
// still be in it — the caller takes the group's first station rather
// than wandering off to another list.
return miembros;
}
// Group deleted (or alive but empty, which offers no station to take):
// widen to all favourites. Unlike the other context types this does not
// require the station to still BE a favourite — the caller takes the
// first one.
return favoritos;
case TipoContextoSalto.favoritos:
return contiene(favoritos) ? favoritos : const [];
case TipoContextoSalto.misEmisoras:
return contiene(misEmisoras) ? misEmisoras : const [];
case TipoContextoSalto.todas:
return contiene(todas) ? todas : const [];
case TipoContextoSalto.destacadas:
// The frozen order is authoritative. `actual` is resolvable from itself
// so a station frozen into the walk from a previous session still
// resolves even when it never belonged to the curated set.
final porUuid = <String, Emisora>{
for (final e in destacadas) e.uuid: e,
actual.uuid: actual,
};
final lista = <Emisora>[
for (final uuid in contexto.uuidsOrdenados)
if (porUuid[uuid] != null) porUuid[uuid]!,
];
return lista.any((e) => e.uuid == actual.uuid) ? lista : const [];
}
}
/// The free tier's frozen walk order: the curated set in its compiled-in
/// order, with [actual] prepended when it does not belong to it.
///
/// Prepending rather than dropping keeps both buttons alive for a station left
/// over from a premium session (or from `ultima_emisora_v1`): a walk the
/// playing station is not part of would make `emisoraVecina` return `null` and
/// both buttons would be dead.
List<String> uuidsCongeladosDestacadas({
required Emisora actual,
required List<Emisora> destacadas,
}) => [
if (!destacadas.any((e) => e.uuid == actual.uuid)) actual.uuid,
...destacadas.map((e) => e.uuid),
];
+196
View File
@@ -0,0 +1,196 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../modelos/emisora.dart';
/// The last-played station's persistence key.
///
/// MUST stay byte-identical to `EstadoRadio._keyUltimaEmisora`
/// (`lib/estado/estado_radio.dart`), which is the only writer. It is
/// duplicated here rather than exported from there on purpose: this file has
/// to be readable from the headless Android Auto engine, where `EstadoRadio`
/// is never constructed, and importing a `ChangeNotifier` that pulls in the
/// whole app-state graph just to read one string constant would drag the
/// entire phone-side stack into a car bind. `emisoras_destacadas_test.dart`
/// pins the literal so a rename on either side fails loudly.
const claveUltimaEmisora = 'ultima_emisora_v1';
/// The stations a FREE-tier driver can browse and play in the car
/// (fix/auto-quality-guidelines, item 6).
///
/// Compiled into the binary, on purpose. Everything else the car could show
/// is empty on the bind a Play reviewer actually performs: a fresh install
/// is free tier (`esPremiumPersistido` is `getBool(...) ?? false`, no trial
/// key), `FuenteEmisorasAutoLocal.todas()` is literally
/// `_snapshotTodas ?? const []` until `EstadoRadio` pushes a network
/// snapshot that a headless bind never fetches, favourites and custom
/// stations are empty, and `ultima_emisora_v1` is absent. A curated const
/// list is the ONLY thing that can put real, playable rows in front of that
/// reviewer.
///
/// Deliberately small. This is not a catalogue — the catalogue is the
/// premium feature. Six rows is enough to prove the app works and short
/// enough to read at a glance from a driving position.
///
/// `favicon` is null for every entry on purpose: `artUriPara` then resolves
/// the on-brand bundled `station_art_*` drawable, so a browse row needs no
/// network at all to render its artwork.
///
/// `uuid`s are app-owned (`pw-destacada-*`), not Radio Browser uuids: these
/// rows must resolve identically whether or not the catalogue is reachable,
/// and a Radio Browser uuid we cannot re-fetch would be a promise this file
/// cannot keep.
const List<Emisora> emisorasDestacadas = [
Emisora(
uuid: 'pw-destacada-fip',
nombre: 'FIP',
url: 'https://icecast.radiofrance.fr/fip-midfi.mp3',
pais: 'France',
codigoPais: 'FR',
idioma: 'french',
),
Emisora(
uuid: 'pw-destacada-france-inter',
nombre: 'France Inter',
url: 'https://icecast.radiofrance.fr/franceinter-midfi.mp3',
pais: 'France',
codigoPais: 'FR',
idioma: 'french',
),
Emisora(
uuid: 'pw-destacada-deutschlandfunk',
nombre: 'Deutschlandfunk',
url: 'https://st01.sslstream.dlf.de/dlf/01/128/mp3/stream.mp3',
pais: 'Germany',
codigoPais: 'DE',
idioma: 'german',
),
Emisora(
uuid: 'pw-destacada-kexp',
nombre: 'KEXP 90.3 FM',
url: 'https://kexp-mp3-128.streamguys1.com/kexp128.mp3',
pais: 'United States',
codigoPais: 'US',
idioma: 'english',
),
Emisora(
uuid: 'pw-destacada-radio-paradise',
nombre: 'Radio Paradise',
url: 'https://stream.radioparadise.com/mp3-128',
pais: 'United States',
codigoPais: 'US',
idioma: 'english',
),
Emisora(
uuid: 'pw-destacada-soma-groove-salad',
nombre: 'SomaFM Groove Salad',
url: 'https://ice1.somafm.com/groovesalad-128-mp3',
pais: 'United States',
codigoPais: 'US',
idioma: 'english',
),
];
/// The free tier's complete, ordered station set: the last station the user
/// actually played (when one is persisted) first, then [emisorasDestacadas],
/// deduplicated by `uuid`.
///
/// Last-played goes first because it is the single row a returning driver is
/// most likely to want, and because it is the only entry that can make the
/// free folder feel like *their* app rather than a demo. It is NOT appended
/// a second time when it already belongs to the curated set.
///
/// Follows `esPremiumPersistido({SharedPreferences? prefs})`'s
/// inject-or-`getInstance()` convention (`estado_entitlement.dart`), so a
/// test can pin prefs without a platform channel.
///
/// Never throws: a corrupt/foreign `ultima_emisora_v1` payload, or a
/// `SharedPreferences` failure, degrades to the curated set alone. This runs
/// inside `getChildren`, and a browse call that throws is a dead folder.
Future<List<Emisora>> resolverEmisorasDestacadas({
SharedPreferences? prefs,
}) async {
final ultima = await _ultimaEmisora(prefs: prefs);
if (ultima == null) return emisorasDestacadas;
return [
ultima,
...emisorasDestacadas.where((e) => e.uuid != ultima.uuid),
];
}
/// Whether [uuid] belongs to [destacadas] — the predicate every play-path
/// gate reads to tell "free content" from "the premium catalogue".
///
/// Pure, and takes the free universe rather than resolving it, so a caller
/// that already holds the list (every one of them does — it also needs it to
/// build the response) asks the question without a second prefs round trip.
///
/// A `null` or empty [uuid] is never free: `emisora:` with no tail is a
/// malformed id, and matching it against an entry with an empty uuid would be
/// a resolution hole rather than a feature.
bool esEmisoraGratuita(String? uuid, List<Emisora> destacadas) =>
uuid != null && uuid.isNotEmpty && destacadas.any((e) => e.uuid == uuid);
/// [esEmisoraGratuita] against the CURRENT free set, resolved here. For
/// callers that do not already hold the list.
Future<bool> esEmisoraGratuitaPorUuid(
String uuid, {
SharedPreferences? prefs,
}) async =>
esEmisoraGratuita(uuid, await resolverEmisorasDestacadas(prefs: prefs));
/// Reads the persisted last-played station, or `null` when there is none.
///
/// Public because the Android Auto "recent" browse root
/// (`AudioService.recentRootId`) needs exactly this one station and nothing
/// else: `onGetRoot` (`AudioService.java:817-821`) answers `recent` whenever
/// the head unit sends `EXTRA_RECENT`, which Android Auto does on every
/// reconnect, and the platform expects a SINGLE resume item there — not a
/// station list, and not an empty folder.
///
/// Tier-independent on purpose: this station is by definition one the user
/// has already played on this device, so offering to resume it is never
/// leaking premium content they have not already had.
Future<Emisora?> ultimaEmisoraPersistida({SharedPreferences? prefs}) =>
_ultimaEmisora(prefs: prefs);
/// Writes [emisora] as the last-played station — the SINGLE writer of
/// [claveUltimaEmisora].
///
/// It lives beside [ultimaEmisoraPersistida] rather than in `EstadoRadio`
/// because the key has to be written from the engine Android Auto starts,
/// which builds no widget tree and therefore never constructs `EstadoRadio`
/// at all: a session that happened only in the car used to leave the key
/// holding whatever the PHONE last played, so the head unit's resume row and
/// the free tier's featured folder were both stale on the next connect.
///
/// Deliberately NOT swallowing failures here: the handler port that calls it
/// traces and swallows (a persistence failure must never break playback),
/// and a silent `catch` in BOTH places would make a dead write channel
/// invisible from a car logcat.
Future<void> guardarUltimaEmisoraPersistida(
Emisora emisora, {
SharedPreferences? prefs,
}) async {
final resueltas = prefs ?? await SharedPreferences.getInstance();
await resueltas.setString(claveUltimaEmisora, jsonEncode(emisora.toMap()));
}
/// Reads the persisted last-played station, or `null` when there is none,
/// the payload is unreadable, or prefs themselves fail.
Future<Emisora?> _ultimaEmisora({SharedPreferences? prefs}) async {
try {
final resueltas = prefs ?? await SharedPreferences.getInstance();
final raw = resueltas.getString(claveUltimaEmisora);
if (raw == null) return null;
final emisora = Emisora.fromMap(jsonDecode(raw) as Map<String, dynamic>);
// A record with no uuid or no url cannot be turned into a playable
// `emisora:<uuid>` row, so it is worse than absent: it would occupy the
// first slot with a row that does nothing when tapped.
if (emisora.uuid.isEmpty || emisora.url.isEmpty) return null;
return emisora;
} catch (_) {
return null;
}
}
+74 -15
View File
@@ -1,5 +1,6 @@
import 'dart:collection';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -61,15 +62,34 @@ String nombreCarpetaDesdeUri(String treeUri, {required String nombreGenerico}) {
segmento = documentId.substring(ultimaBarra + 1);
} else {
final ultimosDosPuntos = documentId.lastIndexOf(':');
segmento = ultimosDosPuntos >= 0
? documentId.substring(ultimosDosPuntos + 1)
: documentId;
segmento =
ultimosDosPuntos >= 0
? documentId.substring(ultimosDosPuntos + 1)
: documentId;
}
final recortado = segmento.trim();
return recortado.isEmpty ? nombreGenerico : recortado;
}
/// Three-valued answer to «¿hay música local usable?»
/// (fix/android-auto-musica-local).
///
/// Sustituye al `bool` anterior, que colapsaba dos causas MUY distintas en
/// el mismo `false`:
///
/// * [noConfigurada] — no hay URI persistida, o el nativo respondió que el
/// permiso ya no es válido (el usuario nunca eligió carpeta, o la
/// revocó). Es la única respuesta que justifica ocultar el nodo.
/// * [configurada] — hay URI persistida y el nativo confirma el permiso.
/// * [canalNoDisponible] — hay URI persistida pero el canal
/// `pluriwave/file_actions` NO tiene handler nativo, así que no se puede
/// saber nada del permiso. Es lo que ocurre en el motor Flutter headless
/// que `audio_service` levanta cuando Android Auto arranca la app sin
/// Activity: `MainActivity.configureFlutterEngine` (único sitio donde se
/// registra ese canal) nunca corre. NO significa «no hay carpeta».
enum EstadoCarpetaLocal { noConfigurada, configurada, canalNoDisponible }
/// Browse-source abstraction for the local-music branch of the Android Auto
/// tree (Design "Interfaces / Contracts"), mirroring [FuenteEmisorasAuto]'s
/// (`navegacion_auto.dart`) cold-start-safe, never-throws contract. Kept as
@@ -77,9 +97,11 @@ String nombreCarpetaDesdeUri(String treeUri, {required String nombreGenerico}) {
/// browse domain, not a station source.
abstract class FuenteMusicaLocalAuto {
/// Whether a local-music root folder is picked AND its permission is
/// still valid. Never throws — a revoked/never-granted permission
/// degrades to `false` (Spec "Permission revoked or never granted").
Future<bool> hayCarpetaConfigurada();
/// still valid — o si esa pregunta no se puede contestar porque el canal
/// nativo no existe en este motor. Never throws: cualquier fallo degrada
/// a un valor de [EstadoCarpetaLocal], nunca a una excepción (Spec
/// "Permission revoked or never granted").
Future<EstadoCarpetaLocal> estadoCarpeta();
/// Immediate children of [documentId] (`''` = the tree root itself), one
/// SAF level deep (Design "Lazy per-folder enumeration, never an eager
@@ -196,19 +218,56 @@ class FuenteMusicaLocalAutoImpl implements FuenteMusicaLocalAuto {
}
@override
Future<bool> hayCarpetaConfigurada() async {
Future<EstadoCarpetaLocal> estadoCarpeta() async {
// Its OWN try, deliberately not merged with the channel one below.
//
// Never-throws restoration: the three-valued refactor moved this read
// outside the try, and the only caller (`getChildren`'s root branch)
// awaits it inline — so a prefs failure took the whole browse root down
// and emptied the car, against this method's own interface doc.
//
// Kept SEPARATE because a prefs failure and a channel failure both
// surface as `MissingPluginException`: one shared `on
// MissingPluginException` clause would answer `canalNoDisponible` —
// «hay carpeta pero no puedo comprobar el permiso» — for a store that
// never told us whether a folder exists at all. That would put an
// unreachable «Música Local» node in the car explaining a channel
// problem that is not happening, which is precisely the collapse the
// three-valued [EstadoCarpetaLocal] exists to prevent.
//
// `noConfigurada` is the honest answer here (the app cannot prove a
// folder was ever picked) and is what this path returned before the
// refactor, when the read still sat inside the catch-all below.
final String? uri;
try {
final uri = await _uriPersistida();
if (uri == null || uri.isEmpty) return false;
final valido = await _canal.invokeMethod<bool>(
'hasPersistedPermission',
{'treeUri': uri},
uri = await _uriPersistida();
} catch (e) {
debugPrint('[PluriWave][musica_local] no se pudo leer la URI local: $e');
return EstadoCarpetaLocal.noConfigurada;
}
if (uri == null || uri.isEmpty) return EstadoCarpetaLocal.noConfigurada;
try {
final valido = await _canal.invokeMethod<bool>('hasPersistedPermission', {
'treeUri': uri,
});
return valido == true
? EstadoCarpetaLocal.configurada
: EstadoCarpetaLocal.noConfigurada;
} on MissingPluginException catch (e) {
// El canal no tiene handler en ESTE motor. Antes esto caía en el
// mismo `catch (_)` que un permiso revocado y devolvía `false`, que
// es exactamente por lo que «Música Local» desaparecía del árbol de
// Android Auto cuando el coche arrancaba la app sin Activity.
debugPrint(
'[PluriWave][musica_local] hasPersistedPermission sin handler '
'nativo (motor sin Activity): $e',
);
return valido ?? false;
} catch (_) {
return EstadoCarpetaLocal.canalNoDisponible;
} catch (e) {
// Cold-start / revoked-permission safety (Spec "Permission revoked or
// never granted"): never throw, degrade to "not configured".
return false;
debugPrint('[PluriWave][musica_local] hasPersistedPermission ERROR $e');
return EstadoCarpetaLocal.noConfigurada;
}
}
+565 -73
View File
@@ -10,6 +10,8 @@ import '../modelos/emisora.dart';
import '../modelos/grupo_favoritos.dart';
import '../modelos/pista_local.dart';
import '../modelos/preset_ecualizador.dart';
import 'contexto_reproduccion.dart';
import 'emisoras_destacadas.dart';
import 'musica_local_auto.dart';
import 'persistencia_tolerante.dart';
import 'servicio_favoritos.dart';
@@ -200,10 +202,97 @@ abstract class FuenteEmisorasAuto {
}) {}
}
/// Every user-readable label of the Android Auto browse tree, already
/// resolved to one locale by the caller.
///
/// THE RULE (fix/auto-quality-guidelines, l10n item): anything a user can
/// read gets translated. This bundle replaces the previous
/// "car-tree labels are hardcoded Spanish, deliberately NOT an arb key"
/// convention, which was defensible only while those labels sat deep inside
/// a premium tree and stopped being defensible the moment Google Play
/// reviewed the car surface on an English head unit.
///
/// It exists as a plain value object rather than an `AppLocalizations`
/// dependency so [ConstructorArbolAuto] stays a PURE builder — the same
/// reason `itemsEcualizadorAuto` lives in `servicio_audio.dart`. The handler,
/// which can resolve localizations headlessly through
/// `resolverLocalizacionesRespaldo`, builds one via
/// `etiquetasArbolAutoDesde` and hands it in.
///
/// NOT in here on purpose: the alphabetical bucket labels (`'A-F'`, `'G-M'`,
/// …). Those are ranges of Latin letters, not prose — translating them would
/// make them lie about which filenames they contain.
class EtiquetasArbolAuto {
const EtiquetasArbolAuto({
required this.escuchar,
required this.favoritos,
required this.todasLasEmisoras,
required this.misEmisoras,
required this.musicaLocal,
required this.musicaLocalNoDisponible,
required this.cargarMas,
required this.ordenarPorCalidad,
required this.reproducirCarpeta,
required this.reproducirAleatorio,
required this.pistaSinNombre,
});
/// Fallback bundle for callers that have no localizations to hand: pure
/// builder tests, and any future non-car consumer.
///
/// It is NOT what the car shows. `ServicioAudio` always injects a bundle
/// resolved from `AppLocalizations`, in every browse and playback path
/// that can produce a label — `etiquetas_arbol_auto_test.dart` is the
/// guard that no NEW hardcoded label can be introduced alongside these.
static const respaldo = EtiquetasArbolAuto(
escuchar: 'Escuchar',
favoritos: 'Favoritos',
todasLasEmisoras: 'Todas las emisoras',
misEmisoras: 'Mis emisoras',
musicaLocal: 'Música Local',
musicaLocalNoDisponible: 'Abre PluriWave en el móvil para leer tu música',
cargarMas: 'Más…',
ordenarPorCalidad: 'Ordenar por calidad',
reproducirCarpeta: 'Reproducir carpeta',
reproducirAleatorio: 'Reproducir aleatorio',
pistaSinNombre: 'Pista sin nombre',
);
/// The free tier's single root folder ([ConstructorArbolAuto.idDestacadas]).
final String escuchar;
/// Premium root folders.
final String favoritos;
final String todasLasEmisoras;
final String misEmisoras;
final String musicaLocal;
/// The non-playable row shown when the local-music folder cannot be read
/// from the car ([ConstructorArbolAuto.idLocalNoLista]).
final String musicaLocalNoDisponible;
/// Trailing "load more" row of every paged local-music view.
final String cargarMas;
/// Local-folder navigation and action rows.
final String ordenarPorCalidad;
final String reproducirCarpeta;
final String reproducirAleatorio;
/// Fallback title for a local file whose name is blank after stripping.
final String pistaSinNombre;
}
/// Pure builder for the Android Auto browse tree: folders, leaf items, id
/// resolution. No platform dependency — fully testable without a running
/// car or a real `AudioHandler`.
class ConstructorArbolAuto {
const ConstructorArbolAuto({this.etiquetas = EtiquetasArbolAuto.respaldo});
/// The already-localized labels this builder stamps onto every
/// user-readable `MediaItem` it produces.
final EtiquetasArbolAuto etiquetas;
/// Root folder ids (Design "media-id scheme"). The tree root itself is
/// identified by [AudioService.browsableRootId], not by a constant here —
/// the handler compares against it directly before calling [raiz].
@@ -211,6 +300,17 @@ class ConstructorArbolAuto {
static const idTodas = 'todas';
static const idMisEmisoras = 'mis_emisoras';
/// Root folder id for the FREE tier's only browsable folder
/// (fix/auto-quality-guidelines, item 8).
///
/// Deliberately NOT added to [_idsCarpetas] — like [idMusicaLocal] and
/// [idEcualizador] it has its own dedicated children ([hijosDestacadas]),
/// fed by `emisoras_destacadas.dart`'s compiled-in set rather than by the
/// generic station-list [hijos] path over a `FuenteEmisorasAuto` that is
/// empty on the bind a Play reviewer actually performs.
static const idDestacadas = 'destacadas';
/// Root folder id for the local-music browsable root (Design "media-id
/// scheme"). Deliberately NOT added to [_idsCarpetas] — it has its own
/// dedicated branch (`hijosMusicaLocal`), not the generic station-list
@@ -229,6 +329,17 @@ class ConstructorArbolAuto {
/// hidden.
static const idEcualizador = 'ecualizador';
/// Non-playable "no puedo leer la carpeta desde aquí" item
/// (fix/android-auto-musica-local). La raíz ya no oculta [idMusicaLocal]
/// cuando el canal nativo `pluriwave/file_actions` no está disponible en
/// este motor, así que abrir la carpeta tenía que dejar de mostrar una
/// lista vacía: vacío se lee como «no tengo música», que es justo la
/// conclusión equivocada. Este item dice qué pasa de verdad.
///
/// Colisión imposible con los prefijos `carpeta_local:` / `pista:` /
/// `emisora:` / `grupo:` — no lleva ninguno de ellos.
static const idLocalNoLista = 'musica_local_no_disponible';
static const _idsCarpetas = {idFavoritos, idTodas, idMisEmisoras};
static const _maxItemsPorCarpeta = 50;
@@ -311,36 +422,103 @@ class ConstructorArbolAuto {
'android.media.browse.CONTENT_STYLE_PLAYABLE_HINT': 2,
};
/// The root folders (Favoritos, Todas las emisoras, Mis emisoras,
/// optionally Música Local, Ecualizador), all non-playable.
/// The root folders, all non-playable, and TIER-DEPENDENT: Favoritos,
/// Todas las emisoras, Mis emisoras and optionally Música Local for a
/// premium driver; the single [idDestacadas] folder for a free one (see
/// [premium] below).
///
/// Decision `auto/ecualizador-diseno` SUPERSEDES the "no equalizer
/// folder" rule that used to live in this doc comment (commit `2403da3`,
/// mirroring the redesign mockup's "sin carpeta de ecualizador", turn t4
/// line 40). That rule was sound when written, but predated on-device
/// feedback showing that Android Auto custom actions don't surface
/// enough state for choosing among six presets: a monochrome icon cannot
/// legibly encode "which preset", and many head units render a custom
/// action icon-first, hiding its label. `Ecualizador` is a real
/// browsable folder again: "Desactivar" first, then the six factory
/// presets, the active one marked (children built by
/// `itemsEcualizadorAuto` in `servicio_audio.dart` -- this class stays
/// free of any `AppLocalizations` dependency, unlike that builder).
/// Always present, and LAST in the list (after Música Local, when
/// included) -- unlike [idMusicaLocal] it is never conditionally hidden.
/// Do not "restore" the no-folder rule without re-reading that decision.
/// There is NO `Ecualizador` folder. The car's only equalizer control is
/// the on/off custom action on the playback screen
/// (`controlesEcualizadorPersonalizados` in `servicio_audio.dart`), which
/// the driver reaches from all three player views without leaving them.
///
/// The folder existed briefly (`8423ccd`) because custom actions were
/// thought unable to convey enough state for a six-preset choice. Owner
/// decision after driving with it: a browsable preset list is more
/// interaction than a driver wants, and on/off is the only equalizer
/// control that belongs in a car. Preset selection stays on the phone.
/// This lands back on the redesign mockup's original rule ("sin carpeta de
/// ecualizador", turn t4 line 40), now for a road-tested reason rather than
/// an assumed one.
///
/// `Música Local` is OMITTED entirely (not just empty) unless
/// [incluirMusicaLocal] is `true` (Design "Local root hidden until a folder
/// is configured") — the caller passes `fuente.hayCarpetaConfigurada()`,
/// keeping this builder itself synchronous and side-effect free.
List<MediaItem> raiz({required bool incluirMusicaLocal}) => [
_carpeta(idFavoritos, 'Favoritos'),
_carpeta(idTodas, 'Todas las emisoras'),
_carpeta(idMisEmisoras, 'Mis emisoras'),
if (incluirMusicaLocal) _carpeta(idMusicaLocal, 'Música Local'),
_carpeta(idEcualizador, 'Ecualizador'),
];
/// is configured") — the caller lo deriva de
/// `premium && fuente.estadoCarpeta() != EstadoCarpetaLocal.noConfigurada`
/// (fix/android-auto-musica-local: un canal nativo ausente ya NO oculta el
/// nodo; fix/auto-quality-guidelines item 9: el `premium &&` va delante a
/// propósito, para que el tier gratuito ni siquiera pague ese round trip
/// nativo), keeping this builder itself synchronous and side-effect free.
///
/// [premium] (fix/auto-quality-guidelines, item 8) is finally READ. It used
/// to be accepted and ignored, on the theory that "the root keeps the same
/// visible folder labels for free users" was friendlier than a reduced
/// menu. It was not: every one of those four folders dead-ended on a single
/// non-playable "Función Premium" row, and Google Play cited exactly that
/// against the Android for Cars App Quality Guidelines.
///
/// The free root is therefore ONE browsable folder, [idDestacadas], and the
/// premium-only folders are OMITTED rather than shown-and-blocked: a folder
/// a driver cannot use is worse than a folder that is not there.
///
/// It must stay at least one BROWSABLE item, never a bare playable one:
/// `audio_service` 0.18.18 discards `rootHints`
/// (`AudioService.java:817-826`), so this code cannot detect whether the
/// head unit accepts a `FLAG_PLAYABLE` root child, and the documented
/// default of `BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS` is
/// `FLAG_BROWSABLE` alone — a root of one playable item renders EMPTY on
/// such a unit.
///
/// Every label here comes from [etiquetas], already resolved to the head
/// unit's locale — the free root's [EtiquetasArbolAuto.escuchar] AND the
/// four premium folders.
///
/// The four premium ones used to be hardcoded Spanish, on the theory that
/// they were leaf rows deep inside a tree only a user who had already
/// chosen the app would reach. That was never a rule, only an untested
/// assumption, and it is retired: anything a user can read gets
/// translated. `escuchar` was localized first (it is 100% of what a free
/// Play reviewer sees), which is exactly why the rest had to follow.
///
/// [tituloDestacadas] stays as an explicit per-call override of
/// [EtiquetasArbolAuto.escuchar]; `null` (the default) uses the bundle.
List<MediaItem> raiz({
required bool incluirMusicaLocal,
required bool premium,
String? tituloDestacadas,
}) =>
premium
? [
_carpeta(idFavoritos, etiquetas.favoritos),
_carpeta(idTodas, etiquetas.todasLasEmisoras),
_carpeta(idMisEmisoras, etiquetas.misEmisoras),
if (incluirMusicaLocal)
_carpeta(idMusicaLocal, etiquetas.musicaLocal),
]
: [_carpeta(idDestacadas, tituloDestacadas ?? etiquetas.escuchar)];
/// The free tier's playable station rows (fix/auto-quality-guidelines,
/// items 8/9): [emisoras] mapped through the SAME [itemEmisora] the premium
/// folders use, capped like every other folder.
///
/// Separate from [hijos] because that path is gated on [_idsCarpetas] and
/// fed by a `FuenteEmisorasAuto` whose lists are all empty on a cold
/// headless bind — which is precisely the bind this folder has to survive.
/// An empty [emisoras] returns `[]` rather than any placeholder row: a
/// non-playable row in the car tree is the thing Play cited.
List<MediaItem> hijosDestacadas(List<Emisora> emisoras) =>
emisoras.take(_maxItemsPorCarpeta).map(itemEmisora).toList();
/// El item de [idLocalNoLista]. Rotulado con
/// [EtiquetasArbolAuto.musicaLocalNoDisponible], ya resuelto al idioma del
/// head unit. No reproducible — seleccionarlo es un no-op.
MediaItem itemLocalNoDisponible() => MediaItem(
id: idLocalNoLista,
title: etiquetas.musicaLocalNoDisponible,
playable: false,
extras: _contentStyleLista,
);
MediaItem _carpeta(String id, String titulo) => MediaItem(
id: id,
@@ -436,20 +614,15 @@ class ConstructorArbolAuto {
return (documentId, pagina);
}
/// Hardcoded-Spanish car-tree label for the trailing "load more" item
/// (Design ADR-5) — matches every other car-tree label in this file
/// (`'Favoritos'`, `'Música Local'`, [_tituloLocalFallback]), none of
/// which go through `AppLocalizations`. Deliberately NOT an arb key.
static const _tituloMasLocal = 'Más…';
/// The trailing "load more" `MediaItem` (Design ADR-5): non-playable, no
/// `artUri` (the label alone is the affordance, like [_carpeta]), id
/// `carpeta_local_pag:<siguientePagina>:<documentIdPadre>` — round-trips
/// via [paginaCarpetaLocalDesde] back to the parent folder's next page.
/// Rotulado con [EtiquetasArbolAuto.cargarMas].
MediaItem _itemMasLocal(String documentIdPadre, int siguientePagina) =>
MediaItem(
id: '$_prefijoCarpetaLocalPaginada$siguientePagina:$documentIdPadre',
title: _tituloMasLocal,
title: etiquetas.cargarMas,
playable: false,
extras: _contentStyleLista,
);
@@ -574,41 +747,41 @@ class ConstructorArbolAuto {
/// for small folders.
bool ofreceBuckets(int totalPistas) => totalPistas > _minPistasParaBuckets;
/// The "Ordenar por calidad" mode-entry `MediaItem` (Design ADR-4):
/// The "sort by quality" mode-entry `MediaItem` (Design ADR-4):
/// non-playable, id `carpeta_local_ord:calidad:0:<documentIdPadre>` —
/// always page 0 of the sorted view, round-trips via [ordenLocalDesde].
/// Hardcoded Spanish label, matching every other car-tree label in this
/// file — never routed through `AppLocalizations` (established
/// car-tree-label precedent, see [_tituloMasLocal]).
/// Rotulado con [EtiquetasArbolAuto.ordenarPorCalidad].
MediaItem _itemModoOrdenCalidad(String documentIdPadre) => _carpeta(
'${_prefijoCarpetaLocalOrd}calidad:0:$documentIdPadre',
'Ordenar por calidad',
etiquetas.ordenarPorCalidad,
);
/// A single bucket-folder `MediaItem` (Design ADR-4): non-playable, id
/// `carpeta_local_bucket:<idx>:0:<documentIdPadre>` — always page 0,
/// round-trips via [bucketLocalDesde]. [etiqueta] is the hardcoded
/// alphabetical-range label (e.g. `'A-F'`), matching every other
/// car-tree label in this file — never routed through `AppLocalizations`.
/// round-trips via [bucketLocalDesde].
///
/// [etiqueta] is an alphabetical RANGE (e.g. `'A-F'`), and it is the one
/// user-visible car-tree string that deliberately does NOT go through
/// [EtiquetasArbolAuto]: it names the Latin letters the folder's filenames
/// actually start with, so translating it would make it lie.
MediaItem _itemBucket(String documentIdPadre, int idx, String etiqueta) =>
_carpeta('$_prefijoCarpetaLocalBucket$idx:0:$documentIdPadre', etiqueta);
/// The "Reproducir carpeta" playable action item (Design ADR-5): id
/// `carpeta_local_reproducir:<documentIdPadre>`. Hardcoded Spanish label,
/// matching every other car-tree label in this file — never routed
/// through `AppLocalizations`.
/// The "play folder" playable action item (Design ADR-5): id
/// `carpeta_local_reproducir:<documentIdPadre>`. Rotulado con
/// [EtiquetasArbolAuto.reproducirCarpeta].
MediaItem _itemReproducirCarpeta(String documentIdPadre) => MediaItem(
id: '$_prefijoCarpetaLocalReproducir$documentIdPadre',
title: 'Reproducir carpeta',
title: etiquetas.reproducirCarpeta,
playable: true,
extras: _contentStyleGrid,
);
/// The "Reproducir aleatorio" playable action item (Design ADR-5),
/// The "shuffle play" playable action item (Design ADR-5),
/// mirrors [_itemReproducirCarpeta].
MediaItem _itemReproducirAleatorio(String documentIdPadre) => MediaItem(
id: '$_prefijoCarpetaLocalAleatorio$documentIdPadre',
title: 'Reproducir aleatorio',
title: etiquetas.reproducirAleatorio,
playable: true,
extras: _contentStyleGrid,
);
@@ -690,7 +863,7 @@ class ConstructorArbolAuto {
int siguientePagina,
) => MediaItem(
id: '$_prefijoCarpetaLocalOrd$modo:$siguientePagina:$documentIdPadre',
title: _tituloMasLocal,
title: etiquetas.cargarMas,
playable: false,
extras: _contentStyleLista,
);
@@ -704,7 +877,7 @@ class ConstructorArbolAuto {
int siguientePagina,
) => MediaItem(
id: '$_prefijoCarpetaLocalBucket$idxBucket:$siguientePagina:$documentIdPadre',
title: _tituloMasLocal,
title: etiquetas.cargarMas,
playable: false,
extras: _contentStyleLista,
);
@@ -784,7 +957,7 @@ class ConstructorArbolAuto {
final titulo =
(tituloMeta != null && tituloMeta.isNotEmpty)
? tituloMeta
: _tituloDesdeNombre(nodo.nombre);
: _tituloDesdeNombre(nodo.nombre, etiquetas.pistaSinNombre);
final artUriMeta = meta?.artUri?.trim();
final artUri =
(artUriMeta != null && artUriMeta.isNotEmpty)
@@ -901,6 +1074,58 @@ class ConstructorArbolAuto {
}
}
/// Whether [parentMediaId] is content the FREE tier is allowed to browse
/// (fix/auto-quality-guidelines, item 10): the browsable root itself, the
/// free folder [ConstructorArbolAuto.idDestacadas], and an `emisora:<uuid>`
/// whose uuid belongs to [destacadas].
///
/// Everything else — the catalogue folders, favourites, custom stations,
/// local music, the equalizer folder, group folders, local tracks, and any
/// station uuid that is not in the free set — is premium content.
///
/// Pure and id-shaped, with the free universe INJECTED, so the whole matrix
/// is testable without prefs or a handler.
bool idPermitidoEnFree(
String parentMediaId, {
required List<Emisora> destacadas,
}) {
if (parentMediaId == AudioService.browsableRootId) return true;
if (parentMediaId == ConstructorArbolAuto.idDestacadas) return true;
if (!parentMediaId.startsWith(_prefijoEmisora)) return false;
final uuid = parentMediaId.substring(_prefijoEmisora.length);
if (uuid.isEmpty) return false;
return destacadas.any((e) => e.uuid == uuid);
}
/// Pure Android Auto browse-gate decision: the AUTHORITATIVE `getChildren`
/// choke point, called BEFORE any other resolution.
///
/// REWRITTEN (fix/auto-quality-guidelines, item 10) from action-blocking to
/// content-scoping. It used to answer ANY non-root id, for a free-tier user,
/// with a single non-playable "Función Premium" row — which is what Google
/// Play cited on version code 157 ("clicking on stop button makes the entire
/// app useless" was the headline, but the browse tree it was reviewed
/// against was four folders that each dead-ended on that row). A
/// non-playable row reachable from a head unit's CACHED tree is a citation
/// waiting to happen, so there is no longer any code path that can produce
/// one: the blocked branch returns the free tier's own playable stations.
///
/// Returns `null` when the caller should proceed with its normal resolution
/// (premium, or free-tier content the free tier owns).
///
/// [destacadas] is the free universe (`resolverEmisorasDestacadas()`); the
/// caller resolves it once per browse. Passing an empty list is legal and
/// yields an empty blocked response — still never a dead row.
List<MediaItem>? respuestaBloqueadaPorEntitlement({
required String parentMediaId,
required bool premium,
required List<Emisora> destacadas,
}) {
if (premium) return null;
if (idPermitidoEnFree(parentMediaId, destacadas: destacadas)) return null;
return ConstructorArbolAuto().hijosDestacadas(destacadas);
}
/// Routing seam between a car-tapped `emisora:<uuid>` media id and the
/// existing internal playback path (Design "playback coherence" — reuse
/// over duplication). Resolves the uuid via [fuente], builds the same
@@ -910,17 +1135,21 @@ class ConstructorArbolAuto {
/// A stale/unknown id (or a malformed one) is a no-op: [reproducir] is
/// never called and no exception propagates (Spec "Unknown or stale media
/// id").
Future<void> reproducirPorMediaId(
///
/// RETURNS whether it actually dispatched (fix/auto-quality-guidelines,
/// item 12). The caller needs to tell "played" from "resolved to nothing"
/// so the second case can publish an explained error to the car instead of
/// leaving the driver with a tap that did nothing and said nothing.
Future<bool> reproducirPorMediaId(
String id, {
required FuenteEmisorasAuto fuente,
required Future<void> Function(MediaItem) reproducir,
}) async {
if (!id.startsWith(_prefijoEmisora)) return;
final uuid = id.substring(_prefijoEmisora.length);
if (uuid.isEmpty) return;
final uuid = uuidDeMediaIdEmisora(id);
if (uuid == null) return false;
final emisora = await fuente.porUuid(uuid);
if (emisora == null) return;
if (emisora == null) return false;
final item = MediaItem(
id: emisora.url,
@@ -936,6 +1165,238 @@ Future<void> reproducirPorMediaId(
extras: {'uuid': emisora.uuid},
);
await reproducir(item);
return true;
}
/// The uuid inside an `emisora:<uuid>` media id, or `null` for any other
/// shape — no prefix (a `pista:`/`carpeta_local_*`/`eq_preset:` id, or a
/// folder id) and an empty tail both answer `null`.
///
/// Extracted (fix/auto-quality-guidelines, item 11) because the play-path
/// entitlement gate has to ask the same question `reproducirPorMediaId` asks,
/// one step earlier: "is this a station id, and which station?".
String? uuidDeMediaIdEmisora(String id) {
if (!id.startsWith(_prefijoEmisora)) return null;
final uuid = id.substring(_prefijoEmisora.length);
return uuid.isEmpty ? null : uuid;
}
/// A [FuenteEmisorasAuto] over nothing but the free tier's station set
/// (fix/auto-quality-guidelines, item 12).
///
/// Stands in for `_fuenteNavegacionGlobal` while that is still `null` — the
/// window between the headless Android Auto engine starting and `main.dart`
/// registering the real source. A tap arriving in that window used to return
/// in silence; the free set is compiled into the binary, so it can always be
/// answered.
///
/// Reports the free stations through [todas] (they are, from the car's point
/// of view, everything there is) and nothing through the curated lists, which
/// a headless bind could not populate anyway.
class FuenteEmisorasAutoDestacadas extends FuenteEmisorasAuto {
FuenteEmisorasAutoDestacadas(this._destacadas);
final List<Emisora> _destacadas;
@override
Future<List<Emisora>> favoritos() async => const [];
@override
Future<List<Emisora>> misEmisoras() async => const [];
@override
Future<List<Emisora>> todas() async => _destacadas;
@override
Future<List<GrupoFavoritos>> grupos() async => const [];
@override
Future<Emisora?> porUuid(String uuid) async {
for (final emisora in _destacadas) {
if (emisora.uuid == uuid) return emisora;
}
return null;
}
}
/// Which list previous/next should walk for [actual]: the NARROWEST context
/// the station belongs to.
///
/// Tightest first:
/// 1. its FAVOURITES GROUP, when it is a favourite filed under a real group,
/// 2. all favourites,
/// 3. my stations,
/// 4. the full catalogue.
///
/// The group tier is what the owner asked for: driving with a themed group,
/// "next" should stay inside that group rather than wander across every
/// favourite. And "next" from a favourite must never land on entry 4,318 of a
/// 50,000-station catalogue that happens to sit beside it alphabetically.
/// Falling through to [todas] only when the station is in neither curated
/// list keeps the button alive for a station reached by search.
///
/// [GrupoFavoritos.sinAsignarId] is deliberately NOT treated as a group: it
/// is the ABSENCE of one, so those stations walk all favourites instead of a
/// bucket that only means "unfiled". A group with a single member also falls
/// through to all favourites — otherwise both buttons would be dead ends.
///
/// Returns an empty list when [actual] is in none of them, which
/// [emisoraVecina] turns into "do nothing".
List<Emisora> listaParaSaltoEmisora({
required Emisora actual,
required List<Emisora> favoritos,
required List<Emisora> misEmisoras,
required List<Emisora> todas,
}) {
final contexto = contextoParaSaltoEmisora(
actual: actual,
favoritos: favoritos,
misEmisoras: misEmisoras,
todas: todas,
);
if (contexto == null) return const [];
switch (contexto.tipo) {
case TipoContextoSalto.grupoFavoritos:
return favoritos
.where((e) => e.grupoFavoritosId == contexto.grupoFavoritosId)
.toList();
case TipoContextoSalto.favoritos:
return favoritos;
case TipoContextoSalto.misEmisoras:
return misEmisoras;
case TipoContextoSalto.todas:
return todas;
case TipoContextoSalto.destacadas:
// Never produced by [contextoParaSaltoEmisora] — the free set is
// resolved by the handler, which owns the entitlement read.
return const [];
}
}
/// The same decision as [listaParaSaltoEmisora], NAMED instead of materialised
/// — so it can be remembered across a process restart.
///
/// The car kills and restarts the engine on every reconnect, and a list of
/// stations is not something that survives that: its members change while the
/// app is dead. The NAME of the list does survive, which is what
/// [ContextoSalto] persists and [resolverListaContexto] re-resolves against
/// whatever the lists hold next time.
///
/// [listaParaSaltoEmisora] is implemented on top of this so the walked list
/// and the remembered context can never disagree (pinned by a test that runs
/// both over the same scenarios).
///
/// Returns `null` when [actual] belongs to none of the three lists — the
/// caller then has no context to remember and leaves playback alone.
ContextoSalto? contextoParaSaltoEmisora({
required Emisora actual,
required List<Emisora> favoritos,
required List<Emisora> misEmisoras,
required List<Emisora> todas,
}) {
Emisora? enLista(List<Emisora> lista) {
for (final e in lista) {
if (e.uuid == actual.uuid) return e;
}
return null;
}
// The FAVOURITE record is the authority on the group, never `actual`: the
// playing station is rebuilt from a MediaItem by `emisoraDesdeMediaItem`,
// which carries no group id and would always report "sin asignar".
final favorita = enLista(favoritos);
if (favorita != null) {
final grupo = favorita.grupoFavoritosId;
if (grupo != GrupoFavoritos.sinAsignarId) {
final delGrupo =
favoritos.where((e) => e.grupoFavoritosId == grupo).toList();
if (delGrupo.length > 1) return ContextoSalto.grupo(grupo);
}
return const ContextoSalto.favoritos();
}
if (enLista(misEmisoras) != null) return const ContextoSalto.misEmisoras();
if (enLista(todas) != null) return const ContextoSalto.todas();
return null;
}
/// The station before or after [actual] in [lista], wrapping around at both
/// ends.
///
/// Wrapping is deliberate: on a car's transport row a button that goes dead
/// at the end of a list reads as a broken app, and there is no visible list
/// position to explain it. Matching is by `uuid`, the same identity the
/// browse tree uses, so a refreshed snapshot with different object instances
/// still resolves.
///
/// Returns `null` when [lista] has fewer than two entries, or when [actual]
/// is not in it — the caller must then leave playback alone rather than jump
/// somewhere arbitrary.
Emisora? emisoraVecina(
Emisora? actual,
List<Emisora> lista, {
required bool haciaAtras,
}) {
if (actual == null || lista.length < 2) return null;
final indice = lista.indexWhere((e) => e.uuid == actual.uuid);
if (indice < 0) return null;
final destino =
haciaAtras
? (indice - 1 + lista.length) % lista.length
: (indice + 1) % lista.length;
return lista[destino];
}
/// Picks the station a spoken query refers to ("pon Radio Clásica"), over the
/// stations the car can already browse.
///
/// Pure and source-agnostic so it is testable without a handler. Ranking, best
/// first:
/// 1. exact name match (case/accent-insensitive),
/// 2. name starts with the query,
/// 3. name contains the query,
/// 4. country contains the query.
/// Ties are broken by the order [candidatas] arrives in, which the caller
/// composes as favourites → my stations → all, so a favourite always wins over
/// a stranger with the same name.
///
/// Returns `null` for an empty query or no match — the caller must then do
/// nothing rather than play something arbitrary, since a driver who asked for
/// a specific station is worse served by a random one than by silence.
Emisora? emisoraParaBusqueda(String consulta, List<Emisora> candidatas) {
final q = _normalizarBusqueda(consulta);
if (q.isEmpty) return null;
Emisora? contiene;
Emisora? empieza;
Emisora? porPais;
for (final emisora in candidatas) {
final nombre = _normalizarBusqueda(emisora.nombre);
if (nombre == q) return emisora;
if (empieza == null && nombre.startsWith(q)) {
empieza = emisora;
} else if (contiene == null && nombre.contains(q)) {
contiene = emisora;
} else if (porPais == null &&
_normalizarBusqueda(emisora.pais ?? '').contains(q)) {
porPais = emisora;
}
}
return empieza ?? contiene ?? porPais;
}
/// Lowercase, accent-stripped, collapsed whitespace — a driver saying "radio
/// clasica" must match "Radio Clásica", and voice transcription rarely gets
/// diacritics right.
String _normalizarBusqueda(String texto) {
const conAcento = 'áàäâãéèëêíìïîóòöôõúùüûñç';
const sinAcento = 'aaaaaeeeeiiiiooooouuuunc';
final buffer = StringBuffer();
for (final rune in texto.toLowerCase().runes) {
final char = String.fromCharCode(rune);
final i = conAcento.indexOf(char);
buffer.write(i >= 0 ? sinAcento[i] : char);
}
return buffer.toString().replaceAll(RegExp(r'\s+'), ' ').trim();
}
/// Routing seam for a car-tapped `eq_preset:<...>` media id (decision
@@ -954,11 +1415,18 @@ Future<void> reproducirPorMediaId(
/// A stale/unresolvable id, or any id that doesn't match
/// [ConstructorArbolAuto.esPresetEqMediaId], is a no-op: neither callback
/// runs and no exception propagates.
///
/// [presets] is the universe the id is resolved against, and it MUST be the
/// same list the folder was rendered from (`presetsEcualizadorAuto` in
/// `servicio_audio.dart` — factory presets plus the user's saved ones).
/// Defaulting to the factory six alone is what made a tapped custom preset a
/// silent no-op: the item was listed, but nothing here could resolve it.
Future<void> seleccionarPresetEqPorMediaId(
String id, {
required bool activo,
required Future<void> Function(PresetEcualizador) aplicarPreset,
required Future<void> Function(bool) activarEcualizador,
List<PresetEcualizador>? presets,
}) async {
final constructor = ConstructorArbolAuto();
if (!constructor.esPresetEqMediaId(id)) return;
@@ -968,32 +1436,29 @@ Future<void> seleccionarPresetEqPorMediaId(
return;
}
final preset = constructor.resolverPresetEq(id);
final preset = constructor.resolverPresetEq(id, presets: presets);
if (preset == null) return;
await aplicarPreset(preset);
if (!activo) await activarEcualizador(true);
}
/// Fallback title (Design "Title = filename minus extension") for a blank
/// or otherwise empty-after-stripping local filename — hardcoded Spanish,
/// matching every other car-tree label in this file (`'Favoritos'`,
/// `'Música Local'`, etc.), none of which go through `AppLocalizations`.
const _tituloLocalFallback = 'Pista sin nombre';
/// Filename → display title (Design "Title = filename minus extension"):
/// strips the LAST `.ext` (the whole trimmed name is kept when there is no
/// dot, or the dot is the first character — e.g. a hidden file like
/// `.mp3`), falling back to [_tituloLocalFallback] when the result would be
/// blank.
String _tituloDesdeNombre(String nombre) {
/// `.mp3`), falling back to [sinNombre] when the result would be blank.
///
/// [sinNombre] is [EtiquetasArbolAuto.pistaSinNombre], passed in rather than
/// hardcoded: it is a title the driver reads, so it is translated like every
/// other car-tree label.
String _tituloDesdeNombre(String nombre, String sinNombre) {
final recortado = nombre.trim();
if (recortado.isEmpty) return _tituloLocalFallback;
if (recortado.isEmpty) return sinNombre;
final ultimoPunto = recortado.lastIndexOf('.');
final sinExtension =
ultimoPunto > 0 ? recortado.substring(0, ultimoPunto) : recortado;
final resultado = sinExtension.trim();
return resultado.isEmpty ? _tituloLocalFallback : resultado;
return resultado.isEmpty ? sinNombre : resultado;
}
/// Resolves the on-brand fallback `artUri` for a local track (Design "art =
@@ -1266,12 +1731,13 @@ Future<void> reproducirCarpetaLocal(
Future<MediaItem?> construirMediaItemColaLocal(
NodoLocal nodo, {
required FuenteMusicaLocalAuto fuente,
EtiquetasArbolAuto etiquetas = EtiquetasArbolAuto.respaldo,
}) async {
final contentUri = await fuente.uriContenidoDePista(nodo.documentId);
if (contentUri == null || contentUri.isEmpty) return null;
return MediaItem(
id: contentUri,
title: _tituloDesdeDocumentId(nodo.documentId),
title: _tituloDesdeDocumentId(nodo.documentId, etiquetas.pistaSinNombre),
album: 'PluriWave',
// Item 3: a queued local track had NO artUri at all before — reuses
// [artUriLocal] (the SAME on-brand rotation the browse tree's
@@ -1335,8 +1801,9 @@ Future<Map<String, MetadatosPista>> _metadatosDeConCache(
Future<List<MediaItem>?> hijosMusicaLocal(
String parentMediaId, {
required FuenteMusicaLocalAuto? fuente,
EtiquetasArbolAuto etiquetas = EtiquetasArbolAuto.respaldo,
}) async {
final constructor = ConstructorArbolAuto();
final constructor = ConstructorArbolAuto(etiquetas: etiquetas);
// Sort-mode and bucket views (Design ADR-4, Phase 2) are routed FIRST —
// routing order is irrelevant to correctness (every prefix in this file
@@ -1395,13 +1862,24 @@ Future<List<MediaItem>?> hijosMusicaLocal(
if (fuente == null) return const [];
try {
final nodos = await fuente.hijos(documentId);
return await constructor.itemsLocales(
final items = await constructor.itemsLocales(
nodos,
documentIdPadre: documentId,
pagina: pagina,
metadatosDe: (ids) => _metadatosDeConCache(ids, fuente: fuente),
fuente: fuente,
);
// fix/android-auto-musica-local: si no salió NADA, el motivo importa.
// Con el canal nativo caído (motor sin Activity) `hijos` degrada a `[]`
// igual que una carpeta realmente vacía, y una carpeta vacía en el
// coche se lee como «no tengo música». El estado se consulta SOLO en
// ese caso vacío, así que la ruta normal no paga ningún round trip
// extra.
if (items.isEmpty &&
await fuente.estadoCarpeta() == EstadoCarpetaLocal.canalNoDisponible) {
return [constructor.itemLocalNoDisponible()];
}
return items;
} catch (_) {
return const [];
}
@@ -1416,11 +1894,11 @@ Future<List<MediaItem>?> hijosMusicaLocal(
/// the SAME [_tituloDesdeNombre] rule the browse tree uses. This keeps the
/// Now Playing title consistent with what the user tapped without requiring
/// a second native round trip.
String _tituloDesdeDocumentId(String documentId) {
String _tituloDesdeDocumentId(String documentId, String sinNombre) {
final ultimaBarra = documentId.lastIndexOf('/');
final segmento =
ultimaBarra >= 0 ? documentId.substring(ultimaBarra + 1) : documentId;
return _tituloDesdeNombre(segmento);
return _tituloDesdeNombre(segmento, sinNombre);
}
/// Routing seam between a car-tapped `pista:<docId>` media id and the
@@ -1439,6 +1917,7 @@ Future<void> reproducirPistaLocal(
String id, {
required FuenteMusicaLocalAuto fuente,
required Future<void> Function(MediaItem) reproducir,
EtiquetasArbolAuto etiquetas = EtiquetasArbolAuto.respaldo,
}) async {
if (!esPistaMediaId(id)) return;
final documentId = id.substring(_prefijoPista.length);
@@ -1449,7 +1928,7 @@ Future<void> reproducirPistaLocal(
final pista = PistaLocal(
documentId: documentId,
titulo: _tituloDesdeDocumentId(documentId),
titulo: _tituloDesdeDocumentId(documentId, etiquetas.pistaSinNombre),
contentUri: contentUri,
);
@@ -1544,6 +2023,16 @@ class FuenteEmisorasAutoLocal implements FuenteEmisorasAuto {
return _snapshotTodas ?? const [];
}
/// Resolves a station uuid across every list this source can reach.
///
/// The free tier's set ([resolverEmisorasDestacadas]) is searched LAST
/// (fix/auto-quality-guidelines, item 7). It has to be searched at all
/// because on a cold headless bind the three lists above are all empty —
/// `todas()` is `_snapshotTodas ?? const []`, favourites and custom
/// stations have nothing persisted on a fresh install — so a curated
/// `emisora:<uuid>` resolved to `null` and tapping the row did NOTHING.
/// It is searched last so a live catalogue/favourite record for the same
/// uuid (richer metadata, the user's own group assignment) still wins.
@override
Future<Emisora?> porUuid(String uuid) async {
final listas = await Future.wait([favoritos(), misEmisoras(), todas()]);
@@ -1552,6 +2041,9 @@ class FuenteEmisorasAutoLocal implements FuenteEmisorasAuto {
if (emisora.uuid == uuid) return emisora;
}
}
for (final emisora in await resolverEmisorasDestacadas()) {
if (emisora.uuid == uuid) return emisora;
}
return null;
}
+37 -2
View File
@@ -564,17 +564,52 @@ class ServicioAlarmas {
final ahora = _reloj();
// S2-R5: a disabled alarm must not keep a pending snooze; clearing it
// here guarantees the snoozed occurrence dies with the alarm.
// Self-heal for a snooze target parked absurdly far out — the reported
// "posponer left it 1400+ minutes away". A legitimate snooze can never
// reach here: posponerEjecucion clamps to `minutos.clamp(1, 120)` and the
// anchor is now guarded on both the native and Dart sides, so anything
// past that ceiling is a leftover from a build that had neither guard.
// Without this, an alarm poisoned before the fix keeps showing tomorrow
// on every tick — the user reinstalls, sees no change, and reasonably
// concludes nothing was fixed. Generous margin over the 120-minute cap so
// a real long snooze is never mistaken for corruption.
const techoSnooze = Duration(hours: 3);
final snoozeCorrupto =
alarma.snoozeHasta != null &&
alarma.snoozeHasta!.isAfter(ahora.add(techoSnooze));
final snoozeActivo =
alarma.activa &&
!snoozeCorrupto &&
alarma.snoozeHasta != null &&
alarma.snoozeHasta!.isAfter(ahora);
// Self-heal for state poisoned before the Detener anchor fix: a stop
// that closed a FUTURE occurrence wrote it into
// ultimaEjecucionGestionada, and _esValida rejects any candidate
// matching it -- so the alarm silently skips that day forever after,
// with nothing in the UI to explain it. An occurrence cannot have been
// handled before it happens, so a value meaningfully in the future is
// corrupt by definition and safe to drop: it can only ever suppress a
// real future ring, never prevent a double-fire (which needs a PAST
// occurrence to guard). Placed here, in the recalculation every load and
// every mutation already funnels through, so an affected alarm heals on
// the next app open with no user action.
final gestionada = alarma.ultimaEjecucionGestionada;
final gestionadaCorrupta =
gestionada != null &&
gestionada.isAfter(
ahora.add(ServicioProgramacionAlarmas.toleranciaDisparoInminente),
);
final saneada =
gestionadaCorrupta
? alarma.copyWith(limpiarUltimaEjecucionGestionada: true)
: alarma;
final proxima = _programacion.calcularProxima(
alarma: alarma,
alarma: saneada,
desde: ahora,
vacaciones: vacaciones,
excepciones: excepciones,
);
return alarma.copyWith(
return saneada.copyWith(
proximaEjecucion: proxima,
limpiarProximaEjecucion: true,
limpiarSnooze: !snoozeActivo,
+224
View File
@@ -0,0 +1,224 @@
import 'dart:async';
import 'package:flutter/foundation.dart' show debugPrint, kReleaseMode;
import 'package:google_mobile_ads/google_mobile_ads.dart';
/// Official Google TEST ad unit ids. ALWAYS used outside release builds —
/// tapping your own real ad unit during development/testing is invalid
/// traffic and AdMob suspends accounts for it, so this is not optional.
const bannerAdUnitIdPrueba = 'ca-app-pub-3940256099942544/6300978111';
const interstitialAdUnitIdPrueba = 'ca-app-pub-3940256099942544/1033173712';
/// Real banner unit id, provisioned in the AdMob console (iap-freemium-unlock).
const _bannerAdUnitIdReal = 'ca-app-pub-6038935671414339/5658618378';
/// Real interstitial unit id, provisioned in the AdMob console (iap-freemium-unlock).
const _interstitialAdUnitIdReal = 'ca-app-pub-6038935671414339/4189478248';
/// TESTING-PHASE SWITCH. While `true`, release builds serve Google's official
/// TEST ad units instead of the real ones, so none of the closed-testing
/// human testers can generate invalid traffic against the AdMob account
/// (they cannot be registered as AdMob test devices). Flip to `false` for
/// the production release — that is the ONLY change needed to start serving
/// real ads. This does NOT affect the AdMob application id in
/// `AndroidManifest.xml`, which stays real in every build (it only
/// initializes the SDK and carries none of the click risk).
const usarAnunciosDePruebaEnRelease = true;
/// Real id in release builds only, and only once [usarAnunciosDePruebaEnRelease]
/// is flipped to `false`; test id everywhere else (debug/profile, including
/// internal-testing-track builds run via `flutter run --release` on a
/// personal device — see the "never tap your own ads" note above).
const bannerAdUnitId =
kReleaseMode && !usarAnunciosDePruebaEnRelease
? _bannerAdUnitIdReal
: bannerAdUnitIdPrueba;
const interstitialAdUnitId =
kReleaseMode && !usarAnunciosDePruebaEnRelease
? _interstitialAdUnitIdReal
: interstitialAdUnitIdPrueba;
/// Ads port + AdMob adapter (Design "Interfaces / Contracts", ADR-6): owns
/// the entitlement gate for both surfaces, the interstitial's session
/// frequency cap, and is the ONLY `google_mobile_ads` call site besides
/// `banner_anuncio_superior.dart`'s `BannerAd` widget wrapper. The frequency
/// cap and premium gating are pure/injectable (`ahora`,
/// `mostrarInterstitialImpl`) so they are unit-testable with a fake clock
/// and zero AdMob platform channels (Design Testing Strategy).
class ServicioAnuncios {
ServicioAnuncios({
required bool Function() esPremium,
DateTime Function()? ahora,
Future<bool> Function()? mostrarInterstitialImpl,
Duration? timeoutIntentoInterstitial,
}) : _esPremium = esPremium,
_ahora = ahora ?? DateTime.now,
_mostrarInterstitialImpl =
mostrarInterstitialImpl ?? _mostrarInterstitialAdMob,
_timeoutIntentoInterstitial =
timeoutIntentoInterstitial ?? timeoutIntentoInterstitialPorDefecto;
/// Session-scoped cap (ad-display spec "Interstitial Frequency Cap"): at
/// most 2 interstitials per process lifetime.
static const maxInterstitialsPorSesion = 2;
/// Minimum spacing between two interstitials (ad-display spec, same
/// requirement).
static const separacionMinima = Duration(minutes: 3);
/// FIX 2 (code review): bounds `InterstitialAd.load`'s callback wait
/// inside [_mostrarInterstitialAdMob] so a load callback that never fires
/// cannot hang a caller — every call site (`pantalla_alarmas.dart`,
/// `pantalla_favoritos.dart`,
/// `ajustes/pantalla_ajustes_emisoras_personalizadas.dart`) `await`s
/// [intentarInterstitial] before opening its form.
static const timeoutCargaInterstitialPorDefecto = Duration(seconds: 5);
/// FIX 2 (code review): bounds the wait for the ad to actually PRESENT
/// (`onAdShowedFullScreenContent`) or fail
/// (`onAdFailedToShowFullScreenContent`) after `show()`. This method
/// deliberately never waits for the ad to be DISMISSED — the caller is
/// not blocked on ad dismissal at all, only on the ad actually rendering.
static const timeoutPresentacionInterstitialPorDefecto = Duration(seconds: 5);
/// FIX 2 (code review): the overall bound applied around the INJECTED
/// [_mostrarInterstitialImpl] itself (production default: the sum of the
/// two timeouts above, plus headroom) — so ANY implementation, including
/// a future bug in an injected fake or a different ad SDK, can never hang
/// a caller indefinitely. Injectable so tests can use a short value.
static const timeoutIntentoInterstitialPorDefecto = Duration(seconds: 15);
final bool Function() _esPremium;
final DateTime Function() _ahora;
final Future<bool> Function() _mostrarInterstitialImpl;
final Duration _timeoutIntentoInterstitial;
int _mostrados = 0;
DateTime? _ultimoMostrado;
/// Ad-display spec "Persistent Top Banner": absent entirely for premium.
bool get debeMostrarBanner => !_esPremium();
bool _dentroDelCap() {
if (_esPremium()) return false;
if (_mostrados >= maxInterstitialsPorSesion) return false;
final ultimo = _ultimoMostrado;
if (ultimo != null && _ahora().difference(ultimo) < separacionMinima) {
return false;
}
return true;
}
/// Attempts to show an interstitial for one of the two allowed CTAs (add
/// station manually, add alarm). Callers are responsible for the ADR-6
/// ordering invariant themselves (cap-check-before-interstitial for
/// add-alarm, so a refusal is never preceded by an ad) — this method only
/// owns entitlement + frequency-cap gating, never the caller's own
/// business-rule ordering.
///
/// Returns whether an interstitial actually rendered. A failed/aborted ad
/// load (network, no fill) does NOT consume the session cap — only a
/// genuinely SHOWN ad does (Spec intent: the cap limits driver-facing
/// interruptions, not load attempts).
Future<bool> intentarInterstitial() async {
if (!_dentroDelCap()) return false;
// FIX 2 (code review): bound the injected implementation itself — no
// caller may ever await this indefinitely, regardless of what
// [_mostrarInterstitialImpl] does internally. A timeout is treated
// exactly like "no ad shown": `false`, cap not consumed.
final mostrado = await _mostrarInterstitialImpl().timeout(
_timeoutIntentoInterstitial,
onTimeout: () => false,
);
if (mostrado) {
_mostrados++;
_ultimoMostrado = _ahora();
}
return mostrado;
}
static Future<bool> _mostrarInterstitialAdMob() async {
try {
final cargaCompleter = Completer<InterstitialAd?>();
// FIX 2 (code review): a load callback that never fires used to hang
// this await forever. `expiradoCarga` guards a LATE callback that
// still arrives after the timeout — the ad is disposed instead of
// leaked, and never completes the already-abandoned completer.
var expiradoCarga = false;
await InterstitialAd.load(
adUnitId: interstitialAdUnitId,
request: const AdRequest(),
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: (ad) {
if (expiradoCarga) {
ad.dispose();
return;
}
if (!cargaCompleter.isCompleted) cargaCompleter.complete(ad);
},
onAdFailedToLoad: (error) {
debugPrint('[PluriWave][anuncios] interstitial load ERROR $error');
if (!cargaCompleter.isCompleted) cargaCompleter.complete(null);
},
),
);
final InterstitialAd? cargado;
try {
cargado = await cargaCompleter.future.timeout(
timeoutCargaInterstitialPorDefecto,
);
} on TimeoutException {
expiradoCarga = true;
return false;
}
if (cargado == null) return false;
// FIX 6 (code review): only a genuinely PRESENTED ad may consume the
// session cap. `onAdFailedToShowFullScreenContent` used to complete
// the same completer as a real dismissal and the method returned
// `true` unconditionally — a failed-to-show ad silently burned one of
// only 2 session slots.
//
// FIX 2 (code review): this method no longer waits for the ad to be
// DISMISSED at all — only for it to PRESENT or fail to present — and
// that wait is itself bounded, so a `fullScreenContentCallback` that
// never fires cannot hang the caller either. `expiradoPresentacion`
// guards a late callback the same way `expiradoCarga` does above.
var expiradoPresentacion = false;
final presentacionCompleter = Completer<bool>();
cargado.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad) {
if (!presentacionCompleter.isCompleted) {
presentacionCompleter.complete(true);
}
},
onAdDismissedFullScreenContent: (ad) {
ad.dispose();
},
onAdFailedToShowFullScreenContent: (ad, error) {
if (expiradoPresentacion) {
ad.dispose();
return;
}
ad.dispose();
if (!presentacionCompleter.isCompleted) {
presentacionCompleter.complete(false);
}
},
);
await cargado.show();
try {
return await presentacionCompleter.future.timeout(
timeoutPresentacionInterstitialPorDefecto,
);
} on TimeoutException {
expiradoPresentacion = true;
await cargado.dispose();
return false;
}
} catch (e) {
debugPrint('[PluriWave][anuncios] interstitial ERROR $e');
return false;
}
}
}
File diff suppressed because it is too large Load Diff
+20 -6
View File
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:developer' as developer;
import 'package:audio_session/audio_session.dart';
import 'package:flutter/foundation.dart';
@@ -58,9 +57,26 @@ class ServicioAudioSession {
Future<void> configurar() async {
try {
final sesion = await _obtenerSesion();
// DUCK, never pause, when another app asks for transient focus.
//
// `androidWillPauseWhenDucked: true` makes `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 "OK Google" — and each one used to stop
// the radio outright instead of dipping the volume for two seconds.
//
// Worse than the audio gap: a pause publishes `playing: false`, which
// `AudioService.setState` turns into `exitPlayingState()` and, with
// `androidStopForegroundOnPause`, into `stopForeground(...)`. A service
// that is no longer in the foreground is killable, and when Android
// took it the app vanished from the Android Auto pane mid-drive and
// another media app took its slot. Ducking keeps `playing: true`
// throughout, so the session, the notification and the car pane all
// survive an interruption — which is also what keeps the equalizer
// alive across it.
await sesion.configure(
const AudioSessionConfiguration.music().copyWith(
androidWillPauseWhenDucked: true,
androidWillPauseWhenDucked: false,
),
);
await _interrupcionesSub?.cancel();
@@ -72,10 +88,8 @@ class ServicioAudioSession {
(_) => unawaited(manejarDesconexionSalida()),
);
} catch (e) {
developer.log(
'[PluriWave] No se pudo configurar la sesion de audio: $e',
name: 'ServicioAudioSession',
level: 900,
debugPrint(
'[PluriWave][ServicioAudioSession] No se pudo configurar la sesion de audio: $e',
);
}
}
+181
View File
@@ -0,0 +1,181 @@
import 'dart:async';
import 'package:flutter/foundation.dart' show debugPrint;
import 'package:in_app_purchase/in_app_purchase.dart';
/// Outcome kinds the purchase stream can report (Design ADR-2). Mirrors
/// `in_app_purchase`'s [PurchaseStatus] but stays a PluriWave-owned type so
/// [EstadoEntitlement] never imports the plugin package directly — the SAME
/// port-boundary discipline `PuertoAlarmasAndroid` already applies.
enum TipoEventoCompra {
/// A fresh purchase completed successfully.
comprada,
/// [PuertoCompras.restaurar] found a prior purchase.
restaurada,
/// The user cancelled the purchase flow before it completed.
cancelada,
/// The purchase/restore flow failed (network, billing error, etc).
error,
/// [PuertoCompras.restaurar] completed with nothing to restore — NOT an
/// error (Spec "Restore finds nothing").
noEncontrada,
/// A purchase is in-flight (billing dialog shown, awaiting the user).
pendiente,
}
/// A single purchase-stream event (Design ADR-2). [mensaje] is populated
/// only for [TipoEventoCompra.error], for diagnostics/logging — never shown
/// to the user verbatim.
class EventoCompra {
const EventoCompra(this.tipo, {this.mensaje});
final TipoEventoCompra tipo;
final String? mensaje;
}
/// Purchase I/O abstraction (Design ADR-2): [EstadoEntitlement] depends on
/// this port, never on `in_app_purchase` directly — matches
/// `EstadoAlarmas(android: PuertoAlarmasAndroid)`'s injection shape, and
/// keeps Strict TDD viable with zero plugin channels in unit tests.
abstract class PuertoCompras {
/// Broadcasts every purchase-flow outcome (Design ADR-2) — [comprar] and
/// [restaurar] do not return the outcome directly because
/// `in_app_purchase`'s own API is stream-based (a purchase can complete
/// asynchronously well after the call that started it, e.g. after leaving
/// and returning to the app).
Stream<EventoCompra> get eventos;
/// Starts the one-time non-consumable purchase flow.
Future<void> comprar();
/// Re-queries Play Billing for a prior purchase on this account.
Future<void> restaurar();
}
/// The SOLE `in_app_purchase` call site (Design ADR-2) — every other file
/// depends on [PuertoCompras] instead.
class ServicioComprasPlayBilling implements PuertoCompras {
ServicioComprasPlayBilling({InAppPurchase? inAppPurchase})
: _iap = inAppPurchase ?? InAppPurchase.instance {
_sub = _iap.purchaseStream.listen(
_alRecibirCompras,
onError: (Object error) {
debugPrint('[PluriWave][compras] purchaseStream ERROR $error');
_eventos.add(
EventoCompra(TipoEventoCompra.error, mensaje: error.toString()),
);
},
);
}
/// The single non-consumable product id (Design "Interfaces / Contracts").
static const idProducto = 'pluriwave_premium';
final InAppPurchase _iap;
final _eventos = StreamController<EventoCompra>.broadcast();
StreamSubscription<List<PurchaseDetails>>? _sub;
@override
Stream<EventoCompra> get eventos => _eventos.stream;
@override
Future<void> comprar() async {
try {
final disponible = await _iap.isAvailable();
if (!disponible) {
_eventos.add(
const EventoCompra(
TipoEventoCompra.error,
mensaje: 'Play Billing no disponible',
),
);
return;
}
final respuesta = await _iap.queryProductDetails({idProducto});
final detalle = respuesta.productDetails.firstOrNull;
if (detalle == null) {
_eventos.add(
const EventoCompra(
TipoEventoCompra.error,
mensaje: 'Producto no encontrado en Play Console',
),
);
return;
}
final parametros = PurchaseParam(productDetails: detalle);
await _iap.buyNonConsumable(purchaseParam: parametros);
} catch (e) {
debugPrint('[PluriWave][compras] comprar ERROR $e');
_eventos.add(EventoCompra(TipoEventoCompra.error, mensaje: e.toString()));
}
}
@override
Future<void> restaurar() async {
try {
await _iap.restorePurchases();
} catch (e) {
debugPrint('[PluriWave][compras] restaurar ERROR $e');
_eventos.add(EventoCompra(TipoEventoCompra.error, mensaje: e.toString()));
}
}
void _alRecibirCompras(List<PurchaseDetails> compras) {
if (compras.isEmpty) {
// `restorePurchases()` with nothing to restore pushes an EMPTY batch
// (`in_app_purchase_android` does `_purchaseUpdatedController.add(
// pastPurchases)` unconditionally) — there is no per-call correlation
// in this stream, so this fires on ANY empty batch. In practice
// `restorePurchases` on an account with nothing to restore is the only
// source of an empty batch this stream would ever emit.
//
// Returning silently here (as this did before) left
// [TipoEventoCompra.noEncontrada] NEVER emitted, so
// `EstadoEntitlement._compraEnCurso` stayed `true` forever and
// `hoja_premium.dart` kept BOTH buttons disabled — restore AND buy.
// A paywall that cannot be paid.
_eventos.add(const EventoCompra(TipoEventoCompra.noEncontrada));
return;
}
for (final compra in compras) {
_eventos.add(
eventoDesdeEstadoCompra(compra.status, mensaje: compra.error?.message),
);
if (compra.pendingCompletePurchase) {
unawaited(_iap.completePurchase(compra));
}
}
}
Future<void> dispose() async {
await _sub?.cancel();
await _eventos.close();
}
}
/// Pure mapping from `in_app_purchase`'s [PurchaseStatus] to the
/// PluriWave-owned [EventoCompra] (Design ADR-2's port boundary): pulled out
/// of [ServicioComprasPlayBilling] so it is unit-testable with zero plugin
/// channels, mirroring how `servicio_audio.dart` extracts its pure mapping
/// helpers (e.g. `mapearEstadoProceso`) out of the un-instantiable handler.
EventoCompra eventoDesdeEstadoCompra(PurchaseStatus status, {String? mensaje}) {
return switch (status) {
PurchaseStatus.pending => const EventoCompra(TipoEventoCompra.pendiente),
PurchaseStatus.purchased => const EventoCompra(TipoEventoCompra.comprada),
PurchaseStatus.restored => const EventoCompra(TipoEventoCompra.restaurada),
PurchaseStatus.error => EventoCompra(
TipoEventoCompra.error,
mensaje: mensaje,
),
PurchaseStatus.canceled => const EventoCompra(TipoEventoCompra.cancelada),
};
}
extension<T> on List<T> {
T? get firstOrNull => isEmpty ? null : first;
}
+106
View File
@@ -0,0 +1,106 @@
import 'dart:async';
import 'package:flutter/foundation.dart' show debugPrint;
import 'package:google_mobile_ads/google_mobile_ads.dart';
/// GDPR/UMP consent I/O abstraction (FIX 4, code review): every other file
/// depends on this port, never on the `google_mobile_ads` UMP classes
/// (`ConsentInformation`, `ConsentForm`) directly — matches
/// `PuertoCompras`'s injection shape, and keeps this testable with zero
/// AdMob/UMP platform channels in unit tests.
abstract class PuertoConsentimiento {
/// Requests consent info, loads-and-shows the consent form if required,
/// and resolves whether ads may be requested afterwards
/// (`ConsentInformation.canRequestAds()`). Implementations must NEVER
/// throw — any underlying failure degrades to `false` (no ads served),
/// never crashes or blocks the caller.
Future<bool> resolver();
}
/// The SOLE UMP call site (FIX 4) — every other file depends on
/// [PuertoConsentimiento] instead.
class ServicioConsentimientoUmp implements PuertoConsentimiento {
ServicioConsentimientoUmp({
ConsentRequestParameters? parametros,
Duration? timeoutActualizacion,
}) : _parametros = parametros ?? ConsentRequestParameters(),
_timeoutActualizacion =
timeoutActualizacion ?? const Duration(seconds: 10);
final ConsentRequestParameters _parametros;
final Duration _timeoutActualizacion;
@override
Future<bool> resolver() async {
try {
// 1. Request an up-to-date consent status. FIX 2's lesson applies
// here too: bound the callback-based wait so a callback that never
// fires cannot hang startup.
final actualizacionCompleter = Completer<void>();
ConsentInformation.instance.requestConsentInfoUpdate(
_parametros,
() {
if (!actualizacionCompleter.isCompleted) {
actualizacionCompleter.complete();
}
},
(error) {
debugPrint(
'[PluriWave][consentimiento] requestConsentInfoUpdate ERROR '
'${error.message}',
);
if (!actualizacionCompleter.isCompleted) {
actualizacionCompleter.complete();
}
},
);
await actualizacionCompleter.future.timeout(
_timeoutActualizacion,
onTimeout: () {},
);
// 2. Load-and-show the consent form ONLY IF the UMP SDK itself
// determines it is required (EEA/UK traffic, no prior valid
// consent) — this single call is a no-op everywhere else.
await ConsentForm.loadAndShowConsentFormIfRequired((formError) {
if (formError != null) {
debugPrint(
'[PluriWave][consentimiento] '
'loadAndShowConsentFormIfRequired ERROR ${formError.message}',
);
}
});
// 3. The only gate that matters for the caller: may ads be
// requested at all right now?
return await ConsentInformation.instance.canRequestAds();
} catch (e) {
debugPrint('[PluriWave][consentimiento] ERROR $e');
return false;
}
}
}
/// Orchestrates the whole gate (FIX 4): premium users NEVER see a consent
/// form at all — they get zero ads regardless of consent — so
/// [PuertoConsentimiento] is never even touched for them. Free-tier users
/// get the real flow, with any failure degrading silently to "ads not
/// allowed" rather than crashing or blocking `main()`.
Future<bool> resolverConsentimientoAnuncios({
required bool esPremium,
required PuertoConsentimiento consentimiento,
}) async {
if (esPremium) return false;
try {
return await consentimiento.resolver();
} catch (e) {
// Defense in depth: [PuertoConsentimiento.resolver] is documented to
// never throw, but a caller-provided implementation (fake or future
// adapter) failing to honor that contract still may not crash or block
// `main()`.
debugPrint(
'[PluriWave][consentimiento] resolverConsentimientoAnuncios ERROR $e',
);
return false;
}
}
@@ -157,7 +157,9 @@ class ServicioDispositivoAudioReal extends ServicioDispositivoAudio {
@override
Future<Map<String, String>> obtenerNombresEmparejados() async {
try {
final raw = await _methodChannel.invokeMethod<Map>('getBondedDeviceNames');
final raw = await _methodChannel.invokeMethod<Map>(
'getBondedDeviceNames',
);
if (raw == null) return const {};
return {
for (final entry in raw.entries)
+61 -17
View File
@@ -70,7 +70,10 @@ class ServicioEcualizador {
final porEmisora = _leerPresetsPorEmisora(prefs);
final presetsDispositivo = _leerMapa(prefs, _keyPresetsPorDispositivo);
final presetsMatriz = _leerMapa(prefs, _keyPresetsMatriz);
final nombresDispositivos = _leerMapaStrings(prefs, _keyNombresDispositivos);
final nombresDispositivos = _leerMapaStrings(
prefs,
_keyNombresDispositivos,
);
return ConfiguracionEcualizador(
principal: principal,
porEmisora: porEmisora,
@@ -124,21 +127,22 @@ class ServicioEcualizador {
String prefijo,
) async {
final presetsPorDispositivo = _leerMapa(prefs, _keyPresetsPorDispositivo);
final dispositivos = presetsPorDispositivo.keys
.where((clave) => clave.startsWith(prefijo))
.toList();
final dispositivos =
presetsPorDispositivo.keys
.where((clave) => clave.startsWith(prefijo))
.toList();
final nombres = _leerMapaStrings(prefs, _keyNombresDispositivos);
final nombresAPurgar = nombres.keys
.where((clave) => clave.startsWith(prefijo))
.toList();
final nombresAPurgar =
nombres.keys.where((clave) => clave.startsWith(prefijo)).toList();
final matriz = _leerMapa(prefs, _keyPresetsMatriz);
final matrizAPurgar = matriz.keys.where((clave) {
final separador = clave.indexOf(':');
if (separador == -1) return false;
return clave.substring(separador + 1).startsWith(prefijo);
}).toList();
final matrizAPurgar =
matriz.keys.where((clave) {
final separador = clave.indexOf(':');
if (separador == -1) return false;
return clave.substring(separador + 1).startsWith(prefijo);
}).toList();
for (final clave in dispositivos) {
presetsPorDispositivo.remove(clave);
@@ -183,11 +187,12 @@ class ServicioEcualizador {
// (station UUIDs are RFC4122 and contain no colons — multi-device-eq
// ADR-3), since deviceId itself may contain colons (e.g. a MAC-based id).
final presetsMatriz = _leerMapa(prefs, _keyPresetsMatriz);
final clavesMatrizAPurgar = presetsMatriz.keys.where((clave) {
final separador = clave.indexOf(':');
if (separador == -1) return false;
return clave.substring(separador + 1) == deviceId;
}).toList();
final clavesMatrizAPurgar =
presetsMatriz.keys.where((clave) {
final separador = clave.indexOf(':');
if (separador == -1) return false;
return clave.substring(separador + 1) == deviceId;
}).toList();
if (clavesMatrizAPurgar.isNotEmpty) {
for (final clave in clavesMatrizAPurgar) {
presetsMatriz.remove(clave);
@@ -233,6 +238,45 @@ class ServicioEcualizador {
await prefs.setBool(_keyActivo, activo);
}
/// The persisted equalizer on/off flag, or `null` when the user has never
/// touched the toggle.
///
/// Deliberately narrower than [cargar] (eq-estado-unico item A): it reads
/// ONE key and runs none of the migrations, because its caller is
/// `registrarHandler`, on the audio bootstrap path of EVERY engine —
/// including the headless one Android Auto starts, where there is no
/// widget tree and `EstadoEcualizador` never exists. It must stay cheap
/// and it must never mutate anything.
///
/// `null` is preserved rather than collapsed to a default so that
/// `estadoEqInicial` — not this service — owns the "never persisted"
/// policy in exactly one place.
Future<bool?> leerActivo() async {
final prefs = await _resolverPrefs();
return prefs.getBool(_keyActivo);
}
/// The persisted principal preset, or `null` when the user has never saved
/// one.
///
/// The exact sibling of [leerActivo] and narrow for the same reason: its
/// caller is `registrarHandler`, on the audio bootstrap path of EVERY
/// engine — including the headless one Android Auto starts, where there is
/// no widget tree and `EstadoEcualizador` never exists to push a preset
/// into the handler. It reads ONE key, runs none of [cargar]'s migrations
/// and mutates nothing.
///
/// `null` (nothing saved, or an unreadable value) is preserved rather than
/// collapsed to [PresetEcualizador.flat] so the handler's own default —
/// not this service — decides what "never persisted" means, and so a seed
/// with nothing to say does not overwrite anything.
Future<PresetEcualizador?> leerPresetPrincipal() async {
final prefs = await _resolverPrefs();
final raw = prefs.getString(_keyPresetPrincipal);
if (raw == null || raw.isEmpty) return null;
return _leerPresetPrincipal(prefs);
}
Future<void> eliminarPorEmisora(String uuid) async {
final prefs = await _resolverPrefs();
final mapa = _leerPresetsPorEmisora(prefs);
+35 -10
View File
@@ -7,26 +7,33 @@ import '../modelos/preset_ecualizador.dart';
/// Owns the backup (export/import) JSON serialization (S4-R4).
///
/// v3 extends v2 with `presetsPorDispositivo`, `presetsMatriz`, and
/// `eqMultiDeviceEnabled`. When those optional parameters are omitted the
/// export stays at v2 for backward compat with the old app. State APPLICATION
/// (writing favorites, EQ, alarms back into the app) stays in
/// `eqMultiDeviceEnabled`. v4 extends v3 with `ecualizadorActivo` (the
/// equalizer's global ON/OFF toggle). When the version-N extension
/// parameters are all omitted the export stays at the lower version for
/// backward compat with older app builds. State APPLICATION (writing
/// favorites, EQ, alarms back into the app) stays in
/// `EstadoRadio.importarConfig` — this service only owns serialization,
/// parsing and the envelope shape.
class ServicioExportImport {
const ServicioExportImport();
/// Current backup schema version (v3multi-device EQ).
static const int versionActual = 3;
/// Current backup schema version (v4equalizer on/off toggle).
static const int versionActual = 4;
/// v3 version constant (multi-device EQ) kept for clarity.
static const int versionV3 = 3;
/// Legacy v2 version constant kept for clarity.
static const int versionV2 = 2;
/// Builds the export envelope.
///
/// When [presetsPorDispositivo] or [presetsMatriz] are provided (non-null),
/// [versionActual] (3) is written. When both are omitted the call behaves
/// identically to the original v2 format (version key stays 2) so old
/// backups keep round-tripping without version bumps.
/// When [presetsPorDispositivo] or [presetsMatriz] or
/// [eqMultiDeviceEnabled] are provided (non-null), at least [versionV3] (3)
/// is written. When [ecualizadorActivo] is ALSO provided (non-null),
/// [versionActual] (4) is written. Omitting all of them behaves identically
/// to the original v2 format (version key stays 2) so old backups keep
/// round-tripping without version bumps.
///
/// The `alarmas` block is the RAW JSON map persisted by ServicioAlarmas
/// and passes through untouched (no re-parsing here).
@@ -45,14 +52,27 @@ class ServicioExportImport {
Map<String, PresetEcualizador>? presetsPorDispositivo,
Map<String, PresetEcualizador>? presetsMatriz,
bool? eqMultiDeviceEnabled,
// v4 extension — the equalizer's global ON/OFF toggle. Omitting it
// produces a v3 (or v2)-compatible export.
bool? ecualizadorActivo,
}) {
final tieneExtensionesV3 =
presetsPorDispositivo != null ||
presetsMatriz != null ||
eqMultiDeviceEnabled != null;
final tieneExtensionV4 = ecualizadorActivo != null;
final int version;
if (tieneExtensionV4) {
version = versionActual;
} else if (tieneExtensionesV3) {
version = versionV3;
} else {
version = versionV2;
}
final envelope = <String, dynamic>{
'version': tieneExtensionesV3 ? versionActual : versionV2,
'version': version,
'exportedAt': (exportadoEn ?? DateTime.now()).toIso8601String(),
// Favorites + groups (preserves grupo_id assignments per station).
// The protected "sin asignar" group is implicit and never exported.
@@ -88,6 +108,11 @@ class ServicioExportImport {
envelope['eqMultiDeviceEnabled'] = eqMultiDeviceEnabled ?? false;
}
// v4 extension: only written when explicitly provided.
if (tieneExtensionV4) {
envelope['ecualizadorActivo'] = ecualizadorActivo;
}
return envelope;
}
+37
View File
@@ -213,6 +213,43 @@ class ServicioFavoritos {
);
}
/// Restaura un favorito tal como estaba en el dispositivo de origen,
/// preservando su `orden` y su `grupo_id`.
/// Usado exclusivamente por importarConfig, igual que [restaurarGrupo].
///
/// Existe porque [agregar] NO sirve como primitiva de restauración: es la
/// primitiva de «marcar como favorita» y fuerza `sin_asignar` más un
/// `orden` al final de la lista, cosa correcta para una emisora recién
/// marcada (que de verdad no pertenece a ningún grupo) y destructiva para
/// una copia de seguridad, que trae ambos campos. Reusarla era la causa de
/// que los grupos volvieran vacíos tras restaurar.
///
/// El grupo se valida igual que en [asignarGrupo]: un `grupo_id` que no
/// existe en `grupos_favoritos` cae a [GrupoFavoritos.sinAsignarId], de modo
/// que una copia editada a mano o restaurada a medias no puede dejar
/// emisoras apuntando a un grupo inexistente. `importarConfig` restaura los
/// grupos ANTES de este bucle, así que en el camino normal siempre existen.
Future<void> restaurarFavorito(Emisora emisora) async {
final db = await _database;
final existe =
Sqflite.firstIntValue(
await db.rawQuery(
'SELECT COUNT(*) FROM grupos_favoritos WHERE id = ?',
[emisora.grupoFavoritosId],
),
) ??
0;
final restaurada =
existe > 0
? emisora
: emisora.copyWith(grupoFavoritosId: GrupoFavoritos.sinAsignarId);
await db.insert(
'favoritos',
restaurada.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
Future<void> eliminarGrupo(String id) async {
if (id == GrupoFavoritos.sinAsignarId) return;
final db = await _database;
+122
View File
@@ -0,0 +1,122 @@
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';
import '../estado/estado_entitlement.dart';
import '../servicios/servicio_anuncios.dart';
/// Entitlement-aware top-banner slot (Design ADR-6, ad-display spec
/// "Persistent Top Banner, Never Overlapping Content"). Collapses to
/// `SizedBox.shrink()` — zero reserved space, zero layout impact — whenever
/// the user is premium OR no ad has finished loading yet; only a
/// successfully loaded [BannerAd] renders a sized box around an [AdWidget].
/// Callers place this as a plain sibling in a `Column` ABOVE the existing
/// body (`app.dart`'s `_PaginaPrincipalState.build`) — this widget itself
/// never wraps its parent in a `Stack`/overlay.
class BannerAnuncioSuperior extends StatefulWidget {
const BannerAnuncioSuperior({super.key, this.alIntentarCargar});
/// Test-only hook (FIX 7, code review): fires exactly once per REAL load
/// ATTEMPT (`BannerAd(...).load()` call), independent of the load's
/// eventual outcome — lets a widget test count load attempts without a
/// real AdMob platform channel. Always `null` in production.
@visibleForTesting
final VoidCallback? alIntentarCargar;
@override
State<BannerAnuncioSuperior> createState() => _BannerAnuncioSuperiorState();
}
class _BannerAnuncioSuperiorState extends State<BannerAnuncioSuperior> {
BannerAd? _bannerAd;
bool _cargado = false;
/// FIX 7 (code review): explicit "load already attempted" flag. Before
/// this, the guard was `_bannerAd == null`, which stays `null` until a
/// load actually SUCCEEDS — so every `notifyListeners()` from ANY
/// provider this widget watches (`EstadoEntitlement` during a
/// purchase/restore in progress) plus theme/locale/`MediaQuery` changes
/// re-ran `didChangeDependencies` and spawned ANOTHER `BannerAd` +
/// `load()` call. Only the LAST loaded ad was ever disposed, leaking
/// every in-flight duplicate before it.
///
/// Retry policy (documented decision): a FAILED load is never retried
/// automatically — this flag is set once and never reset. Retrying on
/// every rebuild is exactly the bug this flag fixes; the next natural
/// retry opportunity is a fresh app session, which is an adequate cadence
/// for a non-critical, collapse-to-nothing UI element.
bool _cargaIntentada = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
final servicio = context.read<ServicioAnuncios>();
if (!_cargaIntentada && servicio.debeMostrarBanner) {
_cargaIntentada = true;
_cargarBanner();
}
}
void _cargarBanner() {
widget.alIntentarCargar?.call();
// Fire-and-forget: a failure (no plugin channel in `flutter test`, no
// fill, offline) leaves `_bannerAd` `null` forever, which keeps this
// widget collapsed — exactly the same degrade-to-shrink path a genuine
// load failure takes in production. Never throws out of this method.
final anuncio = BannerAd(
size: AdSize.banner,
adUnitId: bannerAdUnitId,
request: const AdRequest(),
listener: BannerAdListener(
onAdLoaded: (ad) {
if (!mounted) {
ad.dispose();
return;
}
setState(() {
_bannerAd = ad as BannerAd;
_cargado = true;
});
},
onAdFailedToLoad: (ad, error) {
ad.dispose();
},
),
);
anuncio.load().catchError((_) {});
}
@override
void dispose() {
_bannerAd?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final entitlement = context.watch<EstadoEntitlement>();
if (entitlement.esPremium) return const SizedBox.shrink();
// Instant vanish-on-purchase (ad-display spec "Ads Vanish Immediately
// On Purchase"): even a banner that finished loading BEFORE this
// transition is dropped, never shown to a now-premium user.
if (!_cargado || _bannerAd == null) return const SizedBox.shrink();
final ad = _bannerAd!;
// FIX 1 (code review): the top-inset `SafeArea` now lives HERE, applied
// ONLY when an ad is actually about to render. `SafeArea` reserves
// `MediaQuery.padding.top` regardless of its child's own size — even a
// zero-size `SizedBox.shrink()` child — so the OLD unconditional
// `app.dart`-level `SafeArea(bottom: false, child: BannerAnuncioSuperior())`
// wrapper left a permanent blank status-bar-height strip both for
// premium users and for free users before the first ad finished
// loading. Collapsing (the two early returns above) now returns a
// TRULY zero-height widget, including no reserved padding.
return SafeArea(
bottom: false,
child: SizedBox(
width: ad.size.width.toDouble(),
height: ad.size.height.toDouble(),
child: AdWidget(ad: ad),
),
);
}
}
+219
View File
@@ -0,0 +1,219 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../estado/estado_entitlement.dart';
import '../l10n/gen/app_localizations.dart';
import '../tema/pluriwave_tokens.dart';
import 'pluri_glass_surface.dart';
import 'pluri_layout.dart';
/// Reusable paywall sheet (Design "File Changes" — `hoja_premium.dart`),
/// opened from every gated entry point plus the Settings premium row
/// (freemium-gating spec "Purchase Entry Points At Every Gate Plus
/// Settings"). Mirrors `FormularioEmisoraPersonalizada`'s bottom-sheet
/// shape (`ajustes_emisoras_personalizadas.dart`).
Future<void> mostrarHojaPremium(BuildContext context) {
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
backgroundColor: Colors.transparent,
builder: (_) => const HojaPremium(),
);
}
class HojaPremium extends StatelessWidget {
const HojaPremium({super.key});
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final entitlement = context.watch<EstadoEntitlement>();
final bottom = MediaQuery.of(context).viewInsets.bottom;
return Padding(
padding: EdgeInsets.fromLTRB(
PluriLayout.horizontal,
PluriLayout.horizontal,
PluriLayout.horizontal,
PluriLayout.horizontal + bottom,
),
child: PluriGlassSurface(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Icon(
Icons.workspace_premium_rounded,
color: PluriWaveTokens.brand,
),
const SizedBox(width: 10),
Expanded(
child: Text(
l10n.premiumHojaTitulo,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w900,
),
),
),
// Explicit, obvious dismiss affordance (fix/import-alarmas-y-
// paywall): a purchase sheet the user cannot easily escape is
// a dark pattern and a Play policy risk. Reachable without
// buying or restoring, same weight as any other icon button.
IconButton(
key: const ValueKey('hoja-premium-cerrar'),
icon: const Icon(Icons.close_rounded),
tooltip: l10n.closeAction,
onPressed: () => Navigator.of(context).maybePop(),
),
],
),
const SizedBox(height: 12),
// Concrete, honest value list — accuracy is non-negotiable here:
// these five are the ONLY things premium unlocks. The phone
// equalizer stays free for everyone and must NEVER appear here;
// only its Android Auto surface is affected, as a consequence of
// Auto itself being gated.
_BeneficioPremium(texto: l10n.premiumBeneficioSinAnuncios),
_BeneficioPremium(texto: l10n.premiumBeneficioAndroidAuto),
_BeneficioPremium(texto: l10n.premiumBeneficioGrabacion),
_BeneficioPremium(texto: l10n.premiumBeneficioVacaciones),
_BeneficioPremium(texto: l10n.premiumBeneficioAlarmasIlimitadas),
const SizedBox(height: 12),
Text(
l10n.premiumPagoUnico,
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w600),
),
const SizedBox(height: 20),
// FIX 3 (code review): user-facing feedback for a failed
// purchase/restore, or a restore that found nothing — before
// this, `resultadoUsuario` had ZERO UI, so the spinner just
// stopped with no feedback at all. Never the raw
// `EventoCompra.mensaje` developer string — always the mapped,
// generic localized message.
if (entitlement.resultadoUsuario != null)
Padding(
key: const ValueKey('hoja-premium-resultado'),
padding: const EdgeInsets.only(bottom: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
entitlement.resultadoUsuario ==
ResultadoEntitlementUsuario.error
? Icons.error_outline_rounded
: Icons.info_outline_rounded,
size: 18,
color:
entitlement.resultadoUsuario ==
ResultadoEntitlementUsuario.error
? Theme.of(context).colorScheme.error
: Theme.of(context).textTheme.bodyMedium?.color,
),
const SizedBox(width: 8),
Expanded(
child: Text(
entitlement.resultadoUsuario ==
ResultadoEntitlementUsuario.error
? l10n.compraError
: l10n.restauracionSinCompras,
style: Theme.of(context).textTheme.bodyMedium,
),
),
IconButton(
key: const ValueKey('hoja-premium-resultado-descartar'),
icon: const Icon(Icons.close_rounded, size: 18),
onPressed: () => entitlement.consumirResultadoUsuario(),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
visualDensity: VisualDensity.compact,
),
],
),
),
if (entitlement.esPremium)
Padding(
key: const ValueKey('hoja-premium-activo'),
padding: const EdgeInsets.only(bottom: 12),
child: Text(
l10n.premiumActivo,
style: Theme.of(context).textTheme.bodyMedium,
),
)
else
FilledButton.icon(
key: const ValueKey('hoja-premium-comprar'),
onPressed:
entitlement.compraEnCurso
? null
: () => entitlement.comprar(),
icon:
entitlement.compraEnCurso
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.lock_open_rounded),
label: Text(l10n.desbloquearPremium),
),
const SizedBox(height: 10),
OutlinedButton(
key: const ValueKey('hoja-premium-restaurar'),
onPressed:
entitlement.compraEnCurso
? null
: () => entitlement.restaurar(),
child: Text(l10n.restaurarCompras),
),
if (!entitlement.esPremium) ...[
const SizedBox(height: 4),
// Clearly-labelled, always-reachable decline — same weight as
// any other secondary action, never made harder to find than
// buying (hard constraint: no dark patterns, no guilt-shaming
// decline copy).
TextButton(
key: const ValueKey('hoja-premium-ahora-no'),
onPressed: () => Navigator.of(context).maybePop(),
child: Text(l10n.premiumAhoraNo),
),
],
],
),
),
);
}
}
/// One concrete, honest value-list row (fix/import-alarmas-y-paywall).
class _BeneficioPremium extends StatelessWidget {
const _BeneficioPremium({required this.texto});
final String texto;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.check_circle_rounded,
size: 18,
color: PluriWaveTokens.brand,
),
const SizedBox(width: 8),
Expanded(
child: Text(texto, style: Theme.of(context).textTheme.bodyMedium),
),
],
),
);
}
}
@@ -0,0 +1,100 @@
# Apply Progress: iap-freemium-unlock
Mode: Strict TDD. Delivery: single-pr with `size:exception` (user-approved, single commit).
## Status: ALL 9 PHASES COMPLETE — 27/27 TASKS DONE
## TDD Cycle Evidence
| Task(s) | RED | GREEN | REFACTOR | Test file(s) |
|---|---|---|---|---|
| 0.1/0.2 | N/A (config) | pubspec.yaml + AndroidManifest.xml | N/A | N/A |
| 1.1-1.3 | `estado_entitlement_test.dart` written first, failed (no impl) | `estado_entitlement.dart` (`EstadoEntitlement`, `esPremiumPersistido`) | shared `_keyPremium` const, fail-open documented in doc comments | test/estado/estado_entitlement_test.dart |
| 2.1-2.2 | `servicio_compras_test.dart` (pure mapping) written first, failed | `servicio_compras.dart` (`PuertoCompras`, `ServicioComprasPlayBilling`, `eventoDesdeEstadoCompra` extracted for testability) | N/A | test/servicios/servicio_compras_test.dart |
| 3.1-3.2 | `estado_alarmas_gating_test.dart` written first, failed | `ResultadoGuardarAlarma` enum + `puedeCrearAlarma` + gated `guardarAlarma`/`crearRangoVacaciones` | N/A | test/estado/estado_alarmas_gating_test.dart |
| 3.3 | N/A (UI wiring, no new pure logic) | `pantalla_alarmas.dart` (cap-check+interstitial at the "+" CTA tap per ADR-6, snackbar+CTA on block) + `pantalla_vacaciones.dart` (paywall on block) | Corrected mid-run: interstitial originally placed at save time, moved to the CTA tap per design.md's literal "then open the editor" wording | Regression: pantalla_alarmas_editor_test.dart, pantalla_alarmas_fecha_test.dart, pantalla_vacaciones_test.dart |
| 4.1-4.2 | `estado_grabacion_gating_test.dart` written first, failed | `ResultadoIniciarGrabacion` enum + gated `iniciar()` | N/A | test/estado/estado_grabacion_gating_test.dart |
| 5.1 | `navegacion_auto_gating_test.dart` written first, failed | `raiz(premium:)`, `itemPremiumBloqueado()`, `respuestaBloqueadaPorEntitlement()` | N/A | test/servicios/navegacion_auto_gating_test.dart |
| 5.2 | `servicio_audio_gating_test.dart` written first, failed | `debeBloquearCambioDeEmisora()` wired into `playFromMediaId`/`playFromSearch`/`skipToNext`/`skipToPrevious` | N/A | test/servicios/servicio_audio_gating_test.dart |
| 5.3 | same file, `notificarDesbloqueoAuto`/`registrarNotificacionDesbloqueoAuto` cases | Discovered mid-implementation that `AudioService.notifyChildrenChanged` is deprecated in this `audio_service` version — implemented via `subscribeToChildren` override + per-id `BehaviorSubject` + `notificarHijosCambiaron`, which is what the plugin's own internal listener now forwards to the platform | Wired `registrarHandler` to push to all root-level ids on the hook | test/servicios/servicio_audio_gating_test.dart |
| 5.4 | (covered above) | `getChildren` checks `respuestaBloqueadaPorEntitlement` before any other resolution | N/A | (covered above) + regression: navegacion_auto_test.dart |
| 6.1-6.2 | `servicio_anuncios_test.dart` (fake clock) written first, failed | `ServicioAnuncios` cap/gating logic + AdMob adapter (test ad unit IDs, TODO-marked) | N/A | test/servicios/servicio_anuncios_test.dart |
| 6.3 | `banner_anuncio_superior_test.dart` written first, failed | `BannerAnuncioSuperior` widget + `app.dart` `Column[banner, Expanded(body)]` | N/A | test/widgets/banner_anuncio_superior_test.dart |
| 7.1 | N/A (wiring) | `hoja_premium.dart` + `EstadoEntitlement`/`ServicioAnuncios` registered in `app.dart`'s provider list (EstadoEntitlement FIRST so later `create` closures can `context.read` it) | N/A | Regression: app_test.dart, widget_test.dart |
| 7.2 | N/A (wiring) | Settings premium row (`pantalla_ajustes.dart`); interstitial-before-open at both station-add CTAs (`pantalla_favoritos.dart`, `ajustes_emisoras_personalizadas.dart`) | N/A | Regression: pantalla_ajustes_test.dart, pantalla_favoritos_test.dart, ajustes/pantalla_ajustes_emisoras_personalizadas_test.dart |
| 8.1-8.3 | N/A (content) | 4 keys × 13 locales added to `app_*.arb`; `flutter gen-l10n` regenerated | N/A | literal-encoding scan clean |
| 9.1-9.3 | N/A (verification) | Full suite run in batches, equalizer grep-verified ungated, proposal.md checkboxes updated with verification notes | N/A | See Work Unit Evidence below |
## Files Changed
| File | Action | What Was Done |
|---|---|---|
| `pubspec.yaml` | Modified | Uncommented `in_app_purchase`, `google_mobile_ads` |
| `android/app/src/main/AndroidManifest.xml` | Modified | AdMob test app id meta-data (TODO to swap for real) |
| `lib/estado/estado_entitlement.dart` | Created | `EstadoEntitlement` ChangeNotifier + `esPremiumPersistido()` |
| `lib/servicios/servicio_compras.dart` | Created | `PuertoCompras` + `ServicioComprasPlayBilling` (sole `in_app_purchase` site) |
| `lib/servicios/servicio_anuncios.dart` | Created | `ServicioAnuncios` — banner/interstitial gating + frequency cap + AdMob adapter |
| `lib/widgets/banner_anuncio_superior.dart` | Created | Entitlement-aware top banner slot |
| `lib/widgets/hoja_premium.dart` | Created | Reusable paywall bottom sheet |
| `lib/estado/estado_alarmas.dart` | Modified | `ResultadoGuardarAlarma` enum, `puedeCrearAlarma()`, gated `guardarAlarma`/`crearRangoVacaciones`, `esPremium` injection (default `() => true`) |
| `lib/estado/estado_grabacion.dart` | Modified | `ResultadoIniciarGrabacion` enum, gated `iniciar()`, `esPremium` injection |
| `lib/estado/estado_radio.dart` | Modified | Threaded `esPremium` through to internal `EstadoGrabacion` |
| `lib/servicios/navegacion_auto.dart` | Modified | `raiz(premium:)`, `itemPremiumBloqueado()`, `respuestaBloqueadaPorEntitlement()` |
| `lib/servicios/servicio_audio.dart` | Modified | `getChildren`/`playFromMediaId`/`playFromSearch`/`skipToNext`/`skipToPrevious` gated; `subscribeToChildren` override + `notificarHijosCambiaron`; `registrarNotificacionDesbloqueoAuto`/`notificarDesbloqueoAuto` hook |
| `lib/pantallas/pantalla_alarmas.dart` | Modified | Cap-check + interstitial at the "+" CTA tap; cap snackbar + "Desbloquear Premium" CTA |
| `lib/pantallas/pantalla_vacaciones.dart` | Modified | Paywall sheet on gate block |
| `lib/pantallas/pantalla_reproductor.dart` | Modified | 3 record-start call sites route through the gate, open paywall on block |
| `lib/pantallas/pantalla_ajustes.dart` | Modified | Premium row (buy/restore/active) in APLICACIÓN group |
| `lib/pantallas/pantalla_favoritos.dart` | Modified | Interstitial before opening the add-station form |
| `lib/pantallas/ajustes/pantalla_ajustes_emisoras_personalizadas.dart` | Modified | Interstitial before opening the add-station form |
| `lib/app.dart` | Modified | `EstadoEntitlement`/`ServicioAnuncios` providers; `compras` injection param; banner `Column` wiring |
| `lib/main.dart` | Modified | `MobileAds.instance.initialize()`, `ServicioComprasPlayBilling` wiring |
| `lib/l10n/app_*.arb` (13 files) + `lib/l10n/gen/*` (regenerated) | Modified | `funcionPremium`, `limiteAlarmasAlcanzado`, `desbloquearPremium`, `restaurarCompras` |
| `openspec/changes/iap-freemium-unlock/proposal.md` | Modified | Success Criteria checked off with verification notes |
## Test Files Added
- test/estado/estado_entitlement_test.dart
- test/estado/estado_alarmas_gating_test.dart
- test/estado/estado_grabacion_gating_test.dart
- test/servicios/servicio_compras_test.dart
- test/servicios/servicio_anuncios_test.dart
- test/servicios/navegacion_auto_gating_test.dart
- test/servicios/servicio_audio_gating_test.dart
- test/widgets/banner_anuncio_superior_test.dart
## Test Files Modified (harness fixes — added `ServicioAnuncios`/`EstadoEntitlement` providers so pre-existing widget tests keep working against the new gated call sites)
- test/servicios/navegacion_auto_test.dart (3 `raiz()` call sites get `premium: true`)
- test/pantallas/pantalla_alarmas_fecha_test.dart
- test/pantallas/pantalla_ajustes_test.dart
- test/pantallas/pantalla_ajustes_row_values_test.dart
- test/pantallas/pantalla_favoritos_test.dart
- test/pantallas/ajustes/pantalla_ajustes_emisoras_personalizadas_test.dart
- test/pantallas/pluri_screen_header_retired_test.dart
- test/pantallas/root_header_wiring_test.dart
- test/widgets/pluri_push_scaffold_test.dart
## Deviations from Design (reported honestly)
1. **ADR-4 root/non-root reconciliation**: design.md's ADR-4 prose ("keeps the same visible folder labels for free users") and the android-auto-media spec's literal "rendered as ... explicitly locked item labeled as a premium feature" (for the ROOT) point in slightly different directions. Followed design.md/the orchestrator's own constraint summary: ROOT keeps real folder labels for every tier (regression-safe, byte-identical to today for premium); the lock is enforced one level down, at `getChildren`'s `respuestaBloqueadaPorEntitlement` choke point, which returns exactly one `itemPremiumBloqueado()` for ANY non-root id when free (including stale/deep-linked ids — the mandatory backstop).
2. **`notifyChildrenChanged` deprecated**: `audio_service` 0.18.18 deprecated the static `AudioService.notifyChildrenChanged` helper in favor of a `subscribeToChildren`-stream-based mechanism. Implemented `PluriWaveAudioHandler.subscribeToChildren` (a `BehaviorSubject` per parent id) + `notificarHijosCambiaron(id)`, which is what the plugin's own internal listener forwards to the platform. Functionally equivalent to the design's intent; the public hook name (`registrarNotificacionDesbloqueoAuto`/`notificarDesbloqueoAuto`) is unchanged.
3. **ADR-6 interstitial ordering — corrected mid-run**: initially implemented the alarm interstitial at SAVE time; corrected to fire at the "+" CTA tap (before the editor sheet even opens), matching design.md's literal "puedeCrearAlarma -> ... maybe-interstitial, then open the editor" and mirroring the add-station CTA's identical ordering.
4. **Default `esPremium` callbacks** in `EstadoAlarmas`/`EstadoGrabacion`/`EstadoRadio` default to `() => true` (ungated) when the caller doesn't inject one. This was necessary because 30+ pre-existing test files construct these classes with zero entitlement awareness and expect unrestricted (today's) behavior; production `app.dart` always wires the real `EstadoEntitlement`-backed callback. This is a deliberate, documented DI default, not a security gap — no production code path can reach the default.
5. **`crearRangoVacaciones` returns `bool`**, not `ResultadoGuardarAlarma` — vacations are a full premium gate (no free allowance), semantically distinct from the alarm cap's count-based enum, which design.md's Interfaces/Contracts scoped to `guardarAlarma` specifically.
6. **`PluriWaveApp` gained an optional `compras` constructor param** mirroring the existing `fuenteAuto` injection convention, so no pre-existing widget test ever touches the real `in_app_purchase` plugin channel; `main.dart` wires the real `ServicioComprasPlayBilling`.
7. **Paywall sheet copy stays minimal**: `HojaPremium` reuses the existing `l10n.equalizerActive` string for "active" state (an established codebase pattern for reusable generic labels) rather than inventing new arb keys beyond the 4 explicitly scoped in tasks.md, to keep the 13-locale translation surface bounded.
## Issues Found
- `dart format lib/ test/` (broad invocation) reformatted several pre-existing test files that were untouched semantically. These formatting-only diffs were identified via `git diff --stat` and reverted with `git checkout --` to keep this change scoped to the feature (avoiding an unrelated multi-hundred-line formatting diff riding along in the single-commit delivery).
- None outstanding beyond the above.
## Work Unit Evidence (cumulative, final)
- **Focused test command and result**: `flutter test test/estado/estado_entitlement_test.dart test/estado/estado_alarmas_gating_test.dart test/estado/estado_grabacion_gating_test.dart test/servicios/servicio_compras_test.dart test/servicios/servicio_anuncios_test.dart test/servicios/navegacion_auto_gating_test.dart test/servicios/servicio_audio_gating_test.dart test/widgets/banner_anuncio_superior_test.dart`**48/48 passed**.
- **Runtime harness**: full regression suite run in batches — `test/estado/` (207 passed), `test/servicios/` (512 passed), `test/widgets/` (96 passed), `test/pantallas/` (~248+ across all 30 files, run in multiple batches, all passed after harness fixes), top-level (`app_test.dart`, `arranque_orientacion_test.dart`, `assets_contenido_declarados_test.dart`, `widget_test.dart` — 38 passed). A single `flutter test` full-suite invocation exceeds this environment's command timeout (~10 min); batched runs are the practical substitute and cover 100% of files. Manual on-device QA (Play Billing sandbox purchase, real AdMob rendering, car head-unit browse) is explicitly out of reach of this environment and remains outstanding — noted in `proposal.md`.
- **Rollback boundary**: every file in the "Files Changed" table above is independently revertable; `pubspec.yaml`/`AndroidManifest.xml` revert re-comments both plugins per `proposal.md`'s Rollback Plan (no migration, no schema change, versioned prefs key `compra_premium_v1` is ignored by older builds).
## Final Verification
- `flutter analyze`: clean (5 issues, all pre-existing/unrelated: 2 `deprecated_member_use` on `onReorder` predating this change, 1 pre-existing `unused_catch_stack`, 1 pre-existing `annotate_overrides` info in `estado_radio_test.dart`).
- `dart format`: applied to every file this change touches; unrelated pre-existing files swept up by a broad format invocation were reverted (see Issues Found).
- Literal-encoding scan (`Ã|Â|â€|<25FD>`) on all 13 touched `.arb` files: clean except one PRE-EXISTING false positive (`app_pt.arb`'s legitimate "REPETIÇÃO", unrelated to this change).
- Equalizer regression check: zero `esPremium`/`EstadoEntitlement`/`esPremiumPersistido` references in `estado_ecualizador.dart`, `servicio_ecualizador.dart`, `pantalla_ajustes_ecualizador.dart`, `ecualizador_widget.dart` — confirmed via `grep`.
@@ -0,0 +1,116 @@
# Design: Freemium unlock via one-time in-app purchase
## Technical Approach
One cross-cutting `EstadoEntitlement` notifier (idiomatic `EstadoIdioma` shape) plus a top-level prefs-lazy reader for headless callers. Gating is hybrid: UI CTAs open the paywall, state-layer choke points hold the authoritative check. Ads are a port + AdMob adapter; the banner is a layout sibling (never an overlay), the interstitial fires on a CTA's natural transition behind a frequency cap.
## Architecture Decisions
### ADR-1: Entitlement is a notifier plus a free function, not a singleton
**Choice**: `lib/estado/estado_entitlement.dart` exports `EstadoEntitlement extends ChangeNotifier` (optional injected `SharedPreferences`, key `compra_premium_v1`, `bool get esPremium`) **and** a top-level `Future<bool> esPremiumPersistido({SharedPreferences? prefs})` that reads the same key directly.
**Alternatives**: global singleton; passing the notifier into `PluriWaveAudioHandler`.
**Rationale**: `PluriWaveAudioHandler` registers before `runApp`, so no `BuildContext`/`Provider` exists. The free function mirrors `FuenteMusicaLocalAutoImpl._resolverPrefs()` (`musica_local_auto.dart:163`) — same convention, testable via `setMockInitialValues`, no lifecycle to leak.
### ADR-2: Purchase I/O behind a port
**Choice**: `PuertoCompras` abstraction (`comprar`, `restaurar`, `Stream<EventoCompra>`) with `ServicioComprasPlayBilling` as the only `in_app_purchase` call site; `EstadoEntitlement` takes `PuertoCompras?`.
**Alternatives**: calling `InAppPurchase.instance` from the notifier.
**Rationale**: matches `EstadoAlarmas(android: PuertoAlarmasAndroid)`; keeps Strict TDD viable with zero plugin channels in unit tests.
**Fail-open**: only `purchased`/`restored` writes `true`. Errors, timeouts and offline never write `false`; the persisted flag is the source of truth at cold start.
### ADR-3: Gate placement (4 gates)
| Gate | Authoritative check | UI paywall entry |
|---|---|---|
| Alarm cap > 5 | `EstadoAlarmas.guardarAlarma` (`estado_alarmas.dart:104`) | `_EditorAlarmaSheet` save + the add CTA in `pantalla_alarmas.dart` |
| Alarm vacations | `EstadoAlarmas.crearRangoVacaciones` (`:510`) | `pantalla_vacaciones.dart``vacation-add-header` + `_CtaAnadirRango` |
| Recording | `EstadoGrabacion.iniciar` (`estado_grabacion.dart:90`) | 3 call sites in `pantalla_reproductor.dart` |
| Android Auto | `getChildren` / `playFromMediaId` / `playFromSearch` / `skipToNext-Previous` in `servicio_audio.dart` | none (car never shows a purchase flow) |
The phone equalizer is **not** gated.
### ADR-4: Auto reduced mode = real root labels, locked children, locked switching
**Choice**: `ConstructorArbolAuto.raiz({required bool incluirMusicaLocal, required bool premium})` keeps the same visible folder labels for free users; `getChildren` resolves entitlement once via `esPremiumPersistido()` and, when free, returns exactly `[itemPremiumBloqueado()]` (non-playable, id `premium:info`, hardcoded Spanish label like every other car label) for **any** non-root `parentMediaId`. Station switching is additionally blocked at `playFromMediaId`, `playFromSearch`, `skipToNext`/`skipToPrevious` (no-op returns).
**Alternatives**: empty root; omitting the folders entirely.
**Rationale**: head units cache browse trees, so a stale `emisora:<uuid>` tap would bypass `getChildren` — the play-path gates are mandatory, not belt-and-braces. Keeping labels + one explicit locked item guarantees no blank list. Play/pause/stop of the already-playing station are untouched.
### ADR-5: Distinct alarm-limit signal
**Choice**: `guardarAlarma` returns `ResultadoGuardarAlarma { guardada, limiteAlcanzado }`; `_error` stays reserved for native scheduling failures. Pure query `bool puedeCrearAlarma` (count = `_alarmas.length`, enabled or not; edits of an existing id always pass).
**Rationale**: overloading `_error` would surface a limit as a scheduling failure in `app.dart`'s snackbar path. Grandfathering falls out for free — nothing is deleted, only new creation past 5 is refused.
### ADR-6: Banner reserves layout; interstitial is cap-checked first
**Choice**: In `_PaginaPrincipalState.build`, `body:` becomes `Column[ SafeArea(bottom:false, child: BannerAnuncioSuperior), Expanded(existing SafeArea+AnimatedSwitcher) ]`. Premium or unloaded ⇒ `SizedBox.shrink()` (zero layout impact). Never a `Stack`/overlay.
**Interstitial ordering (add-alarm)**: `puedeCrearAlarma` → if false, show the limit message and **no ad**; if true, maybe-interstitial, then open the editor. Add-station: interstitial on the CTA tap, before `FormularioEmisoraPersonalizada` opens.
**Frequency cap**: in-memory in `ServicioAnuncios` — max 2 interstitials per process lifetime and ≥3 min apart; over cap ⇒ silent no-op.
**Rationale**: an ad followed by "you can't create this" is both hostile and an AdMob disruptive-ad policy risk.
## Data Flow
Play Billing ──→ PuertoCompras ──→ EstadoEntitlement ──→ prefs(compra_premium_v1)
│ │
UI (Provider.watch)┘ │
PluriWaveAudioHandler.getChildren ──→ esPremiumPersistido() ──────┘ (no Provider)
## File Changes
| File | Action | Description |
|---|---|---|
| `lib/estado/estado_entitlement.dart` | Create | Notifier + `esPremiumPersistido()` |
| `lib/servicios/servicio_compras.dart` | Create | `PuertoCompras` + Play Billing adapter |
| `lib/servicios/servicio_anuncios.dart` | Create | Banner/interstitial port + AdMob adapter + frequency cap |
| `lib/widgets/banner_anuncio_superior.dart` | Create | Entitlement-aware banner slot |
| `lib/widgets/hoja_premium.dart` | Create | Paywall sheet, reused by every gate |
| `lib/app.dart` | Modify | Provider registration + banner Column |
| `lib/estado/estado_alarmas.dart` | Modify | `puedeCrearAlarma`, `ResultadoGuardarAlarma`, vacation gate |
| `lib/estado/estado_grabacion.dart` | Modify | Recording gate in `iniciar` |
| `lib/servicios/navegacion_auto.dart` | Modify | `raiz(premium:)`, `itemPremiumBloqueado()` |
| `lib/servicios/servicio_audio.dart` | Modify | Entitlement gate in browse + play paths |
| `lib/pantallas/pantalla_ajustes.dart` | Modify | Purchase + restore rows |
| `lib/pantallas/pantalla_alarmas.dart`, `pantalla_vacaciones.dart`, `pantalla_reproductor.dart`, `pantalla_favoritos.dart`, `ajustes/pantalla_ajustes_emisoras_personalizadas.dart` | Modify | Contextual upsell / interstitial trigger |
| `pubspec.yaml` | Modify | Activate `in_app_purchase`, `google_mobile_ads` |
| `lib/l10n/app_*.arb` | Modify | Paywall, limit message, restore strings |
## Interfaces / Contracts
```dart
class EstadoEntitlement extends ChangeNotifier {
EstadoEntitlement({SharedPreferences? prefs, PuertoCompras? compras});
static const idProducto = 'pluriwave_premium';
bool get esPremium;
bool get compraEnCurso;
Future<void> comprar();
Future<void> restaurar();
}
Future<bool> esPremiumPersistido({SharedPreferences? prefs});
enum ResultadoGuardarAlarma { guardada, limiteAlcanzado }
```
## Testing Strategy
| Layer | What to Test | Approach |
|---|---|---|
| Unit | Entitlement persistence, fail-open on error, restore | Fake `PuertoCompras` + `setMockInitialValues` |
| Unit | `puedeCrearAlarma` at 4/5/6, edit-at-cap, vacations, recording | `EstadoAlarmas(prefs:)`/`EstadoGrabacion` directly |
| Unit | `raiz(premium:false)`, locked-child for every parent id, play-path no-ops | Pure `ConstructorArbolAuto` + handler fakes |
| Unit | Interstitial cap (2/session, 3 min) and cap-before-ad ordering | Fake clock in `ServicioAnuncios` |
| Widget | Banner absent when premium; no overlap on all 5 tabs | `pumpWidget(PluriWaveApp(prefs:))` + golden-free layout asserts |
| Widget | Limit message with secondary unlock action, paywall from each gate | Existing `pantalla_*_test.dart` conventions |
## Threat Matrix
N/A — no routing, shell, subprocess, VCS/PR automation, executable-file classification, or process-integration boundary. Android Auto media-id dispatch is pre-existing in-process routing, not shell/process execution.
## Migration / Rollout
No migration. Additive and prefs-backed; absent key = free. Revert by re-commenting both plugins and reverting the gate commits. Versioned key (`compra_premium_v1`) is ignored by older builds.
## Open Questions
- [ ] Price point (Play Console decision).
- [ ] AdMob ad unit IDs (banner + interstitial) not yet provisioned; test IDs until then.
- [x] ~~Should a cached head-unit tree be actively invalidated (`notifyChildrenChanged`) at purchase time, or is the next browse refresh enough?~~ **RESOLVED (orchestrator): actively invalidate.** On the entitlement transition to premium, call `notifyChildrenChanged` for the affected parent ids. Rationale: the same head-unit caching that forces the `playFromMediaId` guard in ADR-4 also means a purchaser would otherwise keep seeing the locked tree until the unit re-binds — plausibly the rest of the drive. A user who just paid and still sees "Premium feature" in the car reads that as a broken purchase, which is a refund and a one-star review. Relying on the next browse refresh trades a cheap, bounded call for a highly visible failure. The invalidation is one-directional and only fires on the free → premium transition; there is no premium → free transition to handle (the purchase is permanent and entitlement never writes `false`, per ADR-2).
@@ -0,0 +1,47 @@
# Exploration: iap-freemium-unlock
One-time non-consumable IAP that removes ads and unlocks 6 currently-free features. Free-tier users see ads (`google_mobile_ads`, commented out in pubspec.yaml, never activated). Purchasers get zero ads and full access forever from a single purchase (not a subscription).
## Current State
**State/persistence architecture.** `lib/app.dart` (`PluriWaveApp.build`) wires a `MultiProvider` at the app root: `ChangeNotifierProvider<EstadoRadio>`, three `ListenableProvider`s exposing `EstadoRadio`'s owned children (`EstadoEcualizador`, `EstadoGrabacion`, `EstadoBusqueda`), then independent siblings `ChangeNotifierProvider<EstadoAlarmas>`, `ChangeNotifierProvider<EstadoIdioma>`, `ChangeNotifierProvider<EstadoNavegacionRaiz>`. A single `SharedPreferences` instance is resolved once in `lib/main.dart` and injected as `prefs` into every top-level notifier.
Idiomatic per-domain notifier shape (cleanest example: `lib/estado/estado_idioma.dart`): `ChangeNotifier` subclass, optional injected `SharedPreferences?`, a `_resolverPrefs()` fallback to `SharedPreferences.getInstance()` (works from headless callers with no DI), a versioned key constant, `notifyListeners()` after every mutation+persist.
**No existing tier/limit/entitlement concept anywhere** — confirmed via grep across `lib/modelos/alarma_musical.dart`, `lib/estado/estado_alarmas.dart`, `lib/servicios/servicio_alarmas.dart`.
**pubspec.yaml** (version `1.3.0+151`): `google_mobile_ads` and `in_app_purchase` both commented out, lines ~52-56. Neither is an active dependency.
**Fastlane/CI**: `fastlane/Appfile``package_name` = `es.freetimelab.pluriwave`; `fastlane/Fastfile` has one lane (`upload_internal`) publishing to Play's `internal` track; `.gitea/workflows/build.yml` auto-bumps version and calls that lane. No in-app-product ID or billing config exists anywhere in CI/fastlane — that's Play Console-side config only, zero CI/fastlane code changes required for this change.
## Affected Areas (gating points per feature)
1. **Equalizer**`lib/estado/estado_ecualizador.dart`, screen `lib/pantallas/ajustes/pantalla_ajustes_ecualizador.dart`. UI entry: `lib/pantallas/pantalla_ajustes.dart` ~L108-123 (`FilaAjuste.onTap` → push `PantallaAjustesEcualizador`). Second surface: Android Auto's always-present `idEcualizador` folder + on/off custom action in `servicio_audio.dart`/`navegacion_auto.dart` — closed automatically once Android Auto itself is gated.
2. **Android Auto**`lib/servicios/navegacion_auto.dart`'s pure `ConstructorArbolAuto` feeds `lib/servicios/servicio_audio.dart:1667` `getChildren()``constructor.raiz(...)`, the single dispatch point for the whole car tree. `PluriWaveAudioHandler` is registered in `main.dart` before `runApp`, so any gate here must read entitlement via a prefs-lazy fallback, never `BuildContext`/`Provider`.
3. **Alarm vacations**`lib/pantallas/pantalla_vacaciones.dart` (2 create CTAs: header button `'vacation-add-header'`, mid-page `_CtaAnadirRango`), `lib/estado/estado_alarmas.dart` (`crearRangoVacaciones`/`editarRangoVacaciones`/`eliminarRangoVacaciones`/`guardarVacaciones` + 4 pure queries), `lib/servicios/servicio_alarmas.dart`. Entry from Alarms root: `lib/pantallas/pantalla_alarmas.dart`'s `_PanelVacaciones` (L93).
4. **Station recording**`lib/servicios/servicio_grabacion_radio.dart` (engine), `lib/estado/estado_grabacion.dart`'s `EstadoGrabacion.iniciar({Duration? duracion})` (L90) is the single choke point for ≥3 UI call sites (`pantalla_reproductor.dart`'s recording panel ~L489-560, duration-picker sheet ~L601-724, mini-player shortcut `'player-tool-record'` ~L1064). `pantalla_grabaciones.dart`/`pantalla_ajustes_grabaciones.dart` manage *existing* recordings and should probably stay accessible regardless of entitlement.
5. **Alarm count limit (new)**`EstadoAlarmas.guardarAlarma` (L104) is the one save call for create+edit; UI create/edit distinction lives in `_EditorAlarmaSheet` (`pantalla_alarmas.dart`, `widget.alarma == null` checks, save call ~L1189). Today's only failure channel is a `String? _error` used for native scheduling failures — a limit rejection needs a distinct signal, not reuse of `_error`.
6. **Ads** — zero ad code exists anywhere yet. Best candidates: (a) one global anchor in `lib/app.dart`'s `_PaginaPrincipalState.build` bottom `Column` (alongside `MiniReproductor`), covering all 5 tabs with one wiring point; (b) a `SliverToBoxAdapter` row in `PantallaInicio`'s `CustomScrollView` (mirrors `_seccionTusEmisoras`).
## Recommended entitlement architecture
New `lib/estado/estado_entitlement.dart` `ChangeNotifier`, shaped like `EstadoIdioma` (injected optional `SharedPreferences`, versioned key e.g. `compra_premium_v1`, `bool get esPremium`, prefs-lazy fallback for the Android Auto path), registered as an independent sibling `ChangeNotifierProvider` in `app.dart` (not owned by `EstadoRadio` — it's cross-cutting).
## Approaches considered
1. **UI-entry-point gating only** (6 call sites) — small, reviewable diffs, matches idiomatic pattern; risk of a missed call site on future refactors. Effort: Medium.
2. **State-method-layer gating only** — unbypassable, but silent no-op UX unless paired with UI copy anyway (not a real alternative to #1). Effort: Medium-High.
3. **Hybrid (recommended)** — UI entries show the paywall (good UX) + state-layer choke points (`guardarAlarma`, `EstadoGrabacion.iniciar`, Android Auto `getChildren`) carry the authoritative check. Effort: Medium.
## Risks
- Grandfathering: devices with 6+ alarms already before ship — candidate: grandfather existing, block only future creates once count ≥ 5 (needs design sign-off).
- Restore-purchases flow for reinstalls/new devices — no UI placement decided yet.
- Offline/failed entitlement checks — candidate: fail-open (trust last-persisted local flag) over fail-closed.
- No backend exists in this codebase — entitlement will be client/Play-Billing-trusted only, an accepted risk unless design decides otherwise.
- Android Auto's headless cold-start path requires the same "resolve prefs lazily, no DI at construction" convention already used by `FuenteMusicaLocalAutoImpl`.
- Alarm-count rule (all alarms vs. only active/enabled) is undecided and affects UX.
## Ready for Proposal
Yes.
@@ -0,0 +1,102 @@
# Proposal: Freemium unlock via one-time in-app purchase
## Intent
PluriWave (1.3.0+151, Internal Testing) has no monetization. Add one non-consumable purchase that permanently removes ads and unlocks the premium feature set, keeping the free tier usable. Purchasers get everything forever, restorable after reinstall, with no renewal or expiry concept.
## Scope
### In Scope
- `EstadoEntitlement` ChangeNotifier (SharedPreferences, versioned key, prefs-lazy resolve for headless Android Auto), top-level provider in `app.dart`.
- Activate `in_app_purchase`: buy flow, purchase stream, `restorePurchases()` from Settings.
- Activate `google_mobile_ads`: persistent top banner anchored in `app.dart` (must not overlap or displace existing content), plus a full-screen interstitial before two specific actions — adding a station manually and adding an alarm. All ads absent when premium.
- Gate 4 features: Android Auto reduced mode, alarm vacations, starting recordings, creating alarms past 5.
- Paywall reachable from every gated entry point (Settings row + contextual upsell at each gate); distinct "limit reached" signal from `EstadoAlarmas.guardarAlarma` (not the existing `_error`).
### Out of Scope
- Price point and Play Console product setup (console-side, undecided).
- Server-side receipt validation — no backend exists; client + Play Billing trust accepted for v1.
- Subscriptions, trials, promo codes, iOS store setup, CI/fastlane changes (none needed).
- Deleting, hiding, or trimming content free users already created.
- **The equalizer on the phone**: explicitly stays free for all users (user decision). Only its Android Auto surface is affected, as a consequence of Auto reduced mode.
## Business Rules
| Rule | Decision |
|------|----------|
| Purchase | Non-consumable, permanent, per Play account |
| Alarm cap | Free tier = 5 alarms total, enabled or not |
| Alarm cap UX | 6th attempt shows an explanatory message with a secondary "unlock" action — never a bare paywall jump |
| Grandfathering | Existing alarms/vacations/recordings survive; only new creation past the cap is blocked |
| Entitlement failure | Fail-open: trust last persisted flag; never lock out a payer offline |
| Equalizer (phone) | Free for everyone — not a gated feature |
| Android Auto (free) | Reduced mode: current-station player only. No station browsing/switching, no local music. Every other car entry shows a "Premium feature" item |
| Ads — banner | Persistent top banner, laid out so it never overlaps or covers existing UI |
| Ads — interstitial | Full-screen ad before adding a station manually and before adding an alarm |
| Ads lifecycle | Vanish immediately on purchase, no restart |
| Purchase entry points | Settings row + contextual upsell at each gated feature |
| Existing content | Viewing/managing stays free; only new gated actions are blocked |
## Capabilities
### New Capabilities
- `premium-entitlement`: purchase, restore, persistence, offline policy.
- `freemium-gating`: gated features, limits, and how a free user is informed.
- `ad-display`: ad placement and lifecycle for free users only.
### Modified Capabilities
- `android-auto-media`: browse tree becomes entitlement-aware — free tier collapses to a current-station-player-only tree.
## Approach
Hybrid gating (exploration approach 3): UI entry points show the paywall; state-layer choke points (`guardarAlarma`, `EstadoGrabacion.iniciar`, Auto `getChildren`) hold the authoritative check.
## Affected Areas
| Area | Impact | Description |
|------|--------|-------------|
| `lib/estado/estado_entitlement.dart` | New | Entitlement, purchase, restore |
| `lib/app.dart` | Modified | Provider registration, top banner anchor |
| `lib/estado/estado_alarmas.dart`, `estado_grabacion.dart` | Modified | Cap, vacation gate, recording gate |
| `lib/servicios/servicio_audio.dart`, `navegacion_auto.dart` | Modified | Gate car tree |
| `lib/pantallas/` (ajustes, vacaciones, alarmas, reproductor) | Modified | Paywall on gated CTAs |
| `pubspec.yaml` | Modified | Uncomment both plugins |
## Risks
| Risk | Likelihood | Mitigation |
|------|------------|------------|
| Client-only entitlement is tamperable | Med | Accepted for v1; no backend exists |
| Cap feels like data loss | Med | Grandfather all data; explain at creation time |
| Headless Auto has no Provider | Med | Prefs-lazy resolve, mirror `FuenteMusicaLocalAutoImpl` |
| Missed gate on a call site | Low | State-layer choke points as backstop |
| Interstitial before add-alarm/add-station reads as punitive, or trips AdMob's disruptive-ad policy | Med | Interstitial fires on the action's natural transition, never mid-task; enforce a frequency cap so repeated adds in one session don't chain ads; never stack it with the alarm-cap message in the same tap |
| Auto reduced mode leaves a free driver with an empty-looking car UI | Med | Current-station player always present; every locked branch renders an explicit "Premium feature" item, never a blank list |
## Rollback Plan
Additive and prefs-backed. Revert by re-commenting both plugins in `pubspec.yaml` and reverting the gate commits; no migration, no schema change. The persisted key is versioned (`compra_premium_v1`) so older builds ignore it.
## Dependencies
- Play Console in-app product created and priced; AdMob ad unit IDs.
## Success Criteria
- [x] Purchase unlocks every gated item with no restart and survives restart. Verified at the unit level: `EstadoEntitlement.comprar()`/`restaurar()` flip `esPremium` and `notifyListeners()` immediately on a `comprada`/`restaurada` event (no restart needed by construction — every gate reads `esPremium`/`esPremiumPersistido()` live), and the flag persists under `compra_premium_v1`. Full on-device Play Billing QA is still outstanding (deferred — no sandbox purchase available in this environment).
- [x] `restorePurchases()` restores entitlement on a fresh install. Verified: `estado_entitlement_test.dart` covers found/not-found restore outcomes.
- [x] Free tier blocks the 4 gated features and caps alarms at 5 without destroying data. Verified: `estado_alarmas_gating_test.dart` (cap + grandfathering), `estado_grabacion_gating_test.dart` (recording), `navegacion_auto_gating_test.dart`/`servicio_audio_gating_test.dart` (Android Auto).
- [x] Equalizer remains fully usable on the phone for free users. Verified: zero `esPremium`/`EstadoEntitlement`/`esPremiumPersistido` references anywhere in `estado_ecualizador.dart`, `servicio_ecualizador.dart`, `pantalla_ajustes_ecualizador.dart`, `ecualizador_widget.dart`.
- [x] Free-tier Android Auto still plays the current station and never shows a blank list. Verified: `respuestaBloqueadaPorEntitlement` never returns an empty list, `raiz(premium:)` keeps the root non-blank for every tier, and `debeBloquearCambioDeEmisora` only gates `playFromMediaId`/`playFromSearch`/`skipToNext`/`skipToPrevious``play`/`pause`/`stop` are untouched.
- [x] Zero ads (banner and interstitial) for purchasers; offline cold start keeps a purchaser unlocked. Verified: `ServicioAnuncios.debeMostrarBanner`/`intentarInterstitial` gate on `esPremium` first; offline cold start is `esPremiumPersistido`'s fail-open persisted-flag read.
- [x] Top banner never overlaps, covers, or displaces existing UI on any tab. Verified: `banner_anuncio_superior_test.dart` + `app.dart`'s `Column[banner, Expanded(body)]` (never a `Stack`).
Real-device/Play Console/AdMob QA (purchase flow, restore on a fresh install, car head-unit browse, live ad rendering) remains outstanding per the Work Unit runtime-harness notes in `tasks.md` — none of it is exercisable from this environment.
## Open Questions
1. Price point (Play Console decision; 2.994.99 EUR was a benchmark, never confirmed).
@@ -0,0 +1,330 @@
# Spec: iap-freemium-unlock
Combined view of all domain specs for this change. Authoritative per-domain files live under `openspec/changes/iap-freemium-unlock/specs/{domain}/spec.md`.
---
## Domain: premium-entitlement (NEW)
# Premium Entitlement Specification
## Purpose
Track whether the current user holds the permanent, non-consumable premium unlock, and expose that flag to every gated surface (freemium-gating, ad-display, android-auto-media) both from the UI layer and headlessly (Android Auto, registered before `runApp`).
## Requirements
### Requirement: One-Time Non-Consumable Purchase
The system MUST let the user buy a single non-consumable product via `in_app_purchase` from the Settings row or any contextual upsell. On a successful purchase, entitlement MUST flip to premium immediately, app-wide, with no restart required.
#### Scenario: Successful purchase
- GIVEN a free-tier user taps "buy premium" from Settings or a contextual upsell
- WHEN the purchase completes successfully
- THEN entitlement becomes premium immediately, without restarting the app
#### Scenario: Purchase cancelled or failed
- GIVEN a free-tier user starts the purchase flow
- WHEN the user cancels or the purchase fails
- THEN entitlement remains free tier, and no charge or partial state is left behind
#### Scenario: Already-purchased attempt is idempotent
- GIVEN a user already holds premium entitlement
- WHEN they somehow re-trigger the buy flow
- THEN no duplicate charge occurs and entitlement stays premium
### Requirement: Restore Purchases
Settings MUST expose a "restore purchases" action that re-queries Play Billing and unlocks entitlement when a prior purchase is found.
#### Scenario: Restore finds a prior purchase
- GIVEN a reinstall or new device with no local entitlement flag
- WHEN the user taps "restore purchases" and a valid purchase exists on the Play account
- THEN entitlement becomes premium
#### Scenario: Restore finds nothing
- GIVEN a user with no prior purchase
- WHEN they tap "restore purchases"
- THEN the user stays on the free tier with a clear, non-error-looking result (not a crash or ambiguous failure)
### Requirement: Persisted, Fail-Open Entitlement
Entitlement MUST persist locally under a versioned key (e.g. `compra_premium_v1`) and MUST be readable offline. If an entitlement check cannot complete (no network, Play Billing unreachable), the system MUST fail-open: trust the last persisted flag rather than lock out a payer.
(Previously: no entitlement concept existed.)
#### Scenario: Offline cold start after purchase
- GIVEN a user purchased premium previously
- WHEN they open the app fully offline
- THEN premium entitlement is honored from the persisted flag
#### Scenario: Failed check does not falsely grant premium
- GIVEN a free-tier user with no persisted premium flag
- WHEN an entitlement check fails
- THEN the user remains free tier (fail-open trusts the last flag, it does not invent one)
### Requirement: Headless-Safe Entitlement Read
Entitlement MUST be resolvable via a prefs-lazy fallback (no `BuildContext`/`Provider` dependency), for callers such as `PluriWaveAudioHandler` that register before the widget tree exists.
#### Scenario: Android Auto cold start
- GIVEN the audio handler is constructed before `runApp`
- WHEN it needs to know the current entitlement to build the browse tree
- THEN it resolves entitlement via the prefs-lazy path without requiring a `Provider`
### Requirement: Instant Unlock Propagation
A successful purchase or restore MUST notify all listeners (top banner, gated screens, cached Android Auto entitlement) immediately, without an app restart.
#### Scenario: Banner disappears immediately on purchase
- GIVEN the ad banner is visible when the user completes a purchase
- WHEN the purchase confirms
- THEN the banner disappears immediately, with no restart
---
## Domain: freemium-gating (NEW)
# Freemium Gating Specification
## Purpose
Define which features require premium entitlement, the free-tier alarm cap, grandfathering of existing content, and the non-punitive UX for hitting a limit. The equalizer on the phone is explicitly out of scope — it MUST stay free.
## Requirements
### Requirement: Gated Feature Set (Exactly 4)
The system MUST require premium entitlement for exactly: (1) creating alarm vacations, (2) starting a new station recording, (3) creating an alarm beyond the 5-alarm cap, and (4) full Android Auto browsing (see `android-auto-media`). The phone equalizer MUST NOT be gated under any circumstance.
#### Scenario: Free user uses the phone equalizer
- GIVEN a free-tier user
- WHEN they open and use the equalizer screen on the phone
- THEN it works fully, with no entitlement check and no upsell
#### Scenario: Free user attempts a gated action
- GIVEN a free-tier user
- WHEN they tap "add vacation range" or "start recording"
- THEN they see the paywall/upsell instead of the action completing
### Requirement: Alarm Count Cap At 5 (Free Tier)
`EstadoAlarmas.guardarAlarma` MUST count all alarms, enabled or not, and MUST reject creating a 6th alarm for a free-tier user via a distinct "limit reached" signal, separate from the existing `_error` field used for native scheduling failures.
#### Scenario: 6th alarm creation is blocked
- GIVEN a free-tier user already has 5 alarms (any enabled state)
- WHEN they attempt to create a 6th
- THEN `guardarAlarma` rejects it via the distinct limit signal, and no native scheduling is attempted
#### Scenario: Editing an existing alarm is unaffected
- GIVEN a free-tier user has exactly 5 alarms
- WHEN they edit one of those 5 (not create a new one)
- THEN the edit succeeds normally
#### Scenario: Premium user has no cap
- GIVEN a premium user
- WHEN they create a 6th or later alarm
- THEN it succeeds with no limit check
### Requirement: Alarm Cap UX Never Bare-Jumps To Paywall
Hitting the alarm cap MUST show an explanatory message with a secondary "unlock" action; it MUST NOT navigate directly to the paywall as the sole response to the attempt.
#### Scenario: Cap message with secondary action
- GIVEN a free-tier user hits the 5-alarm cap
- WHEN the limit signal is raised
- THEN the UI shows an explanatory message (e.g. "Has alcanzado el límite de 5 alarmas gratuitas") with a secondary button (e.g. "Desbloquear Premium")
- AND only tapping that secondary button navigates to the paywall
### Requirement: Grandfathering Of Existing Content
Alarms, vacations, and recordings created before the gate existed, or already exceeding the cap, MUST remain visible, usable, and editable-in-place. Only NEW creation past a limit or gate is blocked.
(Previously: no cap or gate existed, so this distinction did not apply.)
#### Scenario: Pre-existing alarms above the cap keep working
- GIVEN a device already has 7 alarms before this change ships
- WHEN the free-tier gate is active
- THEN all 7 alarms keep ringing and can be toggled/edited, and only a new 8th creation is blocked
### Requirement: Recording Start Gated, Management Stays Free
`EstadoGrabacion.iniciar` MUST require premium entitlement. Screens that view, play, or delete already-existing recordings MUST remain accessible regardless of entitlement.
#### Scenario: Free user starts a new recording
- GIVEN a free-tier user
- WHEN they tap the record action
- THEN they see the paywall instead of recording starting
#### Scenario: Free user manages existing recordings
- GIVEN a free-tier user with previously recorded files
- WHEN they open the recordings list
- THEN they can view, play, and delete those recordings normally
### Requirement: Purchase Entry Points At Every Gate Plus Settings
Every gated entry point MUST show a contextual upsell. Settings MUST additionally expose a persistent purchase/restore row.
#### Scenario: Contextual upsell at a gate
- GIVEN a free-tier user reaches any of the 4 gated entry points
- WHEN the gate blocks the action
- THEN a contextual purchase CTA is shown at that point
#### Scenario: Settings always shows a premium row
- GIVEN any user opens Settings
- WHEN the screen renders
- THEN it shows either a "buy premium" row (free tier) or a "premium active" state with restore access (premium tier)
---
## Domain: ad-display (NEW)
# Ad Display Specification
## Purpose
Define where and when `google_mobile_ads` renders for free-tier users only: a persistent top banner, plus a capped interstitial before two specific add actions. Ads MUST be entirely absent for premium users.
## Requirements
### Requirement: Persistent Top Banner, Never Overlapping Content
Free-tier users MUST see a persistent banner anchored at the TOP of the app (not bottom), laid out so it reserves its own space and never overlaps, covers, or displaces existing UI on any of the 5 tabs. Premium users MUST see no banner and no reserved space for it.
#### Scenario: Free user on any tab
- GIVEN a free-tier user
- WHEN they view any of the 5 tabs
- THEN the top banner is visible and all existing content remains fully visible and reachable, none hidden behind it
#### Scenario: Premium user
- GIVEN a premium user
- WHEN they view any tab
- THEN no banner and no reserved banner space is shown
### Requirement: Interstitial Before Manual Station Add And Before Alarm Add
For free-tier users, a full-screen interstitial MUST show before completing exactly two actions: adding a station manually, and adding an alarm. It MUST fire on the action's natural transition (e.g. on confirm/save), never mid-form, and MUST NOT show for premium users.
#### Scenario: Free user adds a station manually
- GIVEN a free-tier user completes the "add station manually" form
- WHEN they confirm the add
- THEN a full-screen interstitial shows once before/around that transition
#### Scenario: Free user adds an alarm
- GIVEN a free-tier user under the 5-alarm cap completes the alarm-creation form
- WHEN they save the new alarm
- THEN a full-screen interstitial shows once before/around that transition
#### Scenario: Premium user performs either action
- GIVEN a premium user
- WHEN they add a station manually or add an alarm
- THEN no interstitial shows
### Requirement: Interstitial Frequency Cap
The system MUST enforce a session-scoped frequency cap on interstitials so that repeated adds in one session do not chain interstitials back-to-back on every single attempt.
#### Scenario: Rapid consecutive adds in one session
- GIVEN a free-tier user adds several stations or alarms in quick succession within the same session
- WHEN each add completes
- THEN not every single add triggers a fresh interstitial — the frequency cap suppresses some per its configured spacing/count rule
### Requirement: Interstitial Never Stacks With The Alarm-Cap Message
If an alarm-add attempt would trigger both the interstitial and the 5-alarm-cap message in the same tap, the alarm-cap message MUST take precedence and the interstitial MUST be suppressed for that attempt.
#### Scenario: Cap hit and interstitial would-be trigger collide
- GIVEN a free-tier user already has 5 alarms
- WHEN they tap "add" for a 6th alarm
- THEN only the alarm-cap explanatory message appears, and no interstitial is shown for that same tap
### Requirement: Ads Vanish Immediately On Purchase
Both the top banner and interstitial triggers MUST stop immediately upon successful purchase or restore, with no app restart required.
#### Scenario: Mid-session purchase
- GIVEN a free-tier user with the banner visible completes a purchase
- WHEN the purchase confirms
- THEN the banner disappears immediately and subsequent adds trigger no interstitial, without restarting the app
---
## Domain: android-auto-media (MODIFIED)
# Delta for Android Auto Media
## MODIFIED Requirements
### Requirement: Browsable Media Tree
For a user holding premium entitlement, `getChildren` MUST return a browsable tree rooted at `AudioService.browsableRootId`, organized into non-playable folders (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, and the local-music root) containing playable items. Playable station items SHOULD carry an audio-quality subtitle when known. The `Favoritos` folder additionally MAY contain non-playable favorite-group sub-folders (see "Favorite Group Sub-Folders"); `Todas las emisoras` and `Mis emisoras` remain flat. The `Ecualizador` folder is flat, non-playable, and contains only the 6 fixed EQ preset items (see "EQ Preset Browsable Folder"). The local-music root folder is non-playable and may itself be nested (see "Local Music Browsable Tree"). For a free-tier (non-premium) user, this full tree is NOT exposed; see "Free-Tier Reduced Root Browse" for the entitlement-aware equivalent.
(Previously: root contained exactly 3 folders — Favoritos, Todas las emisoras, Mis emisoras — with no EQ or local-music folder; Favoritos was a flat folder of playable station items only, with no sub-folder nesting; there was no entitlement distinction.)
#### Scenario: Car requests the root (premium)
- GIVEN the user holds premium entitlement and the car head unit connects and requests the root (`AudioService.browsableRootId`)
- WHEN `getChildren` is called with the root id
- THEN it returns five folder `MediaItem`s (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, and the local-music root), each with `playable: false`
#### Scenario: Car requests a folder with no stations (premium)
- GIVEN the user holds premium entitlement and has zero favorite stations
- WHEN `getChildren` is called with the Favoritos folder id
- THEN it returns an empty list, not an error
#### Scenario: Browse requested before app state is loaded (premium)
- GIVEN the user holds premium entitlement and the audio handler starts cold and station/favorites Provider state has not finished loading
- WHEN `getChildren` is called (root or any folder)
- THEN it returns a valid, possibly empty, list without throwing and without blocking or crashing the service
#### Scenario: Station has known codec and bitrate
- GIVEN a station's `Emisora.codec` and `Emisora.bitrate` are both known (non-null)
- WHEN it is mapped to a playable `MediaItem`
- THEN `displaySubtitle` SHALL contain a human-readable quality hint combining bitrate and codec (e.g. "128 kbps · MP3")
#### Scenario: Station has unknown codec or bitrate
- GIVEN a station's `Emisora.codec` or `Emisora.bitrate` (or both) is null/unknown
- WHEN it is mapped to a playable `MediaItem`
- THEN `displaySubtitle` SHALL omit the quality hint gracefully (no subtitle, or a subtitle with no quality fragment)
- AND the subtitle MUST NOT render literal placeholder text such as "null kbps" or "null · null"
#### Scenario: Ungrouped station appears exactly as before (regression guard)
- GIVEN a station's `Emisora.grupoFavoritosId` equals `GrupoFavoritos.sinAsignarId` (`'sin_asignar'`, the default when no group is assigned), and the browsing user holds premium entitlement
- WHEN the `Favoritos`, `Todas las emisoras`, or `Mis emisoras` folders are browsed
- THEN that station appears as a playable `emisora:<uuid>` item in exactly the same folder(s), position (subject to existing sort rules), title, art, and subtitle as it did before favorite-group folders were introduced
- AND its presence and shape are unaffected by the existence, emptiness, or content of any favorite group
## ADDED Requirements
### Requirement: Free-Tier Reduced Root Browse
For a free-tier (non-premium) user, `getChildren` at the root MUST NOT return the full folder tree. Instead it MUST return a non-blank list whose items each represent one of the normally-browsable folders (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, local-music root) rendered as a non-playable, explicitly locked item labeled as a premium feature (e.g. title "Función Premium"). A blank or empty root/folder response for a free-tier user is forbidden.
#### Scenario: Free-tier user requests the root
- GIVEN a free-tier (non-premium) user's car head unit requests the root
- WHEN `getChildren` is called with the root id
- THEN it returns non-playable locked items labeled as premium features, one per normally-browsable folder, and never an empty list
#### Scenario: Free-tier user selects a locked item
- GIVEN a free-tier user is shown a locked "Función Premium" item
- WHEN they select it
- THEN no real folder content or station list is returned, and no crash or unhandled exception occurs
### Requirement: Free-Tier Browse Never Leaks Real Content (Authoritative Backstop)
Even if `getChildren` receives a stale or deep-linked folder id that would resolve to real station or local-music content, for a free-tier (non-premium) user it MUST NOT return that real content. This check MUST be enforced at the `getChildren`/`navegacion_auto.dart` choke point itself, independent of which UI path reached it.
#### Scenario: Stale folder id bypass attempt
- GIVEN a free-tier user's car client holds a cached `emisora:<uuid>` or folder id from before downgrade or from another device
- WHEN `getChildren`/`playFromMediaId` is called with that id
- THEN the authoritative entitlement check at the choke point blocks real content or playback from being returned, regardless of the id's validity
### Requirement: Current-Station Playback Unaffected By Free Tier
Regardless of entitlement, transport controls (play/pause/stop) for whatever station is already loaded or playing MUST keep working for a free-tier user in the car. Only browsing/switching to a different station and local music are restricted by the free tier.
#### Scenario: Free-tier user controls the current station
- GIVEN a free-tier user already has a station loaded or playing when connecting to the car
- WHEN they use play/pause/stop from the car head unit
- THEN the command is honored exactly as for a premium user
#### Scenario: Free-tier user cannot switch stations via browse
- GIVEN a free-tier user is currently playing a station
- WHEN they attempt to browse to a different station via the root tree
- THEN they see only the locked "Función Premium" items, not a station list, and cannot switch stations that way
@@ -0,0 +1,67 @@
# Ad Display Specification
## Purpose
Define where and when `google_mobile_ads` renders for free-tier users only: a persistent top banner, plus a capped interstitial before two specific add actions. Ads MUST be entirely absent for premium users.
## Requirements
### Requirement: Persistent Top Banner, Never Overlapping Content
Free-tier users MUST see a persistent banner anchored at the TOP of the app (not bottom), laid out so it reserves its own space and never overlaps, covers, or displaces existing UI on any of the 5 tabs. Premium users MUST see no banner and no reserved space for it.
#### Scenario: Free user on any tab
- GIVEN a free-tier user
- WHEN they view any of the 5 tabs
- THEN the top banner is visible and all existing content remains fully visible and reachable, none hidden behind it
#### Scenario: Premium user
- GIVEN a premium user
- WHEN they view any tab
- THEN no banner and no reserved banner space is shown
### Requirement: Interstitial Before Manual Station Add And Before Alarm Add
For free-tier users, a full-screen interstitial MUST show before completing exactly two actions: adding a station manually, and adding an alarm. It MUST fire on the action's natural transition (e.g. on confirm/save), never mid-form, and MUST NOT show for premium users.
#### Scenario: Free user adds a station manually
- GIVEN a free-tier user completes the "add station manually" form
- WHEN they confirm the add
- THEN a full-screen interstitial shows once before/around that transition
#### Scenario: Free user adds an alarm
- GIVEN a free-tier user under the 5-alarm cap completes the alarm-creation form
- WHEN they save the new alarm
- THEN a full-screen interstitial shows once before/around that transition
#### Scenario: Premium user performs either action
- GIVEN a premium user
- WHEN they add a station manually or add an alarm
- THEN no interstitial shows
### Requirement: Interstitial Frequency Cap
The system MUST enforce a session-scoped frequency cap on interstitials so that repeated adds in one session do not chain interstitials back-to-back on every single attempt.
#### Scenario: Rapid consecutive adds in one session
- GIVEN a free-tier user adds several stations or alarms in quick succession within the same session
- WHEN each add completes
- THEN not every single add triggers a fresh interstitial — the frequency cap suppresses some per its configured spacing/count rule
### Requirement: Interstitial Never Stacks With The Alarm-Cap Message
If an alarm-add attempt would trigger both the interstitial and the 5-alarm-cap message in the same tap, the alarm-cap message MUST take precedence and the interstitial MUST be suppressed for that attempt.
#### Scenario: Cap hit and interstitial would-be trigger collide
- GIVEN a free-tier user already has 5 alarms
- WHEN they tap "add" for a 6th alarm
- THEN only the alarm-cap explanatory message appears, and no interstitial is shown for that same tap
### Requirement: Ads Vanish Immediately On Purchase
Both the top banner and interstitial triggers MUST stop immediately upon successful purchase or restore, with no app restart required.
#### Scenario: Mid-session purchase
- GIVEN a free-tier user with the banner visible completes a purchase
- WHEN the purchase confirms
- THEN the banner disappears immediately and subsequent adds trigger no interstitial, without restarting the app
@@ -0,0 +1,79 @@
# Delta for Android Auto Media
## MODIFIED Requirements
### Requirement: Browsable Media Tree
For a user holding premium entitlement, `getChildren` MUST return a browsable tree rooted at `AudioService.browsableRootId`, organized into non-playable folders (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, and the local-music root) containing playable items. Playable station items SHOULD carry an audio-quality subtitle when known. The `Favoritos` folder additionally MAY contain non-playable favorite-group sub-folders (see "Favorite Group Sub-Folders"); `Todas las emisoras` and `Mis emisoras` remain flat. The `Ecualizador` folder is flat, non-playable, and contains only the 6 fixed EQ preset items (see "EQ Preset Browsable Folder"). The local-music root folder is non-playable and may itself be nested (see "Local Music Browsable Tree"). For a free-tier (non-premium) user, this full tree is NOT exposed; see "Free-Tier Reduced Root Browse" for the entitlement-aware equivalent.
(Previously: root contained exactly 3 folders — Favoritos, Todas las emisoras, Mis emisoras — with no EQ or local-music folder; Favoritos was a flat folder of playable station items only, with no sub-folder nesting; there was no entitlement distinction.)
#### Scenario: Car requests the root (premium)
- GIVEN the user holds premium entitlement and the car head unit connects and requests the root (`AudioService.browsableRootId`)
- WHEN `getChildren` is called with the root id
- THEN it returns five folder `MediaItem`s (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, and the local-music root), each with `playable: false`
#### Scenario: Car requests a folder with no stations (premium)
- GIVEN the user holds premium entitlement and has zero favorite stations
- WHEN `getChildren` is called with the Favoritos folder id
- THEN it returns an empty list, not an error
#### Scenario: Browse requested before app state is loaded (premium)
- GIVEN the user holds premium entitlement and the audio handler starts cold and station/favorites Provider state has not finished loading
- WHEN `getChildren` is called (root or any folder)
- THEN it returns a valid, possibly empty, list without throwing and without blocking or crashing the service
#### Scenario: Station has known codec and bitrate
- GIVEN a station's `Emisora.codec` and `Emisora.bitrate` are both known (non-null)
- WHEN it is mapped to a playable `MediaItem`
- THEN `displaySubtitle` SHALL contain a human-readable quality hint combining bitrate and codec (e.g. "128 kbps · MP3")
#### Scenario: Station has unknown codec or bitrate
- GIVEN a station's `Emisora.codec` or `Emisora.bitrate` (or both) is null/unknown
- WHEN it is mapped to a playable `MediaItem`
- THEN `displaySubtitle` SHALL omit the quality hint gracefully (no subtitle, or a subtitle with no quality fragment)
- AND the subtitle MUST NOT render literal placeholder text such as "null kbps" or "null · null"
#### Scenario: Ungrouped station appears exactly as before (regression guard)
- GIVEN a station's `Emisora.grupoFavoritosId` equals `GrupoFavoritos.sinAsignarId` (`'sin_asignar'`, the default when no group is assigned), and the browsing user holds premium entitlement
- WHEN the `Favoritos`, `Todas las emisoras`, or `Mis emisoras` folders are browsed
- THEN that station appears as a playable `emisora:<uuid>` item in exactly the same folder(s), position (subject to existing sort rules), title, art, and subtitle as it did before favorite-group folders were introduced
- AND its presence and shape are unaffected by the existence, emptiness, or content of any favorite group
## ADDED Requirements
### Requirement: Free-Tier Reduced Root Browse
For a free-tier (non-premium) user, `getChildren` at the root MUST NOT return the full folder tree. Instead it MUST return a non-blank list whose items each represent one of the normally-browsable folders (Favoritos, Todas las emisoras, Mis emisoras, Ecualizador, local-music root) rendered as a non-playable, explicitly locked item labeled as a premium feature (e.g. title "Función Premium"). A blank or empty root/folder response for a free-tier user is forbidden.
#### Scenario: Free-tier user requests the root
- GIVEN a free-tier (non-premium) user's car head unit requests the root
- WHEN `getChildren` is called with the root id
- THEN it returns non-playable locked items labeled as premium features, one per normally-browsable folder, and never an empty list
#### Scenario: Free-tier user selects a locked item
- GIVEN a free-tier user is shown a locked "Función Premium" item
- WHEN they select it
- THEN no real folder content or station list is returned, and no crash or unhandled exception occurs
### Requirement: Free-Tier Browse Never Leaks Real Content (Authoritative Backstop)
Even if `getChildren` receives a stale or deep-linked folder id that would resolve to real station or local-music content, for a free-tier (non-premium) user it MUST NOT return that real content. This check MUST be enforced at the `getChildren`/`navegacion_auto.dart` choke point itself, independent of which UI path reached it.
#### Scenario: Stale folder id bypass attempt
- GIVEN a free-tier user's car client holds a cached `emisora:<uuid>` or folder id from before downgrade or from another device
- WHEN `getChildren`/`playFromMediaId` is called with that id
- THEN the authoritative entitlement check at the choke point blocks real content or playback from being returned, regardless of the id's validity
### Requirement: Current-Station Playback Unaffected By Free Tier
Regardless of entitlement, transport controls (play/pause/stop) for whatever station is already loaded or playing MUST keep working for a free-tier user in the car. Only browsing/switching to a different station and local music are restricted by the free tier.
#### Scenario: Free-tier user controls the current station
- GIVEN a free-tier user already has a station loaded or playing when connecting to the car
- WHEN they use play/pause/stop from the car head unit
- THEN the command is honored exactly as for a premium user
#### Scenario: Free-tier user cannot switch stations via browse
- GIVEN a free-tier user is currently playing a station
- WHEN they attempt to browse to a different station via the root tree
- THEN they see only the locked "Función Premium" items, not a station list, and cannot switch stations that way
@@ -0,0 +1,88 @@
# Freemium Gating Specification
## Purpose
Define which features require premium entitlement, the free-tier alarm cap, grandfathering of existing content, and the non-punitive UX for hitting a limit. The equalizer on the phone is explicitly out of scope — it MUST stay free.
## Requirements
### Requirement: Gated Feature Set (Exactly 4)
The system MUST require premium entitlement for exactly: (1) creating alarm vacations, (2) starting a new station recording, (3) creating an alarm beyond the 5-alarm cap, and (4) full Android Auto browsing (see `android-auto-media`). The phone equalizer MUST NOT be gated under any circumstance.
#### Scenario: Free user uses the phone equalizer
- GIVEN a free-tier user
- WHEN they open and use the equalizer screen on the phone
- THEN it works fully, with no entitlement check and no upsell
#### Scenario: Free user attempts a gated action
- GIVEN a free-tier user
- WHEN they tap "add vacation range" or "start recording"
- THEN they see the paywall/upsell instead of the action completing
### Requirement: Alarm Count Cap At 5 (Free Tier)
`EstadoAlarmas.guardarAlarma` MUST count all alarms, enabled or not, and MUST reject creating a 6th alarm for a free-tier user via a distinct "limit reached" signal, separate from the existing `_error` field used for native scheduling failures.
#### Scenario: 6th alarm creation is blocked
- GIVEN a free-tier user already has 5 alarms (any enabled state)
- WHEN they attempt to create a 6th
- THEN `guardarAlarma` rejects it via the distinct limit signal, and no native scheduling is attempted
#### Scenario: Editing an existing alarm is unaffected
- GIVEN a free-tier user has exactly 5 alarms
- WHEN they edit one of those 5 (not create a new one)
- THEN the edit succeeds normally
#### Scenario: Premium user has no cap
- GIVEN a premium user
- WHEN they create a 6th or later alarm
- THEN it succeeds with no limit check
### Requirement: Alarm Cap UX Never Bare-Jumps To Paywall
Hitting the alarm cap MUST show an explanatory message with a secondary "unlock" action; it MUST NOT navigate directly to the paywall as the sole response to the attempt.
#### Scenario: Cap message with secondary action
- GIVEN a free-tier user hits the 5-alarm cap
- WHEN the limit signal is raised
- THEN the UI shows an explanatory message (e.g. "Has alcanzado el límite de 5 alarmas gratuitas") with a secondary button (e.g. "Desbloquear Premium")
- AND only tapping that secondary button navigates to the paywall
### Requirement: Grandfathering Of Existing Content
Alarms, vacations, and recordings created before the gate existed, or already exceeding the cap, MUST remain visible, usable, and editable-in-place. Only NEW creation past a limit or gate is blocked.
(Previously: no cap or gate existed, so this distinction did not apply.)
#### Scenario: Pre-existing alarms above the cap keep working
- GIVEN a device already has 7 alarms before this change ships
- WHEN the free-tier gate is active
- THEN all 7 alarms keep ringing and can be toggled/edited, and only a new 8th creation is blocked
### Requirement: Recording Start Gated, Management Stays Free
`EstadoGrabacion.iniciar` MUST require premium entitlement. Screens that view, play, or delete already-existing recordings MUST remain accessible regardless of entitlement.
#### Scenario: Free user starts a new recording
- GIVEN a free-tier user
- WHEN they tap the record action
- THEN they see the paywall instead of recording starting
#### Scenario: Free user manages existing recordings
- GIVEN a free-tier user with previously recorded files
- WHEN they open the recordings list
- THEN they can view, play, and delete those recordings normally
### Requirement: Purchase Entry Points At Every Gate Plus Settings
Every gated entry point MUST show a contextual upsell. Settings MUST additionally expose a persistent purchase/restore row.
#### Scenario: Contextual upsell at a gate
- GIVEN a free-tier user reaches any of the 4 gated entry points
- WHEN the gate blocks the action
- THEN a contextual purchase CTA is shown at that point
#### Scenario: Settings always shows a premium row
- GIVEN any user opens Settings
- WHEN the screen renders
- THEN it shows either a "buy premium" row (free tier) or a "premium active" state with restore access (premium tier)
@@ -0,0 +1,73 @@
# Premium Entitlement Specification
## Purpose
Track whether the current user holds the permanent, non-consumable premium unlock, and expose that flag to every gated surface (freemium-gating, ad-display, android-auto-media) both from the UI layer and headlessly (Android Auto, registered before `runApp`).
## Requirements
### Requirement: One-Time Non-Consumable Purchase
The system MUST let the user buy a single non-consumable product via `in_app_purchase` from the Settings row or any contextual upsell. On a successful purchase, entitlement MUST flip to premium immediately, app-wide, with no restart required.
#### Scenario: Successful purchase
- GIVEN a free-tier user taps "buy premium" from Settings or a contextual upsell
- WHEN the purchase completes successfully
- THEN entitlement becomes premium immediately, without restarting the app
#### Scenario: Purchase cancelled or failed
- GIVEN a free-tier user starts the purchase flow
- WHEN the user cancels or the purchase fails
- THEN entitlement remains free tier, and no charge or partial state is left behind
#### Scenario: Already-purchased attempt is idempotent
- GIVEN a user already holds premium entitlement
- WHEN they somehow re-trigger the buy flow
- THEN no duplicate charge occurs and entitlement stays premium
### Requirement: Restore Purchases
Settings MUST expose a "restore purchases" action that re-queries Play Billing and unlocks entitlement when a prior purchase is found.
#### Scenario: Restore finds a prior purchase
- GIVEN a reinstall or new device with no local entitlement flag
- WHEN the user taps "restore purchases" and a valid purchase exists on the Play account
- THEN entitlement becomes premium
#### Scenario: Restore finds nothing
- GIVEN a user with no prior purchase
- WHEN they tap "restore purchases"
- THEN the user stays on the free tier with a clear, non-error-looking result (not a crash or ambiguous failure)
### Requirement: Persisted, Fail-Open Entitlement
Entitlement MUST persist locally under a versioned key (e.g. `compra_premium_v1`) and MUST be readable offline. If an entitlement check cannot complete (no network, Play Billing unreachable), the system MUST fail-open: trust the last persisted flag rather than lock out a payer.
(Previously: no entitlement concept existed.)
#### Scenario: Offline cold start after purchase
- GIVEN a user purchased premium previously
- WHEN they open the app fully offline
- THEN premium entitlement is honored from the persisted flag
#### Scenario: Failed check does not falsely grant premium
- GIVEN a free-tier user with no persisted premium flag
- WHEN an entitlement check fails
- THEN the user remains free tier (fail-open trusts the last flag, it does not invent one)
### Requirement: Headless-Safe Entitlement Read
Entitlement MUST be resolvable via a prefs-lazy fallback (no `BuildContext`/`Provider` dependency), for callers such as `PluriWaveAudioHandler` that register before the widget tree exists.
#### Scenario: Android Auto cold start
- GIVEN the audio handler is constructed before `runApp`
- WHEN it needs to know the current entitlement to build the browse tree
- THEN it resolves entitlement via the prefs-lazy path without requiring a `Provider`
### Requirement: Instant Unlock Propagation
A successful purchase or restore MUST notify all listeners (top banner, gated screens, cached Android Auto entitlement) immediately, without an app restart.
#### Scenario: Banner disappears immediately on purchase
- GIVEN the ad banner is visible when the user completes a purchase
- WHEN the purchase confirms
- THEN the banner disappears immediately, with no restart
@@ -0,0 +1,80 @@
# Tasks: Freemium unlock via one-time in-app purchase
## Review Workload Forecast
Estimated changed lines: 1200-2000+ (5 new, ~12 modified Dart, 13 `.arb` locales, pubspec.yaml, AndroidManifest.xml, plus tests).
Suggested split: single PR now (`single-pr`); Work Units below double as chained-PR slices if `size:exception` is declined.
Delivery strategy: single-pr.
Decision needed before apply: Yes
Chained PRs recommended: Yes
Chain strategy: size-exception
400-line budget risk: High
Deferred, non-blocking: price point (Play Console); AdMob ad unit IDs — use Google test IDs. Do not invent values.
### Suggested Work Units
| Unit | Goal | Focused test command | Runtime harness | Rollback boundary |
|---|---|---|---|---|
| 1 | Entitlement + purchase I/O | `flutter test test/estado/estado_entitlement_test.dart test/servicios/servicio_compras_test.dart` | Manual: Settings > Restaurar compras | `estado_entitlement.dart`, `servicio_compras.dart` |
| 2 | Alarm, recording, Auto gates + cache invalidation | `flutter test test/estado/estado_alarmas_test.dart test/estado/estado_grabacion_test.dart test/servicios/navegacion_auto_test.dart test/servicios/servicio_audio_test.dart` | Auto head-unit browse smoke | gate diffs in `estado_alarmas.dart`, `estado_grabacion.dart`, `navegacion_auto.dart`, `servicio_audio.dart` |
| 3 | Ads (banner + interstitial) | `flutter test test/servicios/servicio_anuncios_test.dart test/widgets/banner_anuncio_superior_test.dart` | Manual: banner/no-overlap 5 tabs | `servicio_anuncios.dart`, `banner_anuncio_superior.dart`, `app.dart` Column diff |
| 4 | Paywall UI + localization | `flutter test test/pantallas/pantalla_ajustes_test.dart && flutter gen-l10n` | Manual: tap each gate | `hoja_premium.dart`, screen CTA diffs, `app_*.arb` keys |
## Phase 0: Foundation
- [x] 0.1 Uncomment `in_app_purchase`/`google_mobile_ads` in `pubspec.yaml`; `flutter pub get`.
- [x] 0.2 Add AdMob test app ID to `AndroidManifest.xml`.
## Phase 1: Entitlement Core
- [x] 1.1 RED `estado_entitlement_test.dart`: default free; persisted true; fail-open on failure; `esPremiumPersistido()` headless, no `BuildContext`.
- [x] 1.2 GREEN `estado_entitlement.dart`: `EstadoEntitlement` `ChangeNotifier` (key `compra_premium_v1`) + `esPremiumPersistido()`.
- [x] 1.3 REFACTOR: shared prefs-key constant; document fail-open contract.
## Phase 2: Purchase I/O
- [x] 2.1 RED `servicio_compras_test.dart`: `comprar()` success/cancel/idempotent; `restaurar()` found/not-found, no error.
- [x] 2.2 GREEN `servicio_compras.dart`: `PuertoCompras` + `ServicioComprasPlayBilling` (sole `in_app_purchase` site); wire `comprar/restaurar`.
## Phase 3: Alarm Gating
- [x] 3.1 RED `estado_alarmas_gating_test.dart`: `puedeCrearAlarma` 4/5/6; 6th blocked pre-schedule; edit-at-cap ok; premium uncapped; 8 preexisting grandfathered, 9th blocked; vacations free-blocked/premium-ok.
- [x] 3.2 GREEN `estado_alarmas.dart`: `ResultadoGuardarAlarma` enum, `puedeCrearAlarma`, gate `guardarAlarma`(:104)+`crearRangoVacaciones`(:510).
- [x] 3.3 GREEN `pantalla_alarmas.dart`/`_EditorAlarmaSheet` + `pantalla_vacaciones.dart`: cap message + "Desbloquear Premium" CTA; vacation upsell.
## Phase 4: Recording Gating
- [x] 4.1 RED `estado_grabacion_gating_test.dart`: `iniciar()` blocked free/allowed premium; existing recordings stay free.
- [x] 4.2 GREEN `estado_grabacion.dart`: gate `iniciar()`(:90); upsell at 3 sites in `pantalla_reproductor.dart`.
## Phase 5: Android Auto Gating
- [x] 5.1 RED `navegacion_auto_gating_test.dart`: `raiz(premium:false)` non-blank tree with the real folder labels (design ADR-4: root labels stay visible for every tier, lock enforced one level down); `respuestaBloqueadaPorEntitlement(non-root,free)->[itemPremiumBloqueado()]`; premium unchanged (regression).
- [x] 5.2 RED `servicio_audio_gating_test.dart`: `debeBloquearCambioDeEmisora` free/premium; stale-id backstop wired into `playFromMediaId`/`playFromSearch`/`skipToNext`/`skipToPrevious`.
- [x] 5.3 RED: free->premium transition invokes the registered Auto-invalidation hook (`registrarNotificacionDesbloqueoAuto`/`notificarDesbloqueoAuto`), which pushes to `PluriWaveAudioHandler.subscribeToChildren`'s per-id `BehaviorSubject`s (the current non-deprecated `audio_service` API — the plugin's OWN internal listener forwards each push to the platform's `notifyChildrenChanged`).
- [x] 5.4 GREEN: `raiz(premium:)`+`itemPremiumBloqueado()`+`respuestaBloqueadaPorEntitlement` (`navegacion_auto.dart`); gate `getChildren`/`playFromMediaId`/`playFromSearch`/`skipToNext`/`skipToPrevious` + `subscribeToChildren`/`notificarHijosCambiaron` wiring (`servicio_audio.dart`).
## Phase 6: Ads
- [x] 6.1 RED `servicio_anuncios_test.dart`: cap 2/session >=3min (fake clock); over-cap no-op; suppressed with alarm-cap message; none when premium.
- [x] 6.2 GREEN `servicio_anuncios.dart`: banner/interstitial port + AdMob adapter (test ad unit IDs) + frequency cap.
- [x] 6.3 RED+GREEN `banner_anuncio_superior.dart` + `app.dart`: shrink when premium/unloaded, no overlap 5 tabs; `Column[banner, Expanded(body)]`, never `Stack`.
## Phase 7: Purchase UI Wiring
- [x] 7.1 GREEN `hoja_premium.dart` (paywall sheet) + `app.dart`: register `EstadoEntitlement` Provider.
- [x] 7.2 GREEN `pantalla_ajustes.dart`: buy/restore/premium-active row; `pantalla_favoritos.dart` + `ajustes_emisoras_personalizadas.dart`: interstitial before manual station add.
## Phase 8: Localization (13 locales, `app_es.arb` template)
- [x] 8.1 Add keys (`funcionPremium`, `limiteAlarmasAlcanzado`, `desbloquearPremium`, `restaurarCompras`) to `app_es.arb`; translate into 12 remaining locales.
- [x] 8.2 Run `flutter gen-l10n`; verify `AppLocalizations` getters generated.
- [x] 8.3 Run literal-encoding scan on `lib/l10n/app_*.arb` — zero mojibake (only pre-existing "REPETIÇÃO" false positive, unrelated to this change).
## Phase 9: Verification
- [x] 9.1 Run full suite; confirm every RED test above is GREEN.
- [x] 9.2 Regression-check: phone equalizer has zero entitlement checks.
- [x] 9.3 Update `proposal.md` Success Criteria checkboxes.
@@ -0,0 +1,292 @@
```yaml
schema: gentle-ai.verify-result/v1
evidence_revision: sha256:2c382e1b0ea0ead93ebb25ce741be99bc6005c20
verdict: fail
blockers: 2
critical_findings: 2
requirements: 20/20
scenarios: 39/39
test_command: flutter test
test_exit_code: 1
test_output_hash: sha256:3b2a1fcdb1436e77a8a883923ebeb01f7ebc675602162c38c1ca2b42a5acb0c1
build_command: flutter analyze
build_exit_code: 1
build_output_hash: sha256:cb2b64838a0c89a135b8a1b9bda36f57e6060c244129554060b00f6a7f5bcbd6
```
## Verification Report
Change: iap-freemium-unlock
Branch/Commit: feat/iap-freemium-unlock, single commit 2c382e1
Version: N/A (no versioned spec revisions)
Mode: Strict TDD
### Completeness
| Metric | Value |
|--------|-------|
| Tasks total | 27 |
| Tasks complete (checked) | 26 |
| Tasks incomplete (unchecked in tasks.md) | 1 (task 3.3) |
Discrepancy: openspec/changes/iap-freemium-unlock/tasks.md line 45 shows task 3.3
(GREEN pantalla_alarmas.dart/_EditorAlarmaSheet + pantalla_vacaciones.dart: cap message
plus Desbloquear Premium CTA; vacation upsell) as an unchecked box, despite
apply-progress.md's own summary table and both Engram apply-progress observations
(#2834, #2835) explicitly claiming ALL PHASES COMPLETE (27/27 tasks) and Phase 3 marked
complete for 3.1, 3.2 and 3.3. Source inspection confirms the underlying code for 3.3 IS
implemented and covered by regression tests (pantalla_alarmas.dart's _abrirEditor
cap-check-plus-interstitial wiring, _mostrarLimiteAlarmas snackbar and CTA, and
pantalla_vacaciones.dart's paywall-on-block via mostrarHojaPremium) -- this is a
tracking and documentation integrity failure, not a missing implementation. Per the
verify decision gate (an unchecked task always remains CRITICAL, even when other
artifacts are missing or warnings-only), this blocks a clean archive regardless of the
underlying code being present.
### Build and Tests Execution
Static analysis: flutter analyze -> exit 1, 5 issues (all confirmed pre-existing and
unrelated via git blame: 2x deprecated_member_use on onReorder in pantalla_favoritos.dart
and its test, predating this change; 1x unused_catch_stack in servicio_audio.dart:1310,
blamed to commit 0e18c822 dated 2026-05-21, predating this change; 1x annotate_overrides
in estado_radio_test.dart:865). Matches the apply-progress claim exactly. flutter analyze
exits 1 whenever any issue including info level is present -- this is expected repository
baseline behavior, not a regression.
Tests: FAILING -- 1242 passed / 2 skipped / 1 FAILED (1245 total), full flutter test run
completed in about 2 minutes 34 seconds (contrary to apply-progress's claim that a single
flutter test full-suite invocation exceeds this environment's command timeout of about 10
minutes -- it did not, in this run).
```text
$ flutter test
...
02:34 +1242 ~2 -1: Some tests failed.
Failing tests:
C:/Proyectos/pluriwave/test/l10n/arb_anti_copy_test.dart: every non-es value identical to
the Spanish template is a deliberately allowlisted exception, not an accidental untranslated
copy [E]
Expected: empty
Actual: [
pt/desbloquearPremium = "Desbloquear Premium",
pt/restaurarCompras = "Restaurar compras"
]
Found values identical to the Spanish template that are NOT in
identical_value_allowlist.dart -- this is very likely an untranslated copy-paste...
```
This directly contradicts the apply-progress claim of full suite green (719+ tests) and
all phases green. The failure is a genuine, reproducible regression against a pre-existing
guard test (test/l10n/arb_anti_copy_test.dart, not one of this change's own new test files),
caused by this change's own new content: 2 of the 4 new localization keys
(desbloquearPremium, restaurarCompras) were left byte-identical to the Spanish template for
the pt locale and were never added to identical_value_allowlist.dart nor genuinely
translated. The apply-progress literal-encoding scan and dart format checks would never
have caught this -- only arb_anti_copy_test.dart catches it, and it was never run: the
apply-progress's own batched regression run explicitly lists test/estado/, test/servicios/,
test/widgets/, test/pantallas/, and 4 top-level files -- test/l10n/ is absent from every
batch, so this defect went undetected until this verify pass ran the real full suite.
Coverage: not measured (no --coverage run performed; not requested by the phase gates and
project rules prohibit flutter build, and coverage instrumentation was judged non-essential
given the full-suite pass/fail evidence already gathered).
### Spec Compliance Matrix (by requirement; 20 requirements / 39 scenarios across 4 domains)
| Domain | Requirement | Covering test(s) | Result |
|---|---|---|---|
| premium-entitlement | One-Time Non-Consumable Purchase | estado_entitlement_test.dart (comprar success/cancel/idempotent) | COMPLIANT |
| premium-entitlement | Restore Purchases | estado_entitlement_test.dart (restaurar found/not-found) | COMPLIANT |
| premium-entitlement | Persisted, Fail-Open Entitlement | estado_entitlement_test.dart (loads persisted flag; error does not block payer) | COMPLIANT |
| premium-entitlement | Headless-Safe Entitlement Read | estado_entitlement_test.dart (esPremiumPersistido group, no BuildContext) | COMPLIANT |
| premium-entitlement | Instant Unlock Propagation | estado_entitlement_test.dart (ChangeNotifier notification count) plus servicio_audio_gating_test.dart (Auto invalidation hook) | COMPLIANT |
| freemium-gating | Gated Feature Set (exactly 4) | equalizer-zero-refs grep plus alarm/recording/vacation/Auto gating tests | COMPLIANT |
| freemium-gating | Alarm Count Cap At 5 | estado_alarmas_gating_test.dart (4/5/6, pre-schedule block, edit-at-cap, premium uncapped) | COMPLIANT |
| freemium-gating | Alarm Cap UX Never Bare-Jumps To Paywall | pantalla_alarmas.dart _mostrarLimiteAlarmas (source-verified; snackbar plus CTA, no direct nav) | COMPLIANT (source; no dedicated widget test asserts the exact snackbar text/CTA pair) |
| freemium-gating | Grandfathering Of Existing Content | estado_alarmas_gating_test.dart (8 preexisting alarms stay, only the 9th is blocked) | COMPLIANT |
| freemium-gating | Recording Start Gated, Management Stays Free | estado_grabacion_gating_test.dart (free blocked, premium allowed, compat default) | COMPLIANT |
| freemium-gating | Purchase Entry Points At Every Gate Plus Settings | source-verified across pantalla_alarmas.dart, pantalla_vacaciones.dart, pantalla_reproductor.dart, pantalla_ajustes.dart | COMPLIANT |
| ad-display | Persistent Top Banner, Never Overlapping Content | banner_anuncio_superior_test.dart (Column layout, zero-footprint collapse) | COMPLIANT |
| ad-display | Interstitial Before Manual Station Add And Before Alarm Add | source-verified (pantalla_alarmas.dart _abrirEditor, pantalla_favoritos.dart, ajustes_emisoras_personalizadas.dart) plus servicio_anuncios_test.dart cap logic | COMPLIANT |
| ad-display | Interstitial Frequency Cap | servicio_anuncios_test.dart (2 per session, 3-minute spacing, failed load does not consume cap) | COMPLIANT |
| ad-display | Interstitial Never Stacks With The Alarm-Cap Message | source-verified: _abrirEditor returns early on cap-block, before intentarInterstitial is ever called | COMPLIANT |
| ad-display | Ads Vanish Immediately On Purchase | servicio_anuncios_test.dart (premium never shows) plus banner_anuncio_superior_test.dart (premium never attempts) | COMPLIANT |
| android-auto-media | Browsable Media Tree (premium, regression) | navegacion_auto_gating_test.dart (premium identical to current tree) plus navegacion_auto_test.dart (updated call sites, premium true) | COMPLIANT |
| android-auto-media | Free-Tier Reduced Root Browse | navegacion_auto_gating_test.dart (free: same labels, non-blank, never playable; itemPremiumBloqueado non-crash) | COMPLIANT |
| android-auto-media | Free-Tier Browse Never Leaks Real Content (Authoritative Backstop) | navegacion_auto_gating_test.dart (stale/deep-linked id backstop) plus servicio_audio_gating_test.dart (debeBloquearCambioDeEmisora) plus source-verified in all 5 servicio_audio.dart call sites | COMPLIANT |
| android-auto-media | Current-Station Playback Unaffected By Free Tier | source-verified: play(), pause(), stop() in servicio_audio.dart contain no entitlement check | COMPLIANT |
Compliance summary: 20/20 requirements have runtime or source-verified covering evidence.
One requirement (Alarm Cap UX) is source-verified but lacks a dedicated widget test asserting
the exact snackbar/CTA pair -- downgraded to a WARNING below, not a blocker, since the logic
path is simple and exercised transitively by the passing regression suite.
### Orchestrator-Flagged Scrutiny Points
1. Fail-open entitlement default ("() => true" in estado_alarmas.dart:36,
estado_grabacion.dart:57) -- VERIFIED: exactly 2 production construction sites exist for
these classes (app.dart lines 71-76, EstadoRadio(esPremium: () =>
context.read<EstadoEntitlement>().esPremium), threaded internally to EstadoGrabacion at
estado_radio.dart:73; app.dart lines 93-96, EstadoAlarmas(esPremium: ...)), both correctly
wired, with EstadoEntitlement registered FIRST in the provider list specifically so these
context.read calls resolve. The headless Android Auto path (servicio_audio.dart) never
constructs EstadoAlarmas/EstadoGrabacion at all -- it calls esPremiumPersistido() directly,
a separate, unaffected function. No current production or headless path reaches the
fail-open default. See WARNING below for the latent-risk recommendation.
2. Android Auto gating completeness (ADR-4) -- VERIFIED COMPLIANT: playFromMediaId,
playFromSearch, skipToNext, skipToPrevious all call
debeBloquearCambioDeEmisora(premium: await esPremiumPersistido()) and no-op when blocked
(servicio_audio.dart lines approximately 1601, 1626, 1863, 1896). play(), pause(), stop()
contain no such check -- transport of the current station is untouched. getChildren never
returns blank for free tier: respuestaBloqueadaPorEntitlement returns exactly one
itemPremiumBloqueado() item for any non-root id, and the root itself always resolves
through raiz() (never blocked).
3. notifyChildrenChanged replacement -- VERIFIED FUNCTIONALLY EQUIVALENT: the deprecated
static helper is replaced by PluriWaveAudioHandler.subscribeToChildren (a per-parent-id
BehaviorSubject overriding the audio_service base class's stream-based extension point)
plus notificarHijosCambiaron(id), which pushes a fresh value into that subject.
EstadoEntitlement._desbloquear() calls notificarDesbloqueoAuto() on the free-to-premium
edge (only when the user was not already premium), which fires the hook registered in
registrarHandler() that pushes to the root plus all 4 folder ids. This is audio_service's
own documented replacement mechanism for the deprecated helper (the plugin's internal
listener subscribes to subscribeToChildren and forwards to the platform's
notifyChildrenChanged itself) -- not a workaround. Covered by
servicio_audio_gating_test.dart's registrarNotificacionDesbloqueoAuto group.
4. Deviation #5, crearRangoVacaciones returns bool -- VERIFIED ACCEPTABLE: the method has
exactly one failure mode today (entitlement block returns false); there is no other
throw/failure path in its body, so a caller cannot currently confuse "blocked by
entitlement" with any other failure. pantalla_vacaciones.dart's _guardar checks
"if (!creada) mostrarHojaPremium(context)", correctly routing to the paywall. This is a
sound simplification given the current single-failure-mode reality, though it is not
future-proof if crearRangoVacaciones ever grows a second failure mode (see SUGGESTION
below).
5. Interstitial ordering (cap-check before interstitial) -- VERIFIED COMPLIANT:
pantalla_alarmas.dart's _abrirEditor checks estado.puedeCrearAlarma() FIRST; on false it
calls _mostrarLimiteAlarmas(context) and returns immediately --
ServicioAnuncios.intentarInterstitial() is only reached on the true branch. A free user at
the 5-alarm cap can never see an interstitial followed by a refusal.
6. Equalizer NOT gated -- VERIFIED COMPLIANT: zero matches for
esPremium, EstadoEntitlement, esPremiumPersistido or ServicioAnuncios across
estado_ecualizador.dart, servicio_ecualizador.dart, pantalla_ajustes_ecualizador.dart and
ecualizador_widget.dart.
7. Encoding scan -- VERIFIED CLEAN across all 13 app_*.arb files for the mojibake pattern
(A-tilde, A-circumflex, a-euro-etc sequences): only the pre-existing, unrelated
app_pt.arb "REPETICAO" false positive. The 4 new keys are byte-clean in every locale.
Note: this scan does NOT catch the untranslated-copy defect found above -- that is a
semantic/content problem, not a mojibake/encoding problem, and is caught by a different
test, arb_anti_copy_test.dart.
8. Test-harness fixes -- VERIFIED LEGITIMATE: diffed all 9 modified harness files against the
commit. Every change is a strictly additive provider registration
(ChangeNotifierProvider<EstadoEntitlement> and/or Provider<ServicioAnuncios> added to each
test's widget tree) required because the new gated call sites now read those providers via
context.read/context.watch. Zero existing assertions were removed, weakened, or altered in
any of the 9 files (navegacion_auto_test.dart's 3 raiz() call sites gained a
"premium: true" argument, not a removed assertion).
### TDD Compliance
| Check | Result | Details |
|-------|--------|---------|
| TDD Evidence reported | Yes | Full RED/GREEN/REFACTOR table present in apply-progress.md |
| All tasks have tests | Yes | 8 new test files map to every pure-logic phase |
| RED confirmed (tests exist) | Yes | All 8 new test files verified present on disk with real assertions |
| GREEN confirmed (tests pass) | Partial | 7/8 new test files pass fully; none of the 8 NEW files is the failing one (arb_anti_copy_test.dart is pre-existing) |
| Triangulation adequate | Yes | Every gated behavior has 3 or more cases (free/premium/edge -- cap boundary, idempotency, stale-id backstop) |
| Safety Net for modified files | Yes | estado_alarmas.dart, estado_grabacion.dart, navegacion_auto.dart, servicio_audio.dart all have pre-existing regression suites re-run and green |
TDD Compliance: 6/6 checks passed (the one Partial is about the pre-existing, unrelated
l10n regression, not this change's own new tests).
### Test Layer Distribution
| Layer | Tests | Files | Tools |
|-------|-------|-------|-------|
| Unit (pure logic) | approx 40 | estado_entitlement_test.dart, estado_alarmas_gating_test.dart, estado_grabacion_gating_test.dart, servicio_compras_test.dart, servicio_anuncios_test.dart, navegacion_auto_gating_test.dart, servicio_audio_gating_test.dart | flutter_test |
| Widget | approx 8 new plus 9 harness files updated | banner_anuncio_superior_test.dart plus regression widget suites | flutter_test |
| E2E | 0 | none | not installed |
| Total (full suite) | 1245 | 1242 pass / 2 skip / 1 fail | |
### Assertion Quality
Audited all 8 new test files (estado_entitlement_test.dart, servicio_compras_test.dart,
estado_alarmas_gating_test.dart, estado_grabacion_gating_test.dart,
navegacion_auto_gating_test.dart, servicio_audio_gating_test.dart,
servicio_anuncios_test.dart, banner_anuncio_superior_test.dart) for banned patterns
(tautologies, ghost loops over possibly-empty collections, assertion-free production calls,
ratio of mocks to assertions). Loops over hardcoded non-empty literal lists (for example the
respuestaBloqueadaPorEntitlement test's loop over a literal id list) do not qualify as ghost
loops since the collection is a non-empty compile-time literal, not a runtime query result.
Assertion quality: All assertions verify real behavior -- 0 CRITICAL, 0 WARNING.
### Correctness (Static Evidence)
| Requirement area | Status | Notes |
|------------|--------|-------|
| Fail-open entitlement default | Implemented, no reachable bypass today | See WARNING (latent risk) |
| Android Auto gate choke points | Implemented | 5 of 5 dispatch methods gated, 3 of 3 transport methods left open |
| Vacations full gate | Implemented | bool return, single failure mode, correctly UI-routed |
| Ad ordering invariants | Implemented | Cap-check strictly precedes interstitial |
| Equalizer isolation | Implemented | Zero cross-references |
| l10n new keys | Partially implemented | 2 of 4 pt keys are untranslated copies (see CRITICAL) |
### Coherence (Design)
| Decision | Followed? | Notes |
|----------|-----------|-------|
| ADR-1 (versioned prefs key, fail-open) | Yes | compra_premium_v1, absent key equals free |
| ADR-2 (sole in_app_purchase call site) | Yes | ServicioComprasPlayBilling only |
| ADR-3 (callback-injection, not direct EstadoEntitlement dependency) | Yes | Mirrors existing emisoraActual pattern |
| ADR-4 (root labels visible, lock one level down) | Yes | Documented deviation from the spec's literal root-locking wording, resolved per orchestrator/design.md; regression-safe for premium |
| ADR-5 (distinct ResultadoGuardarAlarma enum, not overloaded error field) | Yes | |
| ADR-6 (interstitial ordering: cap-check then interstitial then editor) | Yes | Corrected mid-run per apply-progress's own honest disclosure; final state verified correct |
| notifyChildrenChanged deprecation workaround | Yes | Uses the plugin's own documented replacement mechanism |
### Issues Found
CRITICAL:
1. tasks.md task 3.3 is unchecked on the filesystem despite apply-progress and Engram
artifacts claiming full 27/27 completion. Tracking and documentation integrity failure --
blocks a clean archive per the verify decision gate, even though the underlying
implementation and tests for 3.3 are genuinely present and passing.
2. flutter test (full suite, 1245 tests) FAILS: test/l10n/arb_anti_copy_test.dart catches 2
of the 4 new localization keys (desbloquearPremium, restaurarCompras) left byte-identical
to the Spanish template for the pt locale -- a genuine untranslated-copy defect introduced
by this change, undetected because the apply agent's regression batches never included
test/l10n/. Directly contradicts the "full suite green (719+)" claim.
WARNING:
1. The fail-open entitlement default in EstadoAlarmas/EstadoGrabacion is a latent
monetization-bypass risk pattern: no current call site reaches it, but nothing
structurally prevents a future one from silently doing so with no test failure to catch
it (the default fabricates full premium access rather than failing safe). Recommend a
follow-up hardening task: make esPremium a required parameter (forcing every call site,
including the approximately 30 pre-existing tests, to be explicit), or flip the default to
"() => false" and update the tests that rely on implicit ungated construction.
2. "Alarm Cap UX Never Bare-Jumps To Paywall" requirement is source-verified but has no
dedicated widget test asserting the exact snackbar text plus secondary CTA pair in
isolation.
SUGGESTION:
1. crearRangoVacaciones's bool return (Deviation #5) works today because it has exactly one
failure mode. If a second failure mode is ever added (for example a validation error), the
caller will not be able to distinguish it from an entitlement block. Consider migrating to
a small result enum before that happens, matching the ResultadoGuardarAlarma and
ResultadoIniciarGrabacion precedent already established elsewhere in this same change.
2. "dart format --set-exit-if-changed lib/ test/" currently flags 18 pre-existing files
unrelated to this change (confirmed via diff against the Files Changed table) --
pre-existing repository drift, not a regression, but worth a separate cleanup pass.
### Verdict
FAIL -- 2 CRITICAL findings block a clean archive: (1) tasks.md task 3.3 tracking
discrepancy, and (2) a genuine, reproducible test failure in the full flutter test suite
caused by this change's own untranslated Portuguese localization content, which the apply
agent's own claims (full suite green, 27/27 tasks) did not disclose. Both are narrow and
mechanically fixable (check the box; translate 2 strings or add reviewed allowlist entries)
-- recommend routing back to sdd-apply for a small, targeted fix-and-reverify rather than a
full re-implementation. All 20 spec requirements are otherwise source/test-verified
compliant, and the 6 orchestrator-flagged scrutiny points (fail-open default, Android Auto
gating completeness, notifyChildrenChanged replacement, vacations bool gate, interstitial
ordering, equalizer isolation) all check out as implemented correctly.
@@ -0,0 +1,44 @@
group = "es.freetimelab.pluriwave.fileactions"
version = "1.0-SNAPSHOT"
// Sin bloque `buildscript` a proposito: este modulo solo se construye desde
// `android/settings.gradle.kts` de la app, cuyo `pluginManagement` ya pone
// AGP 8.11.1 y Kotlin 2.2.20 en el classpath compartido. Declarar aqui otro
// classpath de AGP arriesga un choque de versiones con el de la app.
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "es.freetimelab.pluriwave.fileactions"
compileSdk = 36
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
sourceSets {
getByName("main") {
java.srcDirs("src/main/kotlin")
}
}
defaultConfig {
// Igual que `flutter.minSdkVersion` en Flutter 3.44 (FlutterExtension.kt).
minSdk = 24
}
}
dependencies {
// `androidx.core.content.FileProvider`, para servir la caratula embebida
// cacheada desde la autoridad `${applicationId}.fileprovider` que declara
// el manifiesto del modulo de app.
implementation("androidx.core:core-ktx:1.16.0")
}
@@ -0,0 +1 @@
rootProject.name = 'pluriwave_file_actions'
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -0,0 +1,363 @@
package es.freetimelab.pluriwave.fileactions
import android.content.Context
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import android.provider.DocumentsContract
import android.util.Log
import androidx.core.content.FileProvider
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.io.File
/**
* Activity-FREE half of the `pluriwave/file_actions` channel
* (fix/android-auto-musica-local, item 3).
*
* These four methods -- `hasPersistedPermission`, `listAudioChildren`,
* `resolvePlayableUri`, `readAudioMetadataBatch` -- only ever needed a
* [ContentResolver][android.content.ContentResolver], which is an
* app-scoped API: they never touch an Activity, a window, or
* `startActivityForResult`. They were nevertheless trapped inside
* `MainActivity.configureFlutterEngine`, the ONE place in the whole repo
* that installed a handler on this channel.
*
* That is the reported bug: when Android Auto binds the MediaBrowserService
* before the phone app has been opened, `audio_service` builds a bare
* `FlutterEngine` with no Activity, `configureFlutterEngine` never runs, the
* channel has no handler at all, and every `invokeMethod` on it throws
* `MissingPluginException`. Dart could not tell that apart from "permission
* revoked" and silently dropped "Musica Local" from the car's browse tree.
*
* Living in a real plugin package is what makes them registerable on ANY
* engine: [PluriWaveFileActionsPlugin] is listed in
* `GeneratedPluginRegistrant`, which the `FlutterEngine(Context)` constructor
* runs by itself, headless engine included. An app-module class never could.
*
* `pickMusicFolder` and the recordings-folder intents are deliberately NOT
* here: they need `startActivityForResult` / `startActivity` plus an
* `onActivityResult` callback, so they stay on `MainActivity` in the app
* module, which delegates everything else to this same class -- so both
* engines answer the four SAF methods identically, from ONE implementation.
*/
class FileActionsHandler(private val context: Context) {
private val tag = "PluriWave"
/**
* Answers [call] if it is one of the Activity-free methods, replying
* through [result] and returning `true`. Returns `false` -- WITHOUT
* touching [result] -- for anything else, so `MainActivity` can fall
* through to its own Activity-bound methods on the same channel.
*/
fun manejar(call: MethodCall, result: MethodChannel.Result): Boolean {
when (call.method) {
"listAudioChildren" -> {
val treeUri = call.argument<String>("treeUri")
val parentDocumentId = call.argument<String>("parentDocumentId") ?: ""
Log.d(
tag,
"file_actions.listAudioChildren treeUri=$treeUri parentDocumentId=$parentDocumentId"
)
if (treeUri.isNullOrBlank()) {
result.success(emptyList<Map<String, Any>>())
} else {
result.success(listAudioChildren(treeUri, parentDocumentId))
}
}
"resolvePlayableUri" -> {
val treeUri = call.argument<String>("treeUri")
val documentId = call.argument<String>("documentId")
Log.d(
tag,
"file_actions.resolvePlayableUri treeUri=$treeUri documentId=$documentId"
)
if (treeUri.isNullOrBlank() || documentId.isNullOrBlank()) {
result.success(null)
} else {
result.success(resolvePlayableUri(treeUri, documentId))
}
}
"hasPersistedPermission" -> {
val treeUri = call.argument<String>("treeUri")
Log.d(tag, "file_actions.hasPersistedPermission treeUri=$treeUri")
result.success(
if (treeUri.isNullOrBlank()) false else hasPersistedPermission(treeUri)
)
}
"readAudioMetadataBatch" -> {
val treeUri = call.argument<String>("treeUri")
val documentIds = call.argument<List<String>>("documentIds") ?: emptyList()
Log.d(
tag,
"file_actions.readAudioMetadataBatch treeUri=$treeUri count=${documentIds.size}"
)
if (treeUri.isNullOrBlank()) {
result.success(emptyList<Map<String, Any?>>())
} else {
result.success(readAudioMetadataBatch(treeUri, documentIds))
}
}
else -> return false
}
return true
}
/**
* Traza el rechazo de un metodo que exige Activity, para que el log
* distinga "no hay Activity aqui" de "el canal no existe". Lo usa
* [PluriWaveFileActionsPlugin] antes de responder `notImplemented()`.
*/
fun trazarNoDisponibleSinActividad(metodo: String) {
Log.d(tag, "file_actions.$metodo needs an Activity; not available here")
}
/**
* Walks ONE level of the SAF tree rooted at [treeUri] (android-auto-local-music,
* static review only -- Design "Lazy per-folder enumeration, never an
* eager tree dump"): [parentDocumentId] blank means the tree root
* itself, otherwise the given subfolder's documentId. Filters files to
* audio MIME types at the native layer (lean payload); each returned row
* also carries `mime` so the Dart side can re-validate via
* `esArchivoAudio` (defense-in-depth). Any query failure degrades to an
* empty list rather than throwing.
*/
private fun listAudioChildren(treeUri: String, parentDocumentId: String): List<Map<String, Any>> {
return try {
val parsedTree = Uri.parse(treeUri)
val parentId = parentDocumentId.ifBlank {
DocumentsContract.getTreeDocumentId(parsedTree)
}
val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(parsedTree, parentId)
val projection = arrayOf(
DocumentsContract.Document.COLUMN_DOCUMENT_ID,
DocumentsContract.Document.COLUMN_DISPLAY_NAME,
DocumentsContract.Document.COLUMN_MIME_TYPE
)
val resultado = mutableListOf<Map<String, Any>>()
context.contentResolver.query(childrenUri, projection, null, null, null)?.use { cursor ->
val idxDocId = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
val idxNombre = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
val idxMime = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_MIME_TYPE)
while (cursor.moveToNext()) {
val documentId = cursor.getString(idxDocId) ?: continue
val nombre = cursor.getString(idxNombre) ?: continue
val mime = cursor.getString(idxMime) ?: ""
val esDirectorio = mime == DocumentsContract.Document.MIME_TYPE_DIR
if (!esDirectorio && !mime.startsWith("audio/")) continue
resultado.add(
mapOf(
"documentId" to documentId,
"nombre" to nombre,
"esDirectorio" to esDirectorio,
"mime" to mime
)
)
}
}
resultado
} catch (error: Throwable) {
Log.e(tag, "file_actions.listAudioChildren failed treeUri=$treeUri parentDocumentId=$parentDocumentId", error)
emptyList()
}
}
/**
* Resolves a leaf [documentId] within [treeUri] to its playable
* `content://` URI (android-auto-local-music, static review only).
* Returns `null` on any failure instead of throwing.
*/
private fun resolvePlayableUri(treeUri: String, documentId: String): String? {
return try {
val parsedTree = Uri.parse(treeUri)
DocumentsContract.buildDocumentUriUsingTree(parsedTree, documentId).toString()
} catch (error: Throwable) {
Log.e(tag, "file_actions.resolvePlayableUri failed treeUri=$treeUri documentId=$documentId", error)
null
}
}
/**
* Checks whether [treeUri]'s read permission is still among
* [android.content.ContentResolver.getPersistedUriPermissions]
* (android-auto-local-music, static review only) -- used for cold-start
* / revoked-permission detection (Spec "Permission revoked or never
* granted"). Returns `false` (never throws) on a malformed [treeUri] or
* any other failure.
*
* Persisted URI grants are taken by the app, not by the Activity, so
* this answers identically on an engine with no Activity -- which is
* exactly why it belongs in this class.
*/
private fun hasPersistedPermission(treeUri: String): Boolean {
return try {
val parsed = Uri.parse(treeUri)
context.contentResolver.persistedUriPermissions.any {
it.uri == parsed && it.isReadPermission
}
} catch (error: Throwable) {
Log.e(tag, "file_actions.hasPersistedPermission failed treeUri=$treeUri", error)
false
}
}
/**
* Batched embedded-metadata extraction (android-auto-local-music-phase2,
* static review only -- Design "Interfaces / Contracts"): for each of
* [documentIds], extracts title/artist/bitrate/sample-rate and the
* embedded picture via [extraerMetadatosPista]. Never throws across the
* channel boundary -- a malformed [treeUri] (or any other unexpected
* failure) degrades the WHOLE call to `[]`; a per-entry failure is
* already isolated inside [extraerMetadatosPista].
*/
private fun readAudioMetadataBatch(treeUri: String, documentIds: List<String>): List<Map<String, Any?>> {
return try {
val parsedTree = Uri.parse(treeUri)
documentIds.map { documentId -> extraerMetadatosPista(parsedTree, documentId) }
} catch (error: Throwable) {
Log.e(tag, "file_actions.readAudioMetadataBatch failed treeUri=$treeUri", error)
emptyList()
}
}
/**
* Extracts one [documentId]'s embedded metadata via
* [MediaMetadataRetriever] (android-auto-local-music-phase2, static
* review only -- mirrors [listAudioChildren]/[resolvePlayableUri]'s
* never-throws shape). `METADATA_KEY_SAMPLERATE` (raw key `38`, no
* public constant below API 31) is gated behind
* `Build.VERSION.SDK_INT >= 31` (Design ADR-5); every other field is
* available since API 10 and read unconditionally. A resolvable
* embedded picture is handed to [cachearArteEmbebido]; art-cache
* failures degrade that single field to `null` without failing the
* whole entry. On ANY failure for this [documentId] (unsupported
* format, permission edge case, corrupt file), the row degrades to an
* all-null-but-`documentId` entry instead of throwing --
* `retriever.release()` always runs via `finally`.
*/
private fun extraerMetadatosPista(parsedTree: Uri, documentId: String): Map<String, Any?> {
val retriever = MediaMetadataRetriever()
return try {
val documentUri = DocumentsContract.buildDocumentUriUsingTree(parsedTree, documentId)
retriever.setDataSource(context, documentUri)
val titulo = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)
val artista = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
val bitrate = retriever
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE)
?.toIntOrNull()
val sampleRate = if (Build.VERSION.SDK_INT >= 31) {
// METADATA_KEY_SAMPLERATE = 38 (API 31+, Design ADR-5); no
// public constant exists on this minSdk, so the raw key is
// used directly, guarded by the version check above.
retriever.extractMetadata(38)?.toIntOrNull()
} else {
null
}
val artUri = try {
retriever.embeddedPicture?.let { cachearArteEmbebido(documentId, it) }
} catch (error: Throwable) {
Log.e(
tag,
"file_actions.readAudioMetadataBatch embeddedPicture failed documentId=$documentId",
error
)
null
}
mapOf(
"documentId" to documentId,
"titulo" to titulo,
"artista" to artista,
"bitrate" to bitrate,
"sampleRate" to sampleRate,
"artUri" to artUri
)
} catch (error: Throwable) {
Log.e(
tag,
"file_actions.readAudioMetadataBatch entry failed documentId=$documentId",
error
)
mapOf(
"documentId" to documentId,
"titulo" to null,
"artista" to null,
"bitrate" to null,
"sampleRate" to null,
"artUri" to null
)
} finally {
try {
retriever.release()
} catch (_: Throwable) {
// release() failing is not actionable -- the retriever is
// being discarded regardless.
}
}
}
/**
* Embedded-art cache write + LRU trim (android-auto-local-music-phase2,
* static review only -- Design ADR-1). Writes [picture] bytes to
* `cacheDir/pluriwave_art/<hash(documentId)>` (skips the write when the
* file already exists, so re-parsing the same track reuses it), returns
* the `content://` URI served via the EXISTING
* `${applicationId}.fileprovider` authority
* (`AndroidManifest.xml`, `pluriwave_file_paths.xml`'s
* `cache-path path="."`) and trims `pluriwave_art/` via [trimArtCache].
* `hash` uses SHA-256 hex because a raw `documentId` may contain
* `:`/`/`, which are illegal in filenames on most filesystems.
*/
private fun cachearArteEmbebido(documentId: String, picture: ByteArray): String? {
return try {
val artDir = File(context.cacheDir, "pluriwave_art").apply { mkdirs() }
val artFile = File(artDir, hashDocumentId(documentId))
if (!artFile.exists()) {
artFile.writeBytes(picture)
}
trimArtCache(artDir)
FileProvider.getUriForFile(
context,
"${context.packageName}.fileprovider",
artFile
).toString()
} catch (error: Throwable) {
Log.e(tag, "file_actions.cachearArteEmbebido failed documentId=$documentId", error)
null
}
}
private fun hashDocumentId(documentId: String): String {
val digest = java.security.MessageDigest.getInstance("SHA-256")
val bytes = digest.digest(documentId.toByteArray(Charsets.UTF_8))
return bytes.joinToString("") { "%02x".format(it) }
}
/**
* LRU-by-`lastModified` trim of the embedded-art cache dir (Design
* ADR-1): after each write, keeps at most 256 files AND at most 32 MB
* total, deleting the OLDEST-by-mtime entries first. Kept as a
* trivially reviewable loop -- these files are native-owned, so
* round-tripping names to Dart to pick deletions would add channel
* chatter with no testability gain (the `delete()` is native
* regardless, per ADR-1's rationale).
*/
private fun trimArtCache(artDir: File) {
val maxArchivos = 256
val maxBytes = 32L * 1024 * 1024
val archivos = artDir.listFiles()?.sortedByDescending { it.lastModified() }?.toMutableList()
?: return
var totalBytes = archivos.sumOf { it.length() }
while (archivos.isNotEmpty() && (archivos.size > maxArchivos || totalBytes > maxBytes)) {
val masViejo = archivos.removeAt(archivos.size - 1)
totalBytes -= masViejo.length()
masViejo.delete()
}
}
companion object {
const val CHANNEL = "pluriwave/file_actions"
}
}
@@ -0,0 +1,76 @@
package es.freetimelab.pluriwave.fileactions
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodChannel
/**
* Registra `pluriwave/file_actions` en TODOS los FlutterEngine de la app.
*
* ## Por que un paquete plugin y no una clase del modulo de app
*
* `AudioServicePlugin.getFlutterEngine` (audio_service 0.18.18,
* `AudioServicePlugin.java:70-75`) construye el engine compartido con
* `new FlutterEngine(context.getApplicationContext())`. Ese constructor
* encadena hasta el maestro con `automaticallyRegisterPlugins = true`
* (verificado en el bytecode de `FlutterEngine`: `FlutterEngine(Context)` ->
* `FlutterEngine(Context, String[])` con `iconst_1`) y ejecuta
* `GeneratedPluginRegister.registerGeneratedPlugins(this)`, que reflexiona
* sobre `io.flutter.plugins.GeneratedPluginRegistrant`.
*
* Es decir: el engine headless registra PLUGINS por si mismo. Por eso
* `shared_preferences` y `just_audio` ya funcionan cuando Android Auto arranca
* la app con el movil bloqueado, y por eso un handler instalado unicamente en
* `MainActivity.configureFlutterEngine` no podia funcionar nunca ahi: sin
* Activity, `configureFlutterEngine` jamas se ejecuta, el canal se queda sin
* handler y cada `invokeMethod` lanza `MissingPluginException`. El nodo
* "Musica Local" desaparecia del arbol del coche.
*
* ## Reparto con MainActivity (decision deliberada)
*
* Este plugin atiende SOLO los cuatro metodos que no necesitan Activity
* ([FileActionsHandler.manejar]) y responde `notImplemented()` al resto, que es
* la respuesta correcta en un engine sin Activity: `pickMusicFolder`,
* `openDirectory`, `viewDirectory` y `openFile` no pueden funcionar sin una.
*
* En el engine CON Activity ambos escriben en el mismo canal, y gana el
* ultimo: el orden es estructural, no casual. `GeneratedPluginRegistrant` corre
* dentro del constructor de `FlutterEngine`, o sea antes de que el engine
* exista como argumento; `FlutterActivityAndFragmentDelegate.onAttach` llama a
* `host.configureFlutterEngine(flutterEngine)` despues, necesariamente con un
* engine ya construido. Asi que en una Activity siempre gana el handler
* combinado de `MainActivity`, que es el superconjunto: delega los cuatro
* metodos SAF en esta MISMA clase [FileActionsHandler] y añade los suyos.
*
* Se descarto hacer el plugin `ActivityAware` y moverle tambien los metodos con
* Activity: obligaria a trasladar ~400 lineas de malabares de `Intent`
* (FileProvider, DocumentsUI, fallbacks de `ACTION_VIEW`) mas el round trip de
* `onActivityResult`, todo ello sin cobertura de `flutter test`, para arreglar
* un bug que no los toca. El reparto de arriba deja UNA sola implementacion de
* la logica compartida, que era el objetivo real.
*/
class PluriWaveFileActionsPlugin : FlutterPlugin {
private var canal: MethodChannel? = null
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
// applicationContext a proposito: los cuatro metodos solo usan el
// ContentResolver y la cacheDir del proceso, asi que sobreviven a
// cualquier Activity y valen igual en el engine headless.
val handler = FileActionsHandler(binding.applicationContext)
canal = MethodChannel(binding.binaryMessenger, FileActionsHandler.CHANNEL).apply {
setMethodCallHandler { call, result ->
if (!handler.manejar(call, result)) {
handler.trazarNoDisponibleSinActividad(call.method)
result.notImplemented()
}
}
}
}
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
// Solo ocurre al destruir el engine, de modo que nunca puede pisar el
// handler combinado que instala MainActivity sobre este mismo canal.
canal?.setMethodCallHandler(null)
canal = null
}
}
@@ -0,0 +1,20 @@
/// Este paquete NO expone API Dart.
///
/// Existe por una sola razon estructural: un `MethodChannel` registrado desde
/// el modulo de aplicacion (`MainActivity.configureFlutterEngine`) solo vive en
/// el engine que tiene Activity. `audio_service` construye ademas un
/// FlutterEngine *headless* (`AudioServicePlugin.getFlutterEngine`, que llama a
/// `new FlutterEngine(context.getApplicationContext())`) cuando Android Auto
/// enlaza el `MediaBrowserService` con la app cerrada. Ese constructor invoca
/// `GeneratedPluginRegister.registerGeneratedPlugins`, que reflexiona sobre
/// `io.flutter.plugins.GeneratedPluginRegistrant`; es decir, registra los
/// PLUGINS, nunca una clase suelta del modulo de app.
///
/// Empaquetando el lado nativo aqui, `GeneratedPluginRegistrant` lo instala en
/// los dos engines sin tocar el manifiesto ni forkear `audio_service`.
///
/// Los llamantes Dart siguen usando `MethodChannel('pluriwave/file_actions')`
/// directamente (`lib/servicios/musica_local_auto.dart`,
/// `lib/estado/estado_grabacion.dart`), asi que este fichero se queda vacio a
/// proposito: cualquier fachada aqui seria una segunda forma de decir lo mismo.
library;
@@ -0,0 +1,23 @@
name: pluriwave_file_actions
description: >-
Canal nativo `pluriwave/file_actions` de PluriWave empaquetado como plugin
Flutter, para que quede registrado en TODOS los FlutterEngine de la app --
incluido el engine headless que audio_service crea cuando Android Auto
arranca el MediaBrowserService sin Activity.
version: 0.0.1
publish_to: 'none'
environment:
sdk: ^3.7.0
flutter: '>=3.3.0'
dependencies:
flutter:
sdk: flutter
flutter:
plugin:
platforms:
android:
package: es.freetimelab.pluriwave.fileactions
pluginClass: PluriWaveFileActionsPlugin
+89 -2
View File
@@ -325,6 +325,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.3.3"
google_mobile_ads:
dependency: "direct main"
description:
name: google_mobile_ads
sha256: "0d4a3744b5e8ed1b8be6a1b452d309f811688855a497c6113fc4400f922db603"
url: "https://pub.dev"
source: hosted
version: "5.3.1"
hooks:
dependency: transitive
description:
@@ -349,6 +357,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.2"
in_app_purchase:
dependency: "direct main"
description:
name: in_app_purchase
sha256: "0e9510b80b0074e89ab0a8e0fc901439b779dc9ae575ab8d419253c6e1627716"
url: "https://pub.dev"
source: hosted
version: "3.3.0"
in_app_purchase_android:
dependency: transitive
description:
name: in_app_purchase_android
sha256: c04e2cad0470fc868cb0ea06477648f003220b1b6612909db83528ca83ac0905
url: "https://pub.dev"
source: hosted
version: "0.5.2"
in_app_purchase_platform_interface:
dependency: transitive
description:
name: in_app_purchase_platform_interface
sha256: "0b0076cac8ce4fa7048f01e76af8b123aeb6a7c4e0dea2a5206d6664454f3e36"
url: "https://pub.dev"
source: hosted
version: "1.4.1"
in_app_purchase_storekit:
dependency: transitive
description:
name: in_app_purchase_storekit
sha256: "702a23c3d2ddc177b075d521d264900e82f01663881e4ef3ce17775de298c0e3"
url: "https://pub.dev"
source: hosted
version: "0.4.11"
intl:
dependency: "direct main"
description:
@@ -365,6 +405,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.2"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: "2a743920d81b7910627f68ee2c9ac1fc0bfee32b9fc3403587d7c6791ca12f80"
url: "https://pub.dev"
source: hosted
version: "4.12.0"
just_audio:
dependency: "direct main"
description:
@@ -581,6 +629,13 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
pluriwave_file_actions:
dependency: "direct main"
description:
path: "packages/pluriwave_file_actions"
relative: true
source: path
version: "0.0.1"
provider:
dependency: "direct main"
description:
@@ -906,6 +961,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
webview_flutter:
dependency: transitive
description:
name: webview_flutter
sha256: d53e1ccf5516f25017e3c9d44c39034db352d20fa34fe200674270242c2c5111
url: "https://pub.dev"
source: hosted
version: "4.14.1"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
sha256: a97db7a44f8e71af2f3971c45550a08cce1fb60059c1b8e534251e6cfb753490
url: "https://pub.dev"
source: hosted
version: "4.13.0"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
sha256: "1221c1b12f5278791042f2ec2841743784cf25c5a644e23d6680e5d718824f04"
url: "https://pub.dev"
source: hosted
version: "2.15.1"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: c879dd64b87c452aa84381b244d5469da57ba7e8cca6884c7b1e0d406372c12d
url: "https://pub.dev"
source: hosted
version: "3.26.0"
win32:
dependency: transitive
description:
@@ -931,5 +1018,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.10.3 <4.0.0"
flutter: ">=3.38.4"
dart: ">=3.12.0 <4.0.0"
flutter: ">=3.44.0"
+38 -6
View File
@@ -1,7 +1,7 @@
name: pluriwave
description: "Radio mundial con ecualizador, reconocimiento de canciones y UI premium"
publish_to: 'none'
version: 1.2.11+133
version: 1.3.3+162
environment:
sdk: ^3.7.0
@@ -49,12 +49,22 @@ dependencies:
geocoding: ^3.0.0
package_info_plus: ^8.3.1
# Ads (activar cuando tengamos Ad Unit IDs)
# google_mobile_ads: ^5.3.0
# Ads — TODO: swap Google test ad unit IDs (servicio_anuncios.dart) for
# real AdMob unit IDs once provisioned (iap-freemium-unlock, Open Question).
google_mobile_ads: ^5.3.0
# In-app purchase
# in_app_purchase: ^3.2.0
in_app_purchase: ^3.2.0
# Canal nativo SAF (`pluriwave/file_actions`) empaquetado como plugin para
# que GeneratedPluginRegistrant lo instale TAMBIEN en el FlutterEngine
# headless que audio_service crea al arrancar desde Android Auto. Sin esto
# el canal solo existia en el engine de MainActivity y "Musica Local"
# desaparecia del arbol del coche. No expone API Dart: los llamantes siguen
# usando MethodChannel('pluriwave/file_actions').
pluriwave_file_actions:
path: packages/pluriwave_file_actions
# Song recognition (activar con AudD key)
# permission_handler: ^11.3.1
@@ -75,4 +85,26 @@ flutter:
- assets/audio/
- assets/mockups/
- assets/generated/
# Flutter NO recurse: declarar 'assets/content/' incluye solo los
# ficheros sueltos de esa carpeta, nunca los de sus subcarpetas. Todo
# el contenido vive en subcarpetas, asi que NADA de esto viajaba en el
# APK -- verificado abriendo el binario instalado: cero entradas de
# assets/content. El onboarding reventaba en cada arranque con
# 'Unable to load asset: assets/content/onboarding/en.md' aunque el
# fichero existe en disco. Mismo fallo de familia que los drawables
# resueltos por nombre: referencia sin validacion en compilacion.
- assets/content/
- assets/content/onboarding/
- assets/content/updates/ar/
- assets/content/updates/bn/
- assets/content/updates/de/
- assets/content/updates/en/
- assets/content/updates/es/
- assets/content/updates/fr/
- assets/content/updates/hi/
- assets/content/updates/id/
- assets/content/updates/it/
- assets/content/updates/ja/
- assets/content/updates/pt/
- assets/content/updates/ru/
- assets/content/updates/zh/
+66
View File
@@ -1,6 +1,12 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/app.dart';
import 'package:pluriwave/estado/estado_entitlement.dart';
import 'package:pluriwave/servicios/servicio_anuncios.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// S1 (Tier 1 visual fidelity): the prototype (`t4`) never draws a global
/// `AppBar` — every root owns its own 56px title row instead (see
@@ -69,4 +75,64 @@ void main() {
reason: 'the tutorial carousel must run before the what-is-new dialog',
);
});
group(
'construirCuerpoPrincipal — banner y la status bar (FIX 1, code review)',
() {
setUp(() {
SharedPreferences.setMockInitialValues({});
});
Future<void> bombear(WidgetTester tester, {required bool premium}) async {
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(top: 44)),
child: MaterialApp(
home: MultiProvider(
providers: [
ChangeNotifierProvider<EstadoEntitlement>(
create: (_) => EstadoEntitlement(prefs: null),
),
Provider<ServicioAnuncios>(
create: (_) => ServicioAnuncios(esPremium: () => premium),
),
],
child: Scaffold(
body: construirCuerpoPrincipal(
contenido: const Align(
alignment: Alignment.topLeft,
child: Text('contenido'),
),
),
),
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
}
testWidgets(
'usuario premium: el contenido arranca en y=0 -- edge-to-edge, sin '
'franja en blanco reservada para la status bar',
(tester) async {
await bombear(tester, premium: true);
expect(tester.getTopLeft(find.text('contenido')).dy, 0);
},
);
testWidgets(
'usuario free con el banner aún sin cargar: el contenido arranca '
'igualmente en y=0 -- misma posición edge-to-edge que antes del '
'cambio, no una franja reservada de 44px hasta que el ad cargue',
(tester) async {
await bombear(tester, premium: false);
expect(tester.getTopLeft(find.text('contenido')).dy, 0);
},
);
},
);
}
@@ -0,0 +1,207 @@
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/main.dart';
import 'package:pluriwave/servicios/servicio_audio.dart';
import 'helpers/handlers_audio.dart';
/// fix/android-auto-musica-local item 4 — CORRECCIÓN del disparador.
///
/// El disparador anterior era `View.maybeOf(context) != null` dentro de
/// `didChangeDependencies`, con un latch de un solo uso y este comentario:
/// «Que exista una View significa que hay Activity». La premisa es FALSA.
///
/// `runApp` envuelve SIEMPRE el árbol en una `View` construida a partir de
/// `platformDispatcher.implicitView`, y lanza `StateError` si no la hay
/// (`flutter/lib/src/widgets/binding.dart`, `wrapWithDefaultView`). Así que
/// en el motor headless que `audio_service` levanta sin Activity —el mismo
/// que demostrablemente llega a `runApp`, ver la doc de
/// `aplicarPoliticaOrientacion`— `View.maybeOf(context)` ya es no-nulo en el
/// PRIMER `didChangeDependencies`.
///
/// Consecuencia: el latch se gastaba durante el arranque headless, justo en
/// el instante en que no podía conseguir nada (`_childrenSubjects` sigue
/// vacío, y `notificarHijosCambiaron` es `_childrenSubjects[id]?.add(...)`,
/// un no-op silencioso). Y no podía volver a dispararse nunca, porque
/// `didChangeDependencies` no se re-ejecuta cuando más tarde se adjunta una
/// Activity al MISMO motor cacheado. La vía de recuperación estaba muerta en
/// los dos motores.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final crearHandler = registrarHandlersLiberables();
group('debeInvalidarArbolAutoAlReanudar (decisión pura)', () {
test('resumed + coche ya suscrito + latch libre invalida', () {
expect(
debeInvalidarArbolAutoAlReanudar(
estado: AppLifecycleState.resumed,
hayCocheSuscrito: true,
yaInvalidado: false,
),
isTrue,
);
});
test('sin suscripción del coche NO invalida — y por tanto no gasta el '
'latch en el arranque headless', () {
expect(
debeInvalidarArbolAutoAlReanudar(
estado: AppLifecycleState.resumed,
hayCocheSuscrito: false,
yaInvalidado: false,
),
isFalse,
reason:
'notificarHijosCambiaron solo empuja a un sujeto que ya existe, '
'así que invalidar antes de que el coche se suscriba a NADA es '
'demostrablemente un no-op',
);
});
test('ningún estado del ciclo de vida distinto de resumed invalida', () {
for (final estado in [
AppLifecycleState.detached,
AppLifecycleState.inactive,
AppLifecycleState.hidden,
AppLifecycleState.paused,
]) {
expect(
debeInvalidarArbolAutoAlReanudar(
estado: estado,
hayCocheSuscrito: true,
yaInvalidado: false,
),
isFalse,
reason:
'$estado no significa «hay una Activity adjunta en primer '
'plano»; solo resumed lo significa',
);
}
});
test('con el latch ya gastado no vuelve a invalidar (nada de tormenta '
'de notificaciones)', () {
expect(
debeInvalidarArbolAutoAlReanudar(
estado: AppLifecycleState.resumed,
hayCocheSuscrito: true,
yaInvalidado: true,
),
isFalse,
);
});
});
group('OrientacionResponsiveApp — cableado real del disparador', () {
testWidgets('bajo pumpWidget/runApp SIEMPRE existe una View, que es '
'exactamente por qué el disparador anterior no valía', (tester) async {
await tester.pumpWidget(
const OrientacionResponsiveApp(child: SizedBox.shrink()),
);
expect(
View.maybeOf(tester.element(find.byType(SizedBox))),
isNotNull,
reason:
'wrapWithDefaultView envuelve el árbol en una View o lanza '
'StateError: no hay ningún motor bajo runApp sin View',
);
});
testWidgets('arranque headless: hay View desde el primer frame, pero sin '
'Activity ni coche suscrito el latch NO se gasta y sigue disponible '
'para cuando el coche por fin navegue', (tester) async {
final handler = crearHandler();
registrarHandler(handler);
var invalidaciones = 0;
registrarInvalidacionArbolAuto(() => invalidaciones++);
await tester.pumpWidget(
const OrientacionResponsiveApp(child: SizedBox.shrink()),
);
await tester.pump();
expect(
invalidaciones,
0,
reason: 'el primer frame no prueba que haya Activity',
);
// Incluso si un evento de ciclo de vida llegara en frío: el coche no
// ha navegado nada todavía, así que no hay ningún sujeto al que
// empujar y el latch debe sobrevivir.
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(invalidaciones, 0);
// Ahora el coche navega la raíz (esto es lo que crea el sujeto), y la
// siguiente vuelta a primer plano sí encuentra algo que invalidar.
handler.subscribeToChildren(AudioService.browsableRootId);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(invalidaciones, 1);
});
testWidgets('con el coche YA suscrito, adjuntar una Activity (resumed) '
'empuja de verdad por el stream de hijos de la raíz', (tester) async {
final handler = crearHandler();
registrarHandler(handler);
// El coche navegó la raíz durante el arranque headless: el sujeto
// existe y el head unit tiene el listado cacheado.
final eventos = <Map<String, dynamic>>[];
final sub = handler
.subscribeToChildren(AudioService.browsableRootId)
.listen(eventos.add);
addTearDown(sub.cancel);
await tester.pumpWidget(
const OrientacionResponsiveApp(child: SizedBox.shrink()),
);
await tester.pump();
expect(
eventos,
isEmpty,
reason: 'todavía no hay Activity, solo una View',
);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(
eventos,
hasLength(1),
reason:
'esta es la ÚNICA vía de recuperación cuando el registro del '
'canal pluriwave/file_actions falló en el motor headless',
);
// Y no una por cada rebote de ciclo de vida.
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(eventos, hasLength(1));
});
});
group('hayCocheSuscritoAlArbol', () {
test('es false sin handler suscrito y true en cuanto el coche navega un '
'id', () async {
final handler = crearHandler();
registrarHandler(handler);
expect(hayCocheSuscritoAlArbol(), isFalse);
handler.subscribeToChildren(AudioService.browsableRootId);
expect(hayCocheSuscritoAlArbol(), isTrue);
});
});
}
+96
View File
@@ -0,0 +1,96 @@
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));
});
});
});
}
@@ -0,0 +1,55 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
/// Every file under `assets/content/` must be loadable through `rootBundle`,
/// which is the only thing that proves it is DECLARED in pubspec.yaml and
/// therefore actually ships.
///
/// Found by reading the installed APK: it contained ZERO entries under
/// `assets/content/`, while `assets/icons/alarmas/*` was present. pubspec
/// declared `assets/content/` — and Flutter does NOT recurse: naming a
/// directory includes the files sitting directly in it, never its
/// subdirectories. All of this content lives in subdirectories
/// (`onboarding/`, `updates/<locale>/`), so the entire onboarding and
/// release-notes feature had never shipped in any build. On the device it
/// surfaced on every launch as:
///
/// Unable to load asset: "assets/content/onboarding/en.md"
///
/// with the file plainly present on disk.
///
/// Same family as the drawables the resource shrinker deleted: a reference by
/// NAME that nothing validates at compile time, so it fails only on a device.
/// A test that merely checked `File(...).existsSync()` would have stayed green
/// throughout — the files were never missing. Loading through `rootBundle` is
/// what makes it a real guard, because that is the path the app itself takes.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final directorio = Directory('assets/content');
final ficheros =
directorio
.listSync(recursive: true)
.whereType<File>()
.map((f) => f.path.replaceAll(r'\', '/'))
.toList()
..sort();
test('hay contenido que comprobar (si no, este test sería vacuo)', () {
expect(ficheros, isNotEmpty);
});
for (final ruta in ficheros) {
test('$ruta está declarado y se puede cargar', () async {
await expectLater(
rootBundle.loadString(ruta),
completes,
reason:
'existe en disco pero rootBundle no lo encuentra: falta declarar '
'su directorio en pubspec.yaml, y no viajará en el APK',
);
});
}
}
@@ -0,0 +1,179 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_alarmas.dart';
import 'package:pluriwave/modelos/alarma_musical.dart';
import 'package:pluriwave/servicios/servicio_alarmas.dart';
import 'package:pluriwave/servicios/servicio_alarmas_android.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes_alarmas.dart';
/// Reported on-device: an alarm set for Monday 16:20 never rang, and the
/// "next alarm" banner showed a DIFFERENT alarm (the next morning's) instead.
///
/// Root cause: `finalizarEjecucion` ("Detener") anchored the completed
/// occurrence to `proximaEjecucion` with no check that it was the one
/// actually ringing. On the native-fire path the fire-time sync advances
/// `proximaEjecucion` to the NEXT occurrence BEFORE the user can reach the
/// ring screen — so stopping today's ring recorded NEXT week's occurrence as
/// already handled. `ServicioProgramacionAlarmas._esValida` then rejected
/// that occurrence for real, and the alarm silently jumped past it: it never
/// rang, and every sibling alarm outranked it in the banner.
///
/// This is the exact hazard `posponerAlarma` was fixed for in `9c7cf4e`
/// ("anchor snooze to the ringing occurrence, never a future one"). The guard
/// landed on the snooze path and never on the stop path, which sits directly
/// below it in the same file.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
SharedPreferences.setMockInitialValues({});
});
AlarmaMusical semanalLunes(String id) => AlarmaMusical(
id: id,
nombre: 'Tarde del lunes',
hora: 16,
minuto: 20,
tipoProgramacion: TipoProgramacionAlarma.diasSemana,
diasSemana: const [DateTime.monday],
);
test('Detener cierra la ocurrencia que sonaba, no quema la siguiente '
'(el nativo ya avanzó proximaEjecucion antes de que el usuario '
'llegue a la pantalla)', () async {
// Monday 2026-08-03.
var ahora = DateTime(2026, 8, 3, 16, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
);
addTearDown(estado.dispose);
addTearDown(android.dispose);
await estado.guardarAlarma(semanalLunes('a1'));
expect(
estado.alarmas.single.proximaEjecucion,
DateTime(2026, 8, 3, 16, 20),
);
// 16:20 — it rings. The native scheduler records the occurrence handled
// and rearms; the cold-start sync brings that over, which advances
// proximaEjecucion to NEXT Monday while the alarm is still ringing.
ahora = DateTime(2026, 8, 3, 16, 20, 5);
android.ejecucionesNativas.add(
EjecucionAlarmaNativa(
alarmaId: 'a1',
gestionadaEn: DateTime(2026, 8, 3, 16, 20),
),
);
await estado.inicializar();
expect(
estado.alarmas.single.proximaEjecucion,
DateTime(2026, 8, 10, 16, 20),
reason: 'precondición: el nativo ya avanzó a la semana siguiente',
);
// NOW the user taps "Detener" on the ring screen.
await estado.finalizarEjecucion('a1');
expect(
estado.alarmas.single.proximaEjecucion,
DateTime(2026, 8, 10, 16, 20),
reason:
'Detener debe cerrar la ocurrencia que sonaba (hoy), no consumir '
'la del lunes que viene empujándola a 2026-08-17',
);
expect(
estado.alarmas.single.ultimaEjecucionGestionada,
isNot(DateTime(2026, 8, 10, 16, 20)),
reason:
'marcar como gestionada una ocurrencia futura es justo lo que hace '
'que _esValida la rechace y esa alarma no suene ese día',
);
});
test('estado ya envenenado se cura solo: una ocurrencia futura marcada '
'como gestionada se descarta al recalcular', () async {
// Devices that ran the buggy build carry the poisoned value in
// SharedPreferences. Without this, the fix would still leave the
// affected alarm skipping one more time, with nothing in the UI to
// explain it -- and the user would reasonably read that as "not fixed".
final ahora = DateTime(2026, 8, 3, 9, 0);
final servicio = ServicioAlarmas(reloj: () => ahora);
// Saved by the buggy stop path: next Monday recorded as already handled.
await servicio.guardarAlarma(
semanalLunes(
'a3',
).copyWith(ultimaEjecucionGestionada: DateTime(2026, 8, 10, 16, 20)),
);
final config = await servicio.recalcularTodas();
final alarma = config.alarmas.single;
expect(alarma.ultimaEjecucionGestionada, isNull);
expect(
alarma.proximaEjecucion,
DateTime(2026, 8, 3, 16, 20),
reason: 'y con el dato corrupto fuera, hoy vuelve a ser candidata',
);
});
test('una ocurrencia gestionada REAL (pasada) se conserva: es la que evita '
'que la alarma vuelva a sonar en el mismo minuto', () async {
final ahora = DateTime(2026, 8, 3, 16, 20, 30);
final servicio = ServicioAlarmas(reloj: () => ahora);
final gestionada = DateTime(2026, 8, 3, 16, 20);
await servicio.guardarAlarma(
semanalLunes('a4').copyWith(ultimaEjecucionGestionada: gestionada),
);
final alarma = (await servicio.recalcularTodas()).alarmas.single;
expect(alarma.ultimaEjecucionGestionada, gestionada);
expect(
alarma.proximaEjecucion,
DateTime(2026, 8, 10, 16, 20),
reason: 'la de hoy ya sonó, la siguiente es el lunes que viene',
);
});
test(
'Detener sin nada sonando tampoco consume la próxima ocurrencia',
() async {
// Defensive: the ring screen is the only production caller, but a stale
// route or a duplicated stop event must not silently eat a day.
var ahora = DateTime(2026, 8, 3, 9, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
);
addTearDown(estado.dispose);
addTearDown(android.dispose);
await estado.guardarAlarma(semanalLunes('a2'));
expect(
estado.alarmas.single.proximaEjecucion,
DateTime(2026, 8, 3, 16, 20),
);
ahora = DateTime(2026, 8, 3, 9, 1);
await estado.finalizarEjecucion('a2');
expect(
estado.alarmas.single.proximaEjecucion,
DateTime(2026, 8, 3, 16, 20),
reason: 'a las 09:01 la ocurrencia de las 16:20 no está sonando',
);
},
);
}
@@ -17,6 +17,7 @@ void main() {
EstadoAlarmas crearEstado(FakePuertoAlarmasAndroid android) {
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(),
android: android,
iniciarAutomaticamente: false,
@@ -31,8 +31,11 @@ void main() {
android = FakePuertoAlarmasAndroid();
});
EstadoAlarmas crearEstado() =>
EstadoAlarmas(android: android, iniciarAutomaticamente: false);
EstadoAlarmas crearEstado() => EstadoAlarmas(
android: android,
iniciarAutomaticamente: false,
esPremium: () => true,
);
/// Mirrors exactly what the native side puts on the channel.
FalloProgramacionNativo falloNativo(String alarmaId, String tipo) =>
+179
View File
@@ -0,0 +1,179 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_alarmas.dart';
import 'package:pluriwave/modelos/alarma_musical.dart';
import 'package:pluriwave/servicios/servicio_alarmas.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes_alarmas.dart';
/// Freemium gating (freemium-gating spec, design ADR-3/ADR-5): the 5-alarm
/// cap for free-tier users, grandfathering of pre-existing alarms, and the
/// full premium gate on vacation-range creation. `esPremium` is a REQUIRED
/// constructor parameter with no default — every other suite passes
/// `() => true` explicitly to keep its pre-gate behavior, and the tests here
/// inject `() => false` to exercise the free tier.
AlarmaMusical _alarma(String id, {bool activa = true}) => AlarmaMusical(
id: id,
nombre: 'Alarma $id',
hora: 7,
minuto: 0,
tipoProgramacion: TipoProgramacionAlarma.diaria,
diasSemana: const [],
activa: activa,
);
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
SharedPreferences.setMockInitialValues({});
});
EstadoAlarmas construir({required bool premium}) {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
esPremium: () => premium,
);
addTearDown(estado.dispose);
addTearDown(android.dispose);
return estado;
}
group('puedeCrearAlarma / cap de 5 (free tier)', () {
test('con 4 alarmas puede crear una mas', () async {
final estado = construir(premium: false);
for (var i = 1; i <= 4; i++) {
await estado.guardarAlarma(_alarma('a$i'));
}
expect(estado.puedeCrearAlarma(), isTrue);
});
test(
'con 5 alarmas (cualquier estado activa) no puede crear una 6a',
() async {
final estado = construir(premium: false);
for (var i = 1; i <= 4; i++) {
await estado.guardarAlarma(_alarma('a$i'));
}
await estado.guardarAlarma(_alarma('a5', activa: false));
expect(estado.puedeCrearAlarma(), isFalse);
},
);
test('la 6a alarma es bloqueada ANTES de programar en Android', () async {
final estado = construir(premium: false);
for (var i = 1; i <= 5; i++) {
await estado.guardarAlarma(_alarma('a$i'));
}
final android = estado.android as FakePuertoAlarmasAndroid;
final programadasPrevias = android.programadas.length;
final resultado = await estado.guardarAlarma(_alarma('a6'));
expect(resultado, ResultadoGuardarAlarma.limiteAlcanzado);
expect(estado.alarmas.length, 5);
expect(android.programadas.length, programadasPrevias);
});
test('editar una de las 5 alarmas existentes sigue funcionando', () async {
final estado = construir(premium: false);
for (var i = 1; i <= 5; i++) {
await estado.guardarAlarma(_alarma('a$i'));
}
final resultado = await estado.guardarAlarma(
_alarma('a3').copyWith(hora: 8),
);
expect(resultado, ResultadoGuardarAlarma.guardada);
expect(estado.alarmas.firstWhere((a) => a.id == 'a3').hora, 8);
});
test('usuario premium no tiene tope', () async {
final estado = construir(premium: true);
for (var i = 1; i <= 5; i++) {
await estado.guardarAlarma(_alarma('a$i'));
}
final resultado = await estado.guardarAlarma(_alarma('a6'));
expect(resultado, ResultadoGuardarAlarma.guardada);
expect(estado.alarmas.length, 6);
expect(estado.puedeCrearAlarma(), isTrue);
});
test(
'grandfathering: 8 alarmas preexistentes siguen funcionando, solo se bloquea la 9a',
() async {
// Simula alarmas ya persistidas antes de que el gate existiera:
// se crean en modo premium (sin tope) y luego se re-evalua en free.
final estadoPremium = construir(premium: true);
for (var i = 1; i <= 8; i++) {
await estadoPremium.guardarAlarma(_alarma('g$i'));
}
expect(estadoPremium.alarmas.length, 8);
// Editar una de las 8 preexistentes en free tier sigue funcionando.
final estadoFree = EstadoAlarmas(
servicio: estadoPremium.servicio,
android: estadoPremium.android,
iniciarAutomaticamente: false,
esPremium: () => false,
);
addTearDown(estadoFree.dispose);
await estadoFree.cargarPersistidasSinRecalcular();
expect(estadoFree.alarmas.length, 8);
final edicion = await estadoFree.guardarAlarma(
estadoFree.alarmas.first.copyWith(hora: 9),
);
expect(edicion, ResultadoGuardarAlarma.guardada);
expect(estadoFree.alarmas.length, 8);
// Una 9a alarma NUEVA sigue bloqueada.
final resultado = await estadoFree.guardarAlarma(_alarma('g9'));
expect(resultado, ResultadoGuardarAlarma.limiteAlcanzado);
expect(estadoFree.alarmas.length, 8);
},
);
});
group('crearRangoVacaciones — gate completo (freemium-gating)', () {
test('free tier: cualquier creacion de vacaciones es bloqueada', () async {
final estado = construir(premium: false);
final creada = await estado.crearRangoVacaciones(
RangoVacaciones(
id: 'v1',
nombre: 'Verano',
inicio: DateTime(2026, 7, 1),
fin: DateTime(2026, 7, 15),
),
);
expect(creada, isFalse);
expect(estado.vacaciones, isEmpty);
});
test('premium: crea vacaciones sin restriccion', () async {
final estado = construir(premium: true);
final creada = await estado.crearRangoVacaciones(
RangoVacaciones(
id: 'v1',
nombre: 'Verano',
inicio: DateTime(2026, 7, 1),
fin: DateTime(2026, 7, 15),
),
);
expect(creada, isTrue);
expect(estado.vacaciones, hasLength(1));
});
});
}
+284
View File
@@ -0,0 +1,284 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_alarmas.dart';
import 'package:pluriwave/estado/estado_radio.dart';
import 'package:pluriwave/modelos/alarma_musical.dart';
import 'package:pluriwave/pantallas/ajustes/pantalla_ajustes_backup.dart';
import 'package:pluriwave/servicios/servicio_alarmas.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes.dart';
import '../helpers/fakes_alarmas.dart';
/// Regression coverage for the data-loss bug (fix/import-alarmas-y-paywall):
/// `EstadoRadio.importarConfig` writes the imported alarm block straight to
/// SharedPreferences, but `EstadoAlarmas` is a separate long-lived
/// `ChangeNotifier` that loaded its alarms into memory at construction and
/// never re-reads on its own. These tests exercise the EXACT sequence the
/// real call site (`pantalla_ajustes_backup.dart`'s `_importar`) now runs
/// after a successful import: `EstadoRadio.importarConfig` followed by
/// `EstadoAlarmas.cargarPersistidasSinRecalcular()` +
/// `EstadoAlarmas.refrescarProgramacion()` — bypassing the file_picker
/// platform channel and the confirmation dialog, which are pure UI
/// plumbing already covered by `pantalla_ajustes_backup_test.dart`.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Directory tempDir;
setUp(() async {
SharedPreferences.setMockInitialValues({});
// A PRIVATE per-test file, never the shared `test/fixtures/` one:
// `EstadoRadio.importarConfig` unconditionally calls
// `_guardarEmisorasCustom()`, which WRITES to whatever
// `resolverArchivoCustom` resolves to — pointing that at the shared
// fixture previously clobbered its committed BOM on disk as a side
// effect of running this file's tests.
tempDir = await Directory.systemTemp.createTemp(
'pluriwave_estado_alarmas_import_test',
);
});
tearDown(() async {
if (tempDir.existsSync()) {
await tempDir.delete(recursive: true);
}
});
Future<File> archivoCustomVacio() async {
final file = File('${tempDir.path}/emisoras_custom.json');
if (!file.existsSync()) {
await file.writeAsString('[]');
}
return file;
}
Map<String, dynamic> jsonAlarma(AlarmaMusical a) => {
'id': a.id,
'nombre': a.nombre,
'activa': a.activa,
'hora': a.hora,
'minuto': a.minuto,
'tipoProgramacion': a.tipoProgramacion.name,
'diasSemana': a.diasSemana,
};
const alarmaVieja = AlarmaMusical(
id: 'vieja',
nombre: 'Alarma vieja (pre-import)',
hora: 6,
minuto: 0,
tipoProgramacion: TipoProgramacionAlarma.diaria,
diasSemana: [1, 2, 3, 4, 5],
);
const alarmaImportada = AlarmaMusical(
id: 'importada',
nombre: 'Alarma importada',
hora: 8,
minuto: 15,
tipoProgramacion: TipoProgramacionAlarma.diaria,
diasSemana: [6, 7],
);
/// Builds the pair the app wires together: `EstadoRadio` (owns
/// `importarConfig`) and `EstadoAlarmas` (owns the alarm reload +
/// re-scheduling this bugfix adds), sharing ONE `SharedPreferences`
/// instance exactly like the real app's provider tree does.
Future<
({
EstadoRadio radio,
EstadoAlarmas alarmas,
FakePuertoAlarmasAndroid android,
})
>
crearPar() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(
'alarmas_musicales_v1',
jsonEncode({
'alarmas': [jsonAlarma(alarmaVieja)],
'vacaciones': [],
'excepciones': [],
}),
);
final android = FakePuertoAlarmasAndroid();
final alarmas = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(prefs: prefs),
android: android,
prefs: prefs,
iniciarAutomaticamente: false,
);
// Loads + native-syncs the pre-import alarm WITHOUT arming
// `inicializar()`'s periodic timers (irrelevant to this bugfix and a
// needless liability for a `flutter test` run).
await alarmas.refrescarProgramacion();
final radio = EstadoRadio(
esPremium: () => true,
audio: FakeServicioAudio(),
favoritos: FakeServicioFavoritos(),
radio: FakeServicioRadio(),
servicioEcualizador: FakeServicioEcualizador(),
servicioGrabacion: FakeServicioGrabacionRadioInactiva(),
resolverArchivoCustom: archivoCustomVacio,
prefs: prefs,
iniciarAutomaticamente: false,
);
return (radio: radio, alarmas: alarmas, android: android);
}
Map<String, dynamic> backupCon({
required List<AlarmaMusical> alarmas,
List<Map<String, dynamic>> vacaciones = const [],
List<Map<String, dynamic>> excepciones = const [],
String ordenListas = 'nombre',
}) => {
'version': 2,
'gruposFavoritos': [],
'favoritos': [],
'emisorasCustom': [],
'presetsEcualizador': {},
'alarmas': {
'alarmas': alarmas.map(jsonAlarma).toList(),
'vacaciones': vacaciones,
'excepciones': excepciones,
},
'emisoraPreferidaUuid': null,
'ordenListas': ordenListas,
'timerSuenoPresetsSegundos': <int>[300, 600],
};
test('after import, EstadoAlarmas reflects the imported alarms, not the '
'pre-import ones', () async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
expect(par.alarmas.alarmas.map((a) => a.id), ['vieja']);
await aplicarImportacionConfig(
par.radio,
par.alarmas,
backupCon(alarmas: [alarmaImportada]),
);
expect(par.alarmas.alarmas.map((a) => a.id), ['importada']);
expect(par.alarmas.alarmas.single.nombre, 'Alarma importada');
});
test('native re-scheduling is triggered after an import', () async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
// Sanity: the pre-import alarm was already scheduled.
expect(par.android.programadas.map((a) => a.id), contains('vieja'));
await aplicarImportacionConfig(
par.radio,
par.alarmas,
backupCon(alarmas: [alarmaImportada]),
);
// The imported alarm was handed to the native Android bridge — this is
// what makes it actually ring, not just appear in the list.
expect(par.android.programadas.map((a) => a.id), contains('importada'));
});
test(
'vacation ranges and alarm exceptions in the same block come back too',
() async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
expect(par.alarmas.vacaciones, isEmpty);
expect(par.alarmas.excepciones, isEmpty);
await aplicarImportacionConfig(
par.radio,
par.alarmas,
backupCon(
alarmas: [alarmaImportada],
vacaciones: [
{
'id': 'vac1',
'nombre': 'Verano',
'inicio': '2026-07-01T00:00:00.000',
'fin': '2026-07-15T00:00:00.000',
'activo': true,
},
],
excepciones: [
{
'alarmaId': 'importada',
'ejecucion': '2026-08-30T08:15:00.000',
'tipo': 'skipNext',
},
],
),
);
expect(par.alarmas.vacaciones.map((v) => v.id), ['vac1']);
expect(par.alarmas.excepciones.map((e) => e.alarmaId), ['importada']);
},
);
test('a failed import (e.g. malformed/unsupported version) leaves existing '
'alarms untouched', () async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
final backupNoSoportado = backupCon(alarmas: [alarmaImportada])
..['version'] = 99;
// Runs the SAME production function the call site uses: a throw from
// `importarConfig` must propagate before either reload call runs.
await expectLater(
aplicarImportacionConfig(par.radio, par.alarmas, backupNoSoportado),
throwsA(anything),
);
expect(par.alarmas.alarmas.map((a) => a.id), ['vieja']);
expect(par.android.programadas.map((a) => a.id), ['vieja']);
});
test('a cancelled import (dialog declined, importarConfig never called) '
'leaves existing alarms untouched', () async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
// Simulates the user declining the confirm dialog: the call site
// returns before `importarConfig` and the two reload calls ever run.
expect(par.alarmas.alarmas.map((a) => a.id), ['vieja']);
expect(par.android.programadas.map((a) => a.id), ['vieja']);
});
test('regression: importing still restores preferences (ordenListas) '
'exactly as before', () async {
final par = await crearPar();
addTearDown(par.radio.dispose);
addTearDown(par.alarmas.dispose);
addTearDown(par.android.dispose);
await aplicarImportacionConfig(
par.radio,
par.alarmas,
backupCon(alarmas: [alarmaImportada], ordenListas: 'nombre'),
);
expect(par.radio.ordenListas.name, 'nombre');
});
}
@@ -0,0 +1,164 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_alarmas.dart';
import 'package:pluriwave/modelos/alarma_musical.dart';
import 'package:pluriwave/servicios/servicio_alarmas.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes_alarmas.dart';
/// Reported twice on-device: "Posponer" on the pre-notice notification left
/// the alarm snoozed 1400+ minutes — a whole day — instead of the configured
/// few minutes.
///
/// The first fix (7054a4c) guarded the NATIVE anchor, and it was not enough,
/// because Dart runs AFTERWARDS on this path: the receiver's `postponeNext`
/// fires, then `startActivity`, then `app.dart` dispatches here, and this
/// method persists and reschedules. Whatever Dart computes is the value that
/// survives. It was the last snooze path with no occurrence guard at all.
///
/// It also cannot simply reuse `_ocurrenciaSonando`: the pre-notice's
/// occurrence legitimately has NOT arrived yet (the reminder is armed 30 min
/// ahead), so the ringing-screen guard would reject a perfectly good anchor.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
SharedPreferences.setMockInitialValues({});
});
AlarmaMusical diaria(String id) => AlarmaMusical(
id: id,
nombre: 'Mañana',
hora: 16,
minuto: 20,
tipoProgramacion: TipoProgramacionAlarma.diaria,
diasSemana: const [],
snoozeMinutos: 5,
);
({EstadoAlarmas estado, FakePuertoAlarmasAndroid android}) montar(
DateTime Function() reloj,
) {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: reloj),
android: android,
iniciarAutomaticamente: false,
);
addTearDown(estado.dispose);
addTearDown(android.dispose);
return (estado: estado, android: android);
}
test('una ocurrencia del DÍA SIGUIENTE se rechaza: pospone minutos, '
'no 24 horas', () async {
// The exact reported shape. The pre-notice for today's 16:20 is on
// screen at 16:16; the anchor handed in points at TOMORROW (either the
// native spec was already advanced, or app.dart fell back to a
// proximaEjecucion that had moved on).
var ahora = DateTime(2026, 8, 3, 16, 0);
final m = montar(() => ahora);
await m.estado.guardarAlarma(diaria('p1'));
ahora = DateTime(2026, 8, 3, 16, 16);
await m.estado.posponerProximaDesdePreaviso(
m.estado.alarmas.single,
5,
DateTime(2026, 8, 4, 16, 20), // <- tomorrow
);
final snooze = m.estado.alarmas.single.snoozeHasta!;
final minutos = snooze.difference(ahora).inMinutes;
expect(
minutos,
lessThan(60),
reason:
'la alarma quedó a $minutos min ($snooze). El reporte fue "más de '
'1400 minutos"; cualquier cosa por encima de una hora es el mismo bug',
);
expect(
m.estado.alarmas.single.snoozeOrigen,
isNot(DateTime(2026, 8, 4, 16, 20)),
reason:
'el ancla sin validar también se guarda como snoozeOrigen y como '
'ultimaEjecucionGestionada — envenenaría el estado que a9da855 y '
'0430059 existen para mantener limpio',
);
});
test('la ocurrencia REAL del preaviso se respeta aunque esté en el futuro: '
'ancla en la ocurrencia + N, no en ahora + N', () async {
// The whole reason this path needs its own guard instead of reusing
// _ocurrenciaSonando: 30 minutes ahead is legitimate here.
var ahora = DateTime(2026, 8, 3, 16, 0);
final m = montar(() => ahora);
await m.estado.guardarAlarma(diaria('p2'));
// Pre-notice fires at 15:50; the user taps at 15:52, 28 min before.
ahora = DateTime(2026, 8, 3, 15, 52);
await m.estado.posponerProximaDesdePreaviso(
m.estado.alarmas.single,
5,
DateTime(2026, 8, 3, 16, 20),
);
expect(m.estado.alarmas.single.snoozeHasta, DateTime(2026, 8, 3, 16, 25));
expect(m.estado.alarmas.single.snoozeOrigen, DateTime(2026, 8, 3, 16, 20));
});
test('un snooze ya envenenado en disco se cura al recalcular', () async {
// Devices that ran the buggy build carry snoozeHasta = tomorrow in
// SharedPreferences. Without healing it, the alarm keeps reporting
// tomorrow on every tick and the user sees no change after updating.
final ahora = DateTime(2026, 8, 3, 16, 0);
final servicio = ServicioAlarmas(reloj: () => ahora);
await servicio.guardarAlarma(
diaria('p4').copyWith(
snoozeHasta: DateTime(2026, 8, 4, 16, 25),
snoozeOrigen: DateTime(2026, 8, 4, 16, 20),
),
);
final alarma = (await servicio.recalcularTodas()).alarmas.single;
expect(alarma.snoozeHasta, isNull);
expect(alarma.proximaProgramable, DateTime(2026, 8, 3, 16, 20));
});
test('un snooze legítimo de 2 horas NO se toca', () async {
// posponerEjecucion clamps to 120 minutes, so the ceiling has to sit
// above that or the heal would eat real snoozes.
final ahora = DateTime(2026, 8, 3, 16, 0);
final servicio = ServicioAlarmas(reloj: () => ahora);
final hasta = DateTime(2026, 8, 3, 18, 0);
await servicio.guardarAlarma(
diaria('p5').copyWith(snoozeHasta: hasta, snoozeOrigen: ahora),
);
expect(
(await servicio.recalcularTodas()).alarmas.single.snoozeHasta,
hasta,
);
});
test('un ancla absurdamente lejana cae a la ocurrencia propia de la alarma, '
'no a un valor inventado', () async {
var ahora = DateTime(2026, 8, 3, 16, 0);
final m = montar(() => ahora);
await m.estado.guardarAlarma(diaria('p3'));
ahora = DateTime(2026, 8, 3, 16, 10);
await m.estado.posponerProximaDesdePreaviso(
m.estado.alarmas.single,
5,
DateTime(2027, 1, 1, 16, 20), // absurd
);
// proximaEjecucion (today 16:20) is inside the pre-notice window, so it
// is the right fallback and the snooze lands on 16:25.
expect(m.estado.alarmas.single.snoozeHasta, DateTime(2026, 8, 3, 16, 25));
});
}
@@ -36,6 +36,7 @@ void main() {
var ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -74,6 +75,7 @@ void main() {
final android = FakePuertoAlarmasAndroid();
final servicio = ServicioAlarmas(reloj: () => ahora);
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: servicio,
android: android,
iniciarAutomaticamente: false,
@@ -113,6 +115,7 @@ void main() {
var ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -139,6 +142,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -182,6 +186,7 @@ void main() {
var ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -231,6 +236,7 @@ void main() {
),
);
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: servicio,
android: android,
iniciarAutomaticamente: false,
@@ -250,6 +256,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -274,6 +281,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 36);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -307,6 +315,7 @@ void main() {
var ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -337,6 +346,7 @@ void main() {
var ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -363,6 +373,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -393,6 +404,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -423,6 +435,7 @@ void main() {
final ahora = DateTime(2026, 6, 11, 7, 32);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
+27
View File
@@ -20,6 +20,7 @@ void main() {
var ahora = DateTime(2026, 5, 25, 7, 31);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -63,6 +64,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -100,6 +102,7 @@ void main() {
test('finalizar diaria calcula siguiente dia y limpia snooze', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -132,6 +135,7 @@ void main() {
test('finalizar unica la desactiva y queda sin proxima ejecucion', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -163,6 +167,7 @@ void main() {
final android =
FakePuertoAlarmasAndroid()..ignoraOptimizacionBateria = false;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -201,6 +206,7 @@ void main() {
test('no solicita exencion de bateria cuando ya esta exenta', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -227,6 +233,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -256,6 +263,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -284,6 +292,7 @@ void main() {
'(SS-1c, guardia de regresion)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -312,6 +321,7 @@ void main() {
'falla (fail-toward-silence, regresion de eliminarAlarma)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -342,6 +352,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -371,6 +382,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -410,6 +422,7 @@ void main() {
'(SS-2a)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -438,6 +451,7 @@ void main() {
'(SS-2b)', () async {
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -464,6 +478,7 @@ void main() {
'exito (SS-3b)', () async {
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -495,6 +510,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -522,6 +538,7 @@ void main() {
test('evento nativo missed completa la ejecucion (Phase 6)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
android: android,
iniciarAutomaticamente: false,
@@ -587,6 +604,7 @@ void main() {
);
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: servicio,
android: android,
iniciarAutomaticamente: false,
@@ -617,6 +635,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid()..fallaProgramar = true;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -647,6 +666,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid()..fallaProgramar = true;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -676,6 +696,7 @@ void main() {
() async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -730,6 +751,7 @@ void main() {
);
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: servicio,
android: android,
iniciarAutomaticamente: false,
@@ -756,6 +778,7 @@ void main() {
'calza (fixed ahora)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 7, 10)),
android: android,
iniciarAutomaticamente: false,
@@ -783,6 +806,7 @@ void main() {
'ambas son disjuntas del rango activo', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 7, 10)),
android: android,
iniciarAutomaticamente: false,
@@ -838,6 +862,7 @@ void main() {
'(servicio_programacion_alarmas.dart)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 7, 10)),
android: android,
iniciarAutomaticamente: false,
@@ -894,6 +919,7 @@ void main() {
'no afectadas', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 7, 10)),
android: android,
iniciarAutomaticamente: false,
@@ -930,6 +956,7 @@ void main() {
'pureza — son solo lectura sobre _alarmas/_vacaciones)', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 7, 10)),
android: android,
iniciarAutomaticamente: false,
@@ -25,6 +25,7 @@ void main() {
// actually persisting the registration.
final android = FakePuertoAlarmasAndroid()..alarmasNativasPendientes = 0;
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -53,6 +54,7 @@ void main() {
'fallo alguno', () async {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7)),
android: android,
iniciarAutomaticamente: false,
@@ -118,6 +120,7 @@ void main() {
);
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: servicio,
android: android,
iniciarAutomaticamente: false,

Some files were not shown because too many files have changed in this diff Show More