Author SHA1 Message Date
FreeTLab 3ed33c7dbb fix: corregir ecualizador desincronizado, musica local en Android Auto y bloqueo del paywall
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:32:26 +02:00
ShanaiaBot a5572d2cbd chore: bump version to 1.3.1+157 [ci skip] 2026-08-28 23:53:03 +02:00
FreeTLab 98b24d84cd Merge branch 'PRO' of https://git.freetimelab.es/FreeTLab/pluriwave into PRO
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 19s
2026-08-28 23:52:27 +02:00
FreeTLab 72c5777508 ci: name build artifacts by branch and version code [version set]
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:16 +02:00
ShanaiaBot b69041f32a chore: bump version to 1.3.0+156 [ci skip] 2026-08-28 23:40:45 +02:00
FreeTLab 9681a47e83 merge: alarm-import recovery, dismissible paywall and complete config export [version set]
Build & Deploy PluriWave / Análisis de código (push) Successful in 25s
Build & Deploy PluriWave / Build APK + AAB release (push) Failing after 2m1s
Same three fixes already merged to main (e57f7bb, a2bed18, 4ca2813):
alarms actually come back after a backup import and get re-scheduled
natively, the premium sheet can be dismissed, and the equalizer on/off
toggle finally travels with the backup.

[version set] keeps the 1.3.0 release name; CI advances the build number.

