-
public class ConfigManager
-
-
Field Summary
Fields Modifier and Type Field Description private AppConfigurationcurrentprivate final SharedFlow<AppConfiguration>configFetchedpublic final static ConfigManagerINSTANCE
-
Method Summary
Modifier and Type Method Description final UnitmarkApiKeyAvailable()Signal that the API key has been set on Network.apiKey.final Unitinit(Context context)final ContextgetAppContext()final UnitsetConfigOverride(String patchJson, Boolean enabled)Set (or clear) a JSON merge-patch applied on top of every fetched server config. final BooleangetConfigOverrideEnabled()final StringgetConfigOverridePatch()final StringgetEffectiveConfigJson()The currently-applied config, serialized — seeds the editor's "current values" view. final UnitrefreshInBackground()Best-effort re-fetch + apply (honours the override). final AppConfigurationfetch()Single-shot fetch attempt. final AppConfigurationensureLoaded()Returns the loaded config, blocking until a fetch has succeeded. final UnitpreloadAsync()Async variant — kicks off the retry loop but doesn't suspend the caller. final AppConfigurationgetCurrent()final UnitsetCurrent(AppConfiguration current)final SharedFlow<AppConfiguration>getConfigFetched()-
-
Method Detail
-
markApiKeyAvailable
final Unit markApiKeyAvailable()
Signal that the API key has been set on
Network.apiKey. Idempotent — subsequent calls are no-ops. Called from com.doorstepai.sdks.tracking.DoorstepAI.setAPIKey.
-
getAppContext
final Context getAppContext()
-
setConfigOverride
final Unit setConfigOverride(String patchJson, Boolean enabled)
Set (or clear) a JSON merge-patch applied on top of every fetched server config.
enabled=falsekeeps the patch stored but inactive (server config is used verbatim).patchJson=nullclears the stored patch. Throws IllegalArgumentException if a non-null patch isn't a JSON object. Persisted to CONFIG_PREFS so it survives process death. Call refreshInBackground afterward to re-fetch and apply immediately.
-
getConfigOverrideEnabled
final Boolean getConfigOverrideEnabled()
-
getConfigOverridePatch
final String getConfigOverridePatch()
-
getEffectiveConfigJson
final String getEffectiveConfigJson()
The currently-applied config, serialized — seeds the editor's "current values" view.
-
refreshInBackground
final Unit refreshInBackground()
Best-effort re-fetch + apply (honours the override). Non-blocking.
-
fetch
final AppConfiguration fetch()
Single-shot fetch attempt. Returns the parsed config and applies it on HTTP 2xx, or returns
null(and leaves the existingcurrentin place) on any non-2xx, transport error, or decode failure. Useful for best-effort refreshes (e.g. aftersetAPIKey) where the caller doesn't want to block on the retry loop. Production session-start callers should use ensureLoaded instead.
-
ensureLoaded
final AppConfiguration ensureLoaded()
Returns the loaded config, blocking until a fetch has succeeded.
On first call (or after every process restart) this drives an exponential-backoff retry loop — 1 s → 2 s → 4 s → ... capped at 2 h per attempt — until the config endpoint returns successfully. Concurrent callers share the single in-flight retry, so e.g. two simultaneous
startDelivery(...)calls only produce one retry loop.The session-start path gates on this: if the config can't be fetched,
startDelivery(...)won't firenewSessionat all. Backoff state is in-memory and resets on every app launch, so a fresh process always starts from the initial 1 s delay regardless of prior failures.
-
preloadAsync
final Unit preloadAsync()
Async variant — kicks off the retry loop but doesn't suspend the caller. Useful from
initso the config is likely already loaded by the time the host callsstartDelivery(...).
-
getCurrent
final AppConfiguration getCurrent()
-
setCurrent
final Unit setCurrent(AppConfiguration current)
-
getConfigFetched
final SharedFlow<AppConfiguration> getConfigFetched()
-
-
-
-