recheckGate method
Re-evaluates this slot against the current gate, right now, and repairs a live/warm ad that no longer matches it.
Two things can make a mounted or warm ad wrong:
- Permission went away (Remove-Ads bought, consent withdrawn, the
owning
AdFlowdisposed) — the ad is dropped. An idle slot that is newly permitted starts a load. - Consent changed (a consent / privacy-options mutation bumps the internal consent generation) — an ad requested under the old consent is privacy-stale even though showing it makes no new request: its impression and measurement still reflect the old choice. So a warm full-screen ad, or a visible banner/native ad, is DROPPED and reloaded through the fresh gate. A full-screen ad already ON SCREEN is NOT interrupted — its impression already happened — but the next one it preloads on dismissal goes through the fresh gate.
AdFlow calls this on every controller after disableAds/enableAds,
after any consent mutation, and on dispose(). Apps normally never need
to call it, but it is safe to call at any time (2026-07 audit).
Implementation
@override
Future<void> recheckGate() async {
if (_disposed) return;
final state = _state.value;
if (state is AdLoaded) {
// A warm ad requested under a now-stale consent generation
// (consent/privacy changed but ads are still permitted, so the
// permission check below would pass) must be dropped and reloaded under
// the fresh gate, or it would show a stale-consent impression (release
// gate #2). This is the already-warm counterpart of the mid-load check
// in load(); one internal mechanism.
if (_loadedGeneration != _gate.consentGeneration) {
discardCurrentAd();
return;
}
// Cheap current checks only (enabled + live canRequestAds) — the warm
// ad already passed the full load gate; this asks "is it STILL
// permitted?" (Remove-Ads bought, consent withdrawn, graph disposed).
final blocked = await _gate.showBlockReason(slot);
if (_disposed || blocked == null) return;
// Indeterminate is not "revoked": a transient channel hiccup while
// re-checking permission must never destroy the perfectly good warm ad
// (4.0 audit). Definite answers (adsDisabled, consentNotGranted) drop.
if (blocked == AdBlockReason.internalError) return;
if (_state.value is! AdLoaded) return; // changed while awaiting
_timer?.cancel();
_dropHandle();
noteBlocked(blocked);
_state.value = AdBlocked(blocked);
_scheduleGateRecheck();
} else if (state is AdIdle || state is AdFailed || state is AdBlocked) {
// The gate may have just (re)opened — load() re-checks it itself, so
// this simply short-circuits the pending backoff.
if (state is AdFailed) _state.value = const AdIdle();
await load();
}
// AdLoading resolves on its own; AdShowing is on screen — the dismiss
// path reloads through the gate anyway.
}