:library:integration:consent
Purpose
Coordinates user consent state between persisted toolkit preferences and Google's User Messaging Platform (UMP).
Owns
di.consentModule()binds the consent repository and UMP remote source; foundation providers and preferences are supplied by the composing host graph.Consent models in
data/modelsand the repository contract covering apply/request.DefaultConsentRepositoryand the UMP remote data source abstraction/implementation.Mapping host availability into consent behavior.
Does not own
Ads loading/presentation, owned by
:library:integration:ads.Diagnostics screen UI, owned by
:library:feature:diagnostics.Preference storage implementation, owned by
:library:core:datastore.
Depends on
:library:core:commonfor Firebase and shared contracts.:library:core:datastorefor consent preference persistence.:library:core:networkfor shared error/result handling.
Used by
:sampleand:library:apptoolkit.:library:feature:about,:library:feature:onboarding,:library:feature:startup, and:library:feature:settingsfor privacy/diagnostics flows.:library:integration:adsbefore enabling ads.
Flow chart
flowchart TD
UI[Onboarding, privacy, or diagnostics UI] --> Repo[ConsentRepository]
Repo --> Settings[ConsentSettings]
Settings --> Store[Consent preference source]
Host[ConsentHost] --> Availability{Host can show a form?}
Availability -->|no| Rejected[ConsentException: host unavailable]
Availability -->|yes| Flight{Matching request in flight?}
Repo --> Flight
Flight -->|yes| Join[Await the shared round trip]
Flight -->|no| UMP[UmpConsentRemoteDataSource]
UMP --> Refresh[UMP consent-info refresh]
Refresh --> Callback{Form required or explicitly requested?}
Callback -->|yes and host still valid| Form[Show consent form]
Callback -->|no| Result[Request completes or throws]
Form --> Result
Result --> Store
Result --> Firebase[Firebase consent toggles]
Result --> Ads[Ads consumers]Architectural decisions
ConsentPreferencesDataSource.settings(default)reads every choice from one Preferences emission. Diagnostics uses the same snapshot contract, and bulk writes must be atomic.Matching callers await the same consent round trip.
requestConsent()completes after the request succeeds or throws its failure, without emitting loading or result states.showIfRequiredis part of the in-flight key because an explicit privacy-form request cannot be satisfied by a weaker conditional request.Host validity is checked both before SDK work and immediately before form display; asynchronous callbacks must not retain permission to use a destroyed activity.
HOST_UNAVAILABLEleaves consent unresolved. Automatic activity-resume callers should keep a breadcrumb and allow a later resume to retry, rather than recording the lifecycle interruption as a nonfatal or permanently marking the session complete. The sample'sMainViewModeldemonstrates this policy. Explicit privacy-form actions retain their own user-visible error handling.Persistence records the resolved choice, while UMP remains the authority for whether a form is currently available or required.
Public contracts
ConsentRepository,ConsentSettings,ConsentHost, andConsentHostAvailability.ConsentHost(activity), which builds the host from the activity a page reads fromLocalActivity.current. It replaced About'sGmsHostFactory.
Internal implementations
DefaultConsentRepositoryand UMP SDK orchestration.
Current risks
Consent behavior spans persistence, host callbacks, UMP state, Firebase toggles, and ads consumers; changes require coordinated validation across those boundaries.
Requests with different showIfRequired values wait for the current round trip before starting another. A stale-host wait is limited to five seconds; a timeout fails the waiting caller without starting overlapping SDK work. The active operation stays tracked until it answers.
Migration notes
Fixed: UMP 4.0.0 empty-error-body process crash
Reported as NoSuchElementException from Scanner.next() on a UMP ThreadPoolExecutor thread, with no toolkit frame in the stack.
The toolkit previously encountered a process-killing failure after a consent request failed. UMP 4.0.0 performs a metrics request on its own executor and reads a non-success response body with Scanner.next(). An empty body throws NoSuchElementException on that executor thread. Because the throw happens outside the toolkit coroutine/callback path, catches in the remote source or the repository cannot intercept it.
Keep these host checks, request-mode distinctions, and shared-result behaviors when changing UMP coordination:
DefaultConsentRepositoryshares a round trip between matching callers.The in-flight request is keyed by
showIfRequired; an explicit form request must not join a request that only shows a form when required.A host that is finishing or destroyed is rejected before UMP is called.
UmpConsentRemoteDataSourcechecksConsentHost.canShowConsentFormagain in the asynchronous callback before displaying a form.Every starter or joining caller awaits completion or receives an exception. Cancelling one caller's wait does not cancel the shared round trip for other callers.
UMP receives an AdMob application ID only when the host-manifest provider resolves a valid value; there is no library fallback ID.
ConsentSdkCrashGuard narrowly covers any remaining SDK telemetry failure. Remove that guard only after the exact empty-body read is verified as fixed in the released UMP artifact, preferably by inspecting the artifact rather than relying only on release notes.