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.
This commit is contained in:
2026-08-10 20:37:07 +02:00
parent f4a1fac45a
commit aa0b242374
77 changed files with 3757 additions and 72 deletions
+26 -3
View File
@@ -35,14 +35,26 @@ bool esEmisoraGrabable(Emisora emisora) {
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. Defaults to "premium"
// (ungated) so every pre-existing test/call site keeps its exact
// previous behavior — `app.dart` always wires the real callback.
bool Function()? esPremium,
}) : servicio = servicio ?? ServicioGrabacionRadio(),
_emisoraActual = emisoraActual ?? (() => null),
_alError = alError {
_alError = alError,
_esPremium = esPremium ?? (() => true) {
_suscripcion = this.servicio.estadoStream.listen((estado) {
if (estado.tipo == EstadoGrabacionRadioTipo.error &&
estado.error != null) {
@@ -65,6 +77,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;
@@ -87,7 +101,14 @@ 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();
// `emisoraActual` is set by `_cambiarFuente` for EVERY source, local
// tracks included -- a local file becomes an `Emisora` whose `url` is the
@@ -97,12 +118,14 @@ class EstadoGrabacion extends ChangeNotifier {
// 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;
}
}