# Conflicts:
#	pubspec.yaml
2026-08-28 23:38:15 +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
ShanaiaBot 524b8f0035 chore: bump version to 1.3.0+154 [ci skip] 2026-08-28 19:59:13 +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
163 changed files with 10421 additions and 606 deletions
+139 -4
View File
@@ -109,17 +109,152 @@ 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"
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"
DESTINO="/opt/ftl-builds/builds/pluriwave/v${VERSION}"
SSH_KEY="/Users/freetlab/.openclaw/workspace/.secure/zimaboard_ed25519"
@@ -130,8 +265,8 @@ 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}"
echo "✅ APK: builds.freetimelab.es → pluriwave → v${VERSION} → ${APK_NOMBRE}"
echo "✅ AAB: builds.freetimelab.es → pluriwave → v${VERSION} → ${AAB_NOMBRE}"
- name: Preparar credenciales de Google Play
if: ${{ gitea.ref == 'refs/heads/PRO' }}
+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>
@@ -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,
+54 -3
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 {
@@ -507,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 {
+96 -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 {
@@ -627,12 +707,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 +756,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;
}
}
+29 -6
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,
@@ -801,9 +807,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 +838,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 +853,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();
@@ -926,12 +936,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 +957,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));
}
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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": "ليس الآن"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"alarmDiagnosticsFixAction": "সমাধান করুন",
"alarmDiagnosticsIntentUnavailable": "এই ফোনে সেই সেটিংস স্ক্রিনটি খোলা যায়নি। সেটিংসে ম্যানুয়ালি খুঁজে দেখার চেষ্টা করুন।",
"alarmDiagnosticsUnavailableHint": "আমরা এখনও আপনার অ্যালার্ম সেটিংস পরীক্ষা করতে পারিনি।",
"autoEqDisableOption": "বন্ধ করুন"
"autoEqDisableOption": "বন্ধ করুন",
"funcionPremium": "প্রিমিয়াম বৈশিষ্ট্য",
"limiteAlarmasAlcanzado": "আপনি বিনামূল্যে ৫টি অ্যালার্মের সীমায় পৌঁছেছেন।",
"desbloquearPremium": "প্রিমিয়াম আনলক করুন",
"restaurarCompras": "কেনাকাটা পুনরুদ্ধার করুন",
"compraError": "কেনাকাটা সম্পূর্ণ করা যায়নি। আবার চেষ্টা করুন।",
"restauracionSinCompras": "এই অ্যাকাউন্টে আমরা আগের কোনো কেনাকাটা খুঁজে পাইনি।",
"premiumActivo": "প্রিমিয়াম সক্রিয়",
"premiumHojaTitulo": "PluriWave Premium আনলক করুন",
"premiumBeneficioSinAnuncios": "পুরো অ্যাপে কোনো বিজ্ঞাপন নেই",
"premiumBeneficioAndroidAuto": "Android Auto",
"premiumBeneficioGrabacion": "স্টেশন রেকর্ডিং",
"premiumBeneficioVacaciones": "অ্যালার্মের জন্য ছুটির সময়কাল",
"premiumBeneficioAlarmasIlimitadas": "সীমাহীন অ্যালার্ম (ফ্রি প্ল্যানে সর্বোচ্চ ৫টি অনুমোদিত)",
"premiumPagoUnico": "একবারের পেমেন্ট, চিরকালের জন্য। এটি সাবস্ক্রিপশন নয়।",
"premiumAhoraNo": "এখন নয়"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -856,5 +856,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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": "अभी नहीं"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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": "後で"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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": "Не сейчас"
}
+16 -1
View File
@@ -897,5 +897,20 @@
"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": "以后再说"
}
+90
View File
@@ -3325,6 +3325,96 @@ 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;
}
class _AppLocalizationsDelegate
+48
View File
@@ -1840,4 +1840,52 @@ 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 => 'ليس الآن';
}
+49
View File
@@ -1851,4 +1851,53 @@ 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 => 'এখন নয়';
}
+49
View File
@@ -1864,4 +1864,53 @@ 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';
}
+50
View File
@@ -1843,4 +1843,54 @@ 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';
}
+51
View File
@@ -1857,4 +1857,55 @@ 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';
}
+52
View File
@@ -1870,4 +1870,56 @@ 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';
}
+49
View File
@@ -1844,4 +1844,53 @@ 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 => 'अभी नहीं';
}
+50
View File
@@ -1854,4 +1854,54 @@ 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';
}
+52
View File
@@ -1867,4 +1867,56 @@ 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';
}
+45
View File
@@ -1791,4 +1791,49 @@ 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 => '後で';
}
+50
View File
@@ -1854,4 +1854,54 @@ 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';
}
+50
View File
@@ -1861,4 +1861,54 @@ 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 => 'Не сейчас';
}
+45
View File
@@ -1776,4 +1776,49 @@ 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 => '以后再说';
}
+142 -9
View File
@@ -5,13 +5,18 @@ 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/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';
@@ -84,7 +89,7 @@ Future<void> main() async {
//
// Regression this fixes, self-inflicted by the reordering above: the root
// menu decides whether to offer "Música Local" with
// `fuenteLocal != null && await fuenteLocal.hayCarpetaConfigurada()`.
// `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
@@ -99,11 +104,42 @@ Future<void> main() async {
registrarFuenteMusicaLocal(FuenteMusicaLocalAutoImpl());
// Cosmetic, and deliberately NOT awaited: a display preference must never
// gate `runApp`. `_OrientacionResponsiveApp.didChangeDependencies` applies
// 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();
@@ -116,6 +152,18 @@ Future<void> main() async {
final presetsPersonalizados = ServicioPresetsPersonalizados(prefs: prefs);
registrarFuentePresetsPersonalizados(presetsPersonalizados.listar);
// 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
// drops what it is given — so every exception `audio_service` catches
@@ -144,7 +192,11 @@ 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 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
@@ -154,8 +206,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);
@@ -233,20 +285,80 @@ Future<void> aplicarPoliticaOrientacion({
}
}
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();
@@ -260,6 +372,27 @@ class _OrientacionResponsiveAppState extends State<_OrientacionResponsiveApp>
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: _display));
@@ -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);
+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;
}
}
+130 -16
View File
@@ -229,6 +229,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;
@@ -331,15 +342,58 @@ class ConstructorArbolAuto {
///
/// `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}) => [
/// is configured") — the caller lo deriva de
/// `fuente.estadoCarpeta() != EstadoCarpetaLocal.noConfigurada`
/// (fix/android-auto-musica-local: un canal nativo ausente ya NO oculta el
/// nodo), keeping this builder itself synchronous and side-effect free.
///
/// [premium] (iap-freemium-unlock, Design ADR-4): the ROOT keeps the exact
/// same visible folder labels for every tier — "keeps the same visible
/// folder labels for free users" is the explicit design choice, so a free
/// driver still sees a real, familiar menu rather than a wall of "Función
/// Premium" rows. The lock itself is enforced one level DOWN, at the
/// `getChildren` choke point (see [itemPremiumBloqueado] and
/// [respuestaBloqueadaPorEntitlement] below) — tapping any of these
/// folders as a free user reveals the lock there, never here.
List<MediaItem> raiz({
required bool incluirMusicaLocal,
required bool premium,
}) => [
_carpeta(idFavoritos, 'Favoritos'),
_carpeta(idTodas, 'Todas las emisoras'),
_carpeta(idMisEmisoras, 'Mis emisoras'),
if (incluirMusicaLocal) _carpeta(idMusicaLocal, 'Música Local'),
];
/// Free-tier id prefix reserved id (iap-freemium-unlock, Design ADR-4):
/// the single non-playable item every non-root folder collapses to for a
/// free-tier user. Hardcoded Spanish label, matching every other car-tree
/// label in this file (never routed through `AppLocalizations` —
/// established convention, see [_tituloMasLocal]'s doc).
static const idPremiumInfo = 'premium:info';
/// The single locked item shown for ANY non-root folder when the browsing
/// user is free tier (Design ADR-4, android-auto-media spec "Free-Tier
/// Reduced Root Browse"). Non-playable — selecting it is a no-op, never a
/// crash (Spec "Free-tier user selects a locked item").
MediaItem itemPremiumBloqueado() => MediaItem(
id: idPremiumInfo,
title: 'Función Premium',
playable: false,
extras: _contentStyleLista,
);
/// El item de [idLocalNoLista]. Etiqueta en castellano hardcodeado, como
/// TODAS las etiquetas del árbol del coche en este archivo (ver
/// [itemPremiumBloqueado]): convención establecida, nunca
/// `AppLocalizations`. No reproducible — seleccionarlo es un no-op.
MediaItem itemLocalNoDisponible() => MediaItem(
id: idLocalNoLista,
title: 'Abre PluriWave en el móvil para leer tu música',
playable: false,
extras: _contentStyleLista,
);
MediaItem _carpeta(String id, String titulo) => MediaItem(
id: id,
title: titulo,
@@ -899,6 +953,26 @@ class ConstructorArbolAuto {
}
}
/// Pure Android Auto browse-gate decision (iap-freemium-unlock, Design
/// ADR-4): the AUTHORITATIVE `getChildren` choke point, called BEFORE any
/// other resolution. For the root itself this NEVER blocks (the root always
/// resolves through [ConstructorArbolAuto.raiz] instead, which stays
/// visible for every tier). For any non-root [parentMediaId] and a free-tier
/// [premium], it returns the single locked item regardless of what the id
/// actually is — a stale/deep-linked `emisora:<uuid>` or folder id from
/// before a downgrade is blocked exactly the same way as a legitimate
/// current folder id (android-auto-media spec "Free-Tier Browse Never
/// Leaks Real Content (Authoritative Backstop)"). Returns `null` when the
/// caller should proceed with its normal resolution (root, or premium).
List<MediaItem>? respuestaBloqueadaPorEntitlement({
required String parentMediaId,
required bool premium,
}) {
if (parentMediaId == AudioService.browsableRootId) return null;
if (premium) return null;
return [ConstructorArbolAuto().itemPremiumBloqueado()];
}
/// 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
@@ -936,15 +1010,26 @@ Future<void> reproducirPorMediaId(
await reproducir(item);
}
/// Which list previous/next should walk for [actual]: the NARROWEST list the
/// station actually belongs to, favourites first, then my stations, then the
/// full catalogue.
/// Which list previous/next should walk for [actual]: the NARROWEST context
/// the station belongs to.
///
/// Narrowest-first is the point. "Next station" while playing a favourite
/// should land on the next favourite, not 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
/// working for a station reached by search.
/// 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".
@@ -954,10 +1039,28 @@ List<Emisora> listaParaSaltoEmisora({
required List<Emisora> misEmisoras,
required List<Emisora> todas,
}) {
bool contiene(List<Emisora> lista) => lista.any((e) => e.uuid == actual.uuid);
if (contiene(favoritos)) return favoritos;
if (contiene(misEmisoras)) return misEmisoras;
if (contiene(todas)) return 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 delGrupo;
}
return favoritos;
}
if (enLista(misEmisoras) != null) return misEmisoras;
if (enLista(todas) != null) return todas;
return const [];
}
@@ -1505,13 +1608,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 [];
}
+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
+2 -5
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';
@@ -89,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)
+40 -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,24 @@ 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);
}
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;
}
+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.20+142
version: 1.3.1+157
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,203 @@
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';
/// 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();
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 = PluriWaveAudioHandler();
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 = PluriWaveAudioHandler();
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 = PluriWaveAudioHandler();
registrarHandler(handler);
expect(hayCocheSuscritoAlArbol(), isFalse);
handler.subscribeToChildren(AudioService.browsableRootId);
expect(hayCocheSuscritoAlArbol(), isTrue);
});
});
}
@@ -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',
);
});
}
}
@@ -46,6 +46,7 @@ void main() {
var ahora = DateTime(2026, 8, 3, 16, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -151,6 +152,7 @@ void main() {
var ahora = DateTime(2026, 8, 3, 9, 0);
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: () => ahora),
android: android,
iniciarAutomaticamente: false,
@@ -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');
});
}
@@ -41,6 +41,7 @@ void main() {
) {
final android = FakePuertoAlarmasAndroid();
final estado = EstadoAlarmas(
esPremium: () => true,
servicio: ServicioAlarmas(reloj: reloj),
android: android,
iniciarAutomaticamente: false,
@@ -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,
+217
View File
@@ -33,6 +33,7 @@ void main() {
test('EQ preset change does NOT rebuild EstadoRadio listeners '
'(S4-R1-A, S4-R5)', () async {
final estado = EstadoRadio(
esPremium: () => true,
audio: FakeServicioAudio(),
favoritos: FakeServicioFavoritos(),
radio: FakeServicioRadio(),
@@ -1568,6 +1569,83 @@ void main() {
});
});
group(
'EstadoEcualizador — importarConfiguracion(activo:) '
'(equalizer on/off export/import gap)',
() {
test(
'activo: false turns the equalizer off — persisted AND pushed to '
'the live audio engine (reuses cambiarActivo, not a bare field set)',
() async {
final servicio = FakeServicioEcualizador(activo: true);
final audio = FakeServicioAudio();
final eq = EstadoEcualizador(audio: audio, servicio: servicio);
await eq.cargarPersistido();
audio.cambiosEcualizadorActivo.clear();
await eq.importarConfiguracion(
principal: PresetEcualizador.flat,
porEmisora: {},
activo: false,
);
expect(eq.activo, isFalse);
expect(audio.cambiosEcualizadorActivo, contains(false));
expect(servicio.config.activo, isFalse);
expect(servicio.guardarActivoLlamadas, 1);
eq.dispose();
},
);
test(
'activo: true turns the equalizer on — persisted AND pushed to '
'the live audio engine',
() async {
final servicio = FakeServicioEcualizador(activo: false);
final audio = FakeServicioAudio();
final eq = EstadoEcualizador(audio: audio, servicio: servicio);
await eq.cargarPersistido();
audio.cambiosEcualizadorActivo.clear();
await eq.importarConfiguracion(
principal: PresetEcualizador.flat,
porEmisora: {},
activo: true,
);
expect(eq.activo, isTrue);
expect(audio.cambiosEcualizadorActivo, contains(true));
expect(servicio.config.activo, isTrue);
expect(servicio.guardarActivoLlamadas, 1);
eq.dispose();
},
);
test(
'activo: null (old backup, no field) leaves the current toggle '
'untouched and does not persist anything for it',
() async {
final servicio = FakeServicioEcualizador(activo: false);
final audio = FakeServicioAudio();
final eq = EstadoEcualizador(audio: audio, servicio: servicio);
await eq.cargarPersistido();
audio.cambiosEcualizadorActivo.clear();
await eq.importarConfiguracion(
principal: PresetEcualizador.flat,
porEmisora: {},
// activo omitted — simulates a pre-v4 backup.
);
expect(eq.activo, isFalse);
expect(audio.cambiosEcualizadorActivo, isEmpty);
expect(servicio.guardarActivoLlamadas, 0);
eq.dispose();
},
);
},
);
group('EstadoEcualizador — bonded Bluetooth names', () {
const deviceId = 'bt_a2dp:AA:BB:CC:DD:EE:FF';
@@ -1727,6 +1805,145 @@ void main() {
eq.dispose();
});
});
// ---------------------------------------------------------------------------
// eq-sync-superficies: car/notification-initiated EQ changes must reach
// EstadoEcualizador (and persist through ServicioEcualizador), not just
// the audio handler.
// ---------------------------------------------------------------------------
group('EstadoEcualizador — resync with handler-initiated EQ changes '
'(eq-sync-superficies)', () {
test(
'a handler-initiated toggle (car/notification) syncs activo and '
'notifies listeners',
() async {
final fakeAudio = FakeServicioAudio();
final eq = EstadoEcualizador(
audio: fakeAudio,
servicio: FakeServicioEcualizador(activo: true),
);
await eq.cargarPersistido();
expect(eq.activo, isTrue);
var avisos = 0;
eq.addListener(() => avisos++);
// Simulates `accionEqToggle` calling
// `PluriWaveAudioHandler.setEcualizadorActivo` directly, bypassing
// `ServicioAudio`/`EstadoEcualizador` entirely.
fakeAudio.simularCambioEqDesdeHandler(activo: false);
await Future<void>.delayed(const Duration(milliseconds: 50));
expect(eq.activo, isFalse);
expect(avisos, greaterThanOrEqualTo(1));
eq.dispose();
},
);
test(
'a handler-initiated preset change (Android Auto) syncs presetActual '
'and notifies listeners',
() async {
final fakeAudio = FakeServicioAudio();
final eq = EstadoEcualizador(
audio: fakeAudio,
servicio: FakeServicioEcualizador(principal: PresetEcualizador.flat),
);
await eq.cargarPersistido();
expect(eq.presetActual, equals(PresetEcualizador.flat));
var avisos = 0;
eq.addListener(() => avisos++);
// Simulates `seleccionarPresetEqPorMediaId` calling
// `PluriWaveAudioHandler.aplicarPreset` directly.
fakeAudio.simularCambioEqDesdeHandler(preset: PresetEcualizador.jazz);
await Future<void>.delayed(const Duration(milliseconds: 50));
expect(eq.presetActual, equals(PresetEcualizador.jazz));
expect(avisos, greaterThanOrEqualTo(1));
eq.dispose();
},
);
test(
'a handler-initiated toggle is ADOPTED for display and NOT written '
'again from here (eq-estado-unico: the handler owns the write)',
() async {
final fakeAudio = FakeServicioAudio();
final fakeServicio = FakeServicioEcualizador(activo: true);
final eq = EstadoEcualizador(audio: fakeAudio, servicio: fakeServicio);
await eq.cargarPersistido();
fakeAudio.simularCambioEqDesdeHandler(activo: false);
await Future<void>.delayed(const Duration(milliseconds: 50));
expect(
eq.activo,
isFalse,
reason: 'the phone toggle must show what the engine is really doing',
);
expect(
fakeServicio.guardarActivoLlamadas,
equals(0),
reason:
'persistence moved to PluriWaveAudioHandler itself, because '
'this resync only exists while an EstadoEcualizador does — and '
'on the headless Android Auto engine that produced the bug, '
'none ever does. A second write from here would be a second '
'owner of the same fact.',
);
eq.dispose();
},
);
test(
'resync does not cause an extra handler write (no feedback loop)',
() async {
final fakeAudio = FakeServicioAudio();
final eq = EstadoEcualizador(
audio: fakeAudio,
servicio: FakeServicioEcualizador(activo: true),
);
await eq.cargarPersistido();
fakeAudio.cambiosEcualizadorActivo.clear();
fakeAudio.presetsAplicados.clear();
fakeAudio.simularCambioEqDesdeHandler(activo: false);
await Future<void>.delayed(const Duration(milliseconds: 50));
// The resync must only read from `audio` and write to `servicio` —
// never write BACK into `audio`, or a handler write would trigger
// another stream tick, which would resync again, forever.
expect(fakeAudio.cambiosEcualizadorActivo, isEmpty);
expect(fakeAudio.presetsAplicados, isEmpty);
eq.dispose();
},
);
test(
'a UI-initiated toggle still works exactly as before and persists '
'exactly once (regression)',
() async {
final fakeAudio = FakeServicioAudio();
final fakeServicio = FakeServicioEcualizador(activo: true);
final eq = EstadoEcualizador(audio: fakeAudio, servicio: fakeServicio);
await eq.cargarPersistido();
fakeAudio.cambiosEcualizadorActivo.clear();
await eq.cambiarActivo(false);
// Give any (harmless, no-op) resync tick a chance to run too.
await Future<void>.delayed(const Duration(milliseconds: 50));
expect(eq.activo, isFalse);
expect(fakeServicio.config.activo, isFalse);
expect(fakeServicio.guardarActivoLlamadas, equals(1));
expect(fakeAudio.cambiosEcualizadorActivo, equals([false]));
eq.dispose();
},
);
});
}
/// Fake whose [guardarActivo] stays pending until released, and releases the
+353
View File
@@ -0,0 +1,353 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_entitlement.dart';
import 'package:pluriwave/servicios/servicio_compras.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Fake [PuertoCompras] (Design ADR-2): never touches `in_app_purchase`,
/// lets each test drive [emitir] to simulate the purchase stream.
class _PuertoComprasFalso implements PuertoCompras {
final _eventos = StreamController<EventoCompra>.broadcast();
int comprasIntentadas = 0;
int restaurosIntentados = 0;
@override
Stream<EventoCompra> get eventos => _eventos.stream;
@override
Future<void> comprar() async {
comprasIntentadas++;
}
@override
Future<void> restaurar() async {
restaurosIntentados++;
}
void emitir(EventoCompra evento) => _eventos.add(evento);
Future<void> dispose() => _eventos.close();
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
SharedPreferences.setMockInitialValues({});
});
group('EstadoEntitlement', () {
test('por defecto es free (sin flag persistida)', () async {
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isFalse);
});
test('carga premium desde una flag persistida previamente', () async {
SharedPreferences.setMockInitialValues({'compra_premium_v1': true});
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isTrue);
});
test('comprar() con éxito desbloquea premium y persiste', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final prefs = await SharedPreferences.getInstance();
final estado = EstadoEntitlement(prefs: prefs, compras: compras);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
var notificaciones = 0;
estado.addListener(() => notificaciones++);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.comprada));
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isTrue);
expect(estado.compraEnCurso, isFalse);
expect(compras.comprasIntentadas, 1);
expect(prefs.getBool('compra_premium_v1'), isTrue);
expect(notificaciones, greaterThan(0));
});
test('comprar() cancelada deja el tier free sin cargo', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.cancelada));
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isFalse);
expect(estado.compraEnCurso, isFalse);
});
test(
'comprar() ya premium es idempotente: no reintenta la compra',
() async {
SharedPreferences.setMockInitialValues({'compra_premium_v1': true});
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
await estado.comprar();
expect(compras.comprasIntentadas, 0);
expect(estado.esPremium, isTrue);
},
);
test('restaurar() encuentra una compra y desbloquea premium', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.restaurar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.restaurada));
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isTrue);
expect(compras.restaurosIntentados, 1);
});
test('restaurar() sin compra previa mantiene free sin error', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.restaurar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
await Future<void>.delayed(Duration.zero);
expect(estado.esPremium, isFalse);
expect(estado.compraEnCurso, isFalse);
});
test('tras restaurar() sin compras el paywall NO queda bloqueado: se '
'puede volver a comprar', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.restaurar());
await Future<void>.delayed(Duration.zero);
expect(estado.compraEnCurso, isTrue);
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
await Future<void>.delayed(Duration.zero);
// `compraEnCurso` deshabilita AMBOS botones de `hoja_premium.dart`
// (comprar y restaurar): si se queda pegado en `true`, el usuario ya no
// puede pagar nunca más.
expect(estado.compraEnCurso, isFalse);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
expect(compras.comprasIntentadas, 1);
});
test(
'un error en el flujo de compra no bloquea al pagador (fail-open)',
() async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.error));
await Future<void>.delayed(Duration.zero);
// Fail-open: un error NUNCA escribe `false` sobre una flag ya premium,
// y tampoco inventa un `true` para un usuario free.
expect(estado.esPremium, isFalse);
},
);
group('resultadoUsuario (FIX 3, code review)', () {
test(
'un error en el flujo de compra expone ResultadoEntitlementUsuario.error',
() async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
expect(estado.resultadoUsuario, isNull);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.error));
await Future<void>.delayed(Duration.zero);
expect(estado.resultadoUsuario, ResultadoEntitlementUsuario.error);
},
);
test('restaurar() sin compra previa expone su propio resultado '
'(restauracionSinCompras), distinto de un error', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.restaurar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
await Future<void>.delayed(Duration.zero);
expect(
estado.resultadoUsuario,
ResultadoEntitlementUsuario.restauracionSinCompras,
);
expect(
estado.resultadoUsuario,
isNot(ResultadoEntitlementUsuario.error),
);
});
test('consumirResultadoUsuario() limpia la señal y notifica a los '
'listeners', () async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.error));
await Future<void>.delayed(Duration.zero);
expect(estado.resultadoUsuario, isNotNull);
var notificaciones = 0;
estado.addListener(() => notificaciones++);
estado.consumirResultadoUsuario();
expect(estado.resultadoUsuario, isNull);
expect(notificaciones, greaterThan(0));
// También se limpia (probado por separado) el resultado de una
// restauración sin compras.
unawaited(estado.restaurar());
await Future<void>.delayed(Duration.zero);
compras.emitir(const EventoCompra(TipoEventoCompra.noEncontrada));
await Future<void>.delayed(Duration.zero);
expect(estado.resultadoUsuario, isNotNull);
estado.consumirResultadoUsuario();
expect(estado.resultadoUsuario, isNull);
});
test(
'nunca expone el texto interno/de desarrollador de EventoCompra.mensaje',
() async {
final compras = _PuertoComprasFalso();
addTearDown(compras.dispose);
final estado = EstadoEntitlement(
prefs: await SharedPreferences.getInstance(),
compras: compras,
);
addTearDown(estado.dispose);
await Future<void>.delayed(Duration.zero);
unawaited(estado.comprar());
await Future<void>.delayed(Duration.zero);
compras.emitir(
const EventoCompra(
TipoEventoCompra.error,
mensaje: 'Producto no encontrado en Play Console',
),
);
await Future<void>.delayed(Duration.zero);
// resultadoUsuario es un enum tipado -- estructuralmente incapaz
// de filtrar el string interno de EventoCompra.mensaje hacia la
// UI.
expect(estado.resultadoUsuario, ResultadoEntitlementUsuario.error);
},
);
});
});
group('esPremiumPersistido (headless, sin BuildContext)', () {
test('lee la flag persistida directamente desde prefs', () async {
SharedPreferences.setMockInitialValues({'compra_premium_v1': true});
final prefs = await SharedPreferences.getInstance();
expect(await esPremiumPersistido(prefs: prefs), isTrue);
});
test('por defecto (sin flag) resuelve a free', () async {
final prefs = await SharedPreferences.getInstance();
expect(await esPremiumPersistido(prefs: prefs), isFalse);
});
test(
'resuelve sin prefs inyectadas (SharedPreferences.getInstance)',
() async {
SharedPreferences.setMockInitialValues({'compra_premium_v1': true});
expect(await esPremiumPersistido(), isTrue);
},
);
});
}
@@ -0,0 +1,57 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_grabacion.dart';
import 'package:pluriwave/modelos/emisora.dart';
/// Reported: recording a station stopped working, 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 the message is a LOCAL MP3, not a station.
/// `PluriWaveAudioHandler._cambiarFuente` sets `emisoraActual` for every
/// source it plays, so a local track becomes an `Emisora` whose `url` is the
/// SAF `content://` document URI it was opened from. The recorder then tried
/// to open that as an HTTP stream.
///
/// "It used to work" is accurate: before local music playback existed,
/// whatever was playing was always a real station, so this could not happen.
void main() {
Emisora conUrl(String url) => Emisora(uuid: 'u', nombre: 'n', url: url);
test('un stream de red es grabable', () {
expect(esEmisoraGrabable(conUrl('http://stream.example.com/live')), isTrue);
expect(
esEmisoraGrabable(conUrl('https://stream.example.com/live')),
isTrue,
);
expect(
esEmisoraGrabable(conUrl('HTTPS://STREAM.EXAMPLE.COM/live')),
isTrue,
reason: 'el esquema no distingue mayúsculas',
);
});
test('la URI content:// de una pista local NO es grabable — el caso '
'exacto del reporte', () {
expect(
esEmisoraGrabable(
conUrl(
'content://com.android.externalstorage.documents/tree/'
'primary%3AMusic/document/primary%3AMusic%2FNew%20Limit%20-%20'
'Smile.mp3',
),
),
isFalse,
);
});
test('ni un fichero local, ni una url vacía o rota', () {
expect(
esEmisoraGrabable(conUrl('file:///storage/emulated/0/a.mp3')),
isFalse,
);
expect(esEmisoraGrabable(conUrl('')), isFalse);
expect(esEmisoraGrabable(conUrl('no es una uri')), isFalse);
});
}
@@ -0,0 +1,99 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_grabacion.dart';
import 'package:pluriwave/modelos/emisora.dart';
import 'package:pluriwave/servicios/servicio_grabacion_radio.dart';
import '../helpers/fakes.dart';
/// Freemium gating (freemium-gating spec "Recording Start Gated, Management
/// Stays Free"): starting a NEW recording requires premium; management of
/// already-existing recordings (listing/playing/deleting — untouched by
/// this file) stays free regardless.
void main() {
test(
'free tier: iniciar() no llama al servicio y reporta requierePremium',
() async {
final servicio = _ServicioGrabacionControlado();
final emisora = emisoraDemo(uuid: 'rec-1', nombre: 'Grabable');
final estado = EstadoGrabacion(
servicio: servicio,
emisoraActual: () => emisora,
esPremium: () => false,
);
addTearDown(estado.dispose);
final resultado = await estado.iniciar();
expect(resultado, ResultadoIniciarGrabacion.requierePremium);
expect(servicio.inicios, 0);
},
);
test('premium: iniciar() delega en el servicio normalmente', () async {
final servicio = _ServicioGrabacionControlado();
final emisora = emisoraDemo(uuid: 'rec-2', nombre: 'Grabable');
final estado = EstadoGrabacion(
servicio: servicio,
emisoraActual: () => emisora,
esPremium: () => true,
);
addTearDown(estado.dispose);
final resultado = await estado.iniciar(
duracion: const Duration(minutes: 1),
);
expect(resultado, ResultadoIniciarGrabacion.iniciada);
expect(servicio.inicios, 1);
});
// `esPremium` is a required parameter, so "no entitlement callback" is no
// longer a reachable state to test; what stays worth covering is the
// premium path through `iniciar()` with no explicit `duracion`.
test('premium: iniciar() sin duracion tambien delega', () async {
final servicio = _ServicioGrabacionControlado();
final emisora = emisoraDemo(uuid: 'rec-3', nombre: 'Grabable');
final estado = EstadoGrabacion(
esPremium: () => true,
servicio: servicio,
emisoraActual: () => emisora,
);
addTearDown(estado.dispose);
final resultado = await estado.iniciar();
expect(resultado, ResultadoIniciarGrabacion.iniciada);
expect(servicio.inicios, 1);
});
}
class _ServicioGrabacionControlado extends ServicioGrabacionRadio {
final _controller = StreamController<EstadoGrabacionRadio>.broadcast();
final EstadoGrabacionRadio _estadoActual =
const EstadoGrabacionRadio.inactiva();
int inicios = 0;
@override
EstadoGrabacionRadio get estado => _estadoActual;
@override
Stream<EstadoGrabacionRadio> get estadoStream => _controller.stream;
@override
Future<void> inicializar() async {}
@override
Future<void> iniciar(
Emisora emisora, {
Duration? duracion,
String? directorio,
}) async {
inicios++;
}
@override
Future<void> dispose() => _controller.close();
}
+8 -2
View File
@@ -12,7 +12,7 @@ import '../helpers/fakes.dart';
void main() {
test('notifica listeners cuando cambia el estado de grabación', () async {
final servicio = _ServicioGrabacionControlado();
final estado = EstadoGrabacion(servicio: servicio);
final estado = EstadoGrabacion(esPremium: () => true, servicio: servicio);
addTearDown(estado.dispose);
var notificaciones = 0;
@@ -36,6 +36,7 @@ void main() {
final servicio = _ServicioGrabacionControlado();
final emisora = emisoraDemo(uuid: 'rec-2', nombre: 'Actual');
final estado = EstadoGrabacion(
esPremium: () => true,
servicio: servicio,
emisoraActual: () => emisora,
);
@@ -54,6 +55,7 @@ void main() {
final servicio = _ServicioGrabacionControlado();
final errores = <String>[];
final estado = EstadoGrabacion(
esPremium: () => true,
servicio: servicio,
emisoraActual: () => null,
alError: errores.add,
@@ -70,7 +72,11 @@ void main() {
test('un estado de error del servicio se reporta vía alError', () async {
final servicio = _ServicioGrabacionControlado();
final errores = <String>[];
final estado = EstadoGrabacion(servicio: servicio, alError: errores.add);
final estado = EstadoGrabacion(
servicio: servicio,
alError: errores.add,
esPremium: () => true,
);
addTearDown(estado.dispose);
servicio.emitir(
@@ -0,0 +1,171 @@
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_radio.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes.dart';
import '../helpers/fakes_alarmas.dart';
/// Closes the last remaining export/import gap: `EstadoEcualizador._activo`
/// (the equalizer's global ON/OFF toggle) was not part of the backup
/// envelope at all, so restoring a backup on another device silently kept
/// whatever that device's toggle happened to be. These tests exercise the
/// flag end to end through `EstadoRadio.exportarConfig`/`importarConfig`,
/// the real call sites `pantalla_ajustes_backup.dart` uses.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Directory tempDir;
setUp(() async {
SharedPreferences.setMockInitialValues({});
// A PRIVATE per-test file, never the shared `test/fixtures/` one — see
// `estado_alarmas_import_test.dart` for why: `importarConfig`
// unconditionally writes to whatever `resolverArchivoCustom` resolves to.
tempDir = await Directory.systemTemp.createTemp(
'pluriwave_eq_activo_export_test',
);
});
tearDown(() async {
if (tempDir.existsSync()) {
await tempDir.delete(recursive: true);
}
});
Future<EstadoRadio> crearRadio({bool ecualizadorActivo = true}) async {
final prefs = await SharedPreferences.getInstance();
final archivoCustom = File('${tempDir.path}/emisoras_custom.json');
if (!archivoCustom.existsSync()) {
await archivoCustom.writeAsString('[]');
}
final radio = EstadoRadio(
esPremium: () => true,
audio: FakeServicioAudio(),
favoritos: FakeServicioFavoritos(),
radio: FakeServicioRadio(),
servicioEcualizador: FakeServicioEcualizador(activo: ecualizadorActivo),
servicioGrabacion: FakeServicioGrabacionRadioInactiva(),
resolverArchivoCustom: () async => archivoCustom,
prefs: prefs,
iniciarAutomaticamente: false,
);
await radio.ecualizador.cargarPersistido();
return radio;
}
Map<String, dynamic> backupBase({
required int version,
bool? ecualizadorActivo,
}) {
final data = <String, dynamic>{
'version': version,
'gruposFavoritos': [],
'favoritos': [],
'emisorasCustom': [],
'presetsEcualizador': {},
'alarmas': null,
'emisoraPreferidaUuid': null,
'ordenListas': 'nombre',
'timerSuenoPresetsSegundos': <int>[300, 600],
};
if (ecualizadorActivo != null) {
data['ecualizadorActivo'] = ecualizadorActivo;
}
return data;
}
group('EstadoRadio export/import — equalizer on/off toggle (v4)', () {
test('exportarConfig includes the flag when the equalizer is ON', () async {
final radio = await crearRadio(ecualizadorActivo: true);
addTearDown(radio.dispose);
final exportado = await radio.exportarConfig();
expect(exportado['ecualizadorActivo'], isTrue);
expect(exportado['version'], 4);
});
test(
'exportarConfig includes the flag when the equalizer is OFF',
() async {
final radio = await crearRadio(ecualizadorActivo: false);
addTearDown(radio.dispose);
final exportado = await radio.exportarConfig();
expect(exportado['ecualizadorActivo'], isFalse);
expect(exportado['version'], 4);
},
);
test('importarConfig(activo: false) turns the equalizer off — persisted '
'and reflected in EstadoEcualizador.activo', () async {
final radio = await crearRadio(ecualizadorActivo: true);
addTearDown(radio.dispose);
expect(radio.ecualizador.activo, isTrue);
await radio.importarConfig(
backupBase(version: 4, ecualizadorActivo: false),
);
expect(radio.ecualizador.activo, isFalse);
});
test('importarConfig(activo: true) turns the equalizer on — persisted '
'and reflected in EstadoEcualizador.activo', () async {
final radio = await crearRadio(ecualizadorActivo: false);
addTearDown(radio.dispose);
expect(radio.ecualizador.activo, isFalse);
await radio.importarConfig(
backupBase(version: 4, ecualizadorActivo: true),
);
expect(radio.ecualizador.activo, isTrue);
});
test('importing an OLD backup (no ecualizadorActivo field) does not throw '
'and leaves the current toggle untouched', () async {
final radio = await crearRadio(ecualizadorActivo: false);
addTearDown(radio.dispose);
expect(radio.ecualizador.activo, isFalse);
await radio.importarConfig(backupBase(version: 2));
expect(radio.ecualizador.activo, isFalse);
});
test(
'full round-trip: export -> import restores the equalizer toggle',
() async {
final origen = await crearRadio(ecualizadorActivo: false);
addTearDown(origen.dispose);
final exportado = await origen.exportarConfig();
final destino = await crearRadio(ecualizadorActivo: true);
addTearDown(destino.dispose);
expect(destino.ecualizador.activo, isTrue);
await destino.importarConfig(exportado);
expect(destino.ecualizador.activo, isFalse);
},
);
test('regression: other fields still round-trip exactly as before '
'(ordenListas, timerSuenoPresetsSegundos)', () async {
final origen = await crearRadio();
addTearDown(origen.dispose);
await origen.guardarTimerSuenoPresetsSegundos([120, 900]);
final exportado = await origen.exportarConfig();
final destino = await crearRadio();
addTearDown(destino.dispose);
await destino.importarConfig(exportado);
expect(destino.ordenListas.name, origen.ordenListas.name);
});
});
}

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