Configuration management and import/export
Configuration management gives the application one shared view of user and service settings. It keeps those values on the device, exposes selected groups to the local HTTP API, presents them through focused preference screens, and lets the cloud gateway apply remote changes.
Configuration model
The application treats settings as named groups with stable keys. Each group reads and writes its values through shared preferences, while a common service gathers the groups that support transfer across an API boundary. This makes local UI changes and remote updates reach the same settings used by the server, gateway, message, inbox, and webhook services.
Persistent settings
Persistent settings use a group prefix so values from different services do not share a key by accident. Simple values stay as native preference values. Structured values use JSON, which lets settings such as gateway registration data remain one logical value. Missing values use service defaults, and some generated values are created the first time a service needs them.
The settings module also wires device settings into the shared settings system. These settings can accept selected remote values, but they are not part of the exported configuration. The module also owns small app-wide preferences such as language and automatic start. These values affect Android behavior or the UI rather than the transferable service configuration. Startup access also performs limited migration for older preference names.
References: app/…/PreferencesStorage.kt• L7-65 app/…/ValueSerializer.kt• L6-15 app/…/SettingsHelper.kt• L11-51 app/…/Module.kt• L21-85
Settings service
SettingsService is the shared access point for configuration transfer. It maps stable group names to settings providers, reads exportable values, and sends incoming group data to providers that support import. A provider reports whether a value changed, so the service can notify the user only when an update needs a restart or other follow-up. Providers that do not support one of these actions do not add that action to the transfer.
The transfer set is not the same as every preference shown in the app. Local server credentials and runtime switches remain local, while some sensitive or device-specific values are intentionally absent from export. The device settings provider is import-only, so a remote update can change its supported value without turning it into a device-state backup. This boundary prevents a configuration transfer from becoming a full device identity or secret backup.
References: app/…/SettingsService.kt• L16-69 app/…/Exporter.kt• L3-5 app/…/Importer.kt• L3-5 app/…/DeviceSettings.kt• L7-46
Settings domains
The settings domains group controls by the service behavior they change. The preference screens use the same key groups that the service layer reads, so a saved choice affects the corresponding runtime policy rather than a separate UI-only copy.
Local server settings
Local server settings control whether the device exposes its local HTTP service and how that service accepts requests. They cover the listening port, local credentials, and the lifetime of local JWT access tokens. The server derives or stores a device identity and keeps its JWT signing secret local; changing these values can require a service or app restart.
References: app/…/LocalServerSettings.kt• L7-63 app/…/LocalServerService.kt• L31-47 app/…/local_server_preferences.xml• L4-51
Cloud gateway settings
Cloud gateway settings select the cloud API and its notification mode. They also hold registration state, access credentials, the device token, and an optional private token used to reach a non-public cloud service. Registration state supplies the gateway identity and credentials used by cloud message, webhook, and settings requests.
References: app/…/GatewaySettings.kt• L8-67 app/…/GatewayService.kt• L36-65 app/…/cloud_server_preferences.xml• L4-59
Message settings
Message settings define how outgoing work is selected and paced. They cover SIM selection, queue order, send delays, message limits, log retention, and optional working hours. These choices shape when the message service accepts or processes work, so they also affect messages received from the cloud gateway.
References: app/…/MessagesSettings.kt• L33-69 app/…/MessagesSettings.kt• L173-185 app/…/messages_preferences.xml• L4-85
Inbox settings
Inbox settings control how long incoming messages remain and whether content-provider monitoring supplements broadcast-based message capture. They apply to the local inbox data path and are separate from outgoing message queue settings.
References: app/…/IncomingMessagesSettings.kt• L8-41 app/…/ReceiverSettings.kt• L6-15 app/…/inbox_preferences.xml• L4-17
Webhook settings
Webhook settings control delivery policy rather than the webhook list itself. They set whether delivery waits for an internet connection, how many retries are allowed, and the local signing key used for webhook requests. Webhook definitions are separate records with a source such as local or cloud, so list changes follow the webhook data path instead of the general settings map.
References: app/…/WebhooksSettings.kt• L9-37 app/…/WebHooksService.kt• L48-77 app/…/webhooks_preferences.xml• L4-29
Supporting settings
Encryption, ping, and log settings support cross-cutting service behavior. Encryption accepts a passphrase but does not export it. Ping uses a positive interval to enable periodic health work, while log retention uses a positive lifetime and can be transferred as part of the settings map.
References: app/…/EncryptionSettings.kt• L7-56 app/…/PingSettings.kt• L8-46 app/…/LogsSettings.kt• L8-62
Service access
Services read settings through injected domain objects rather than through the preference screens. This keeps background work independent of the UI and lets the local server and cloud gateway use the same stored values.
Local API access
The local server exposes settings at /settings. A caller with settings:read can read the transferable groups. A caller with settings:write can send a partial group map, after which the API returns the current settings map. The API treats malformed values or rejected domain values as a bad request.
References: app/…/SettingsRoutes.kt• L14-55 app/…/AuthScopes.kt• L17-24 app/…/WebService.kt• L198-204
Runtime access
The local server reads its binding settings when its service starts. The gateway reads its endpoint and token when it creates its cloud client. Message, inbox, log, ping, encryption, and webhook services read their domain settings as they make decisions. Because long-running services may capture startup values, a successful settings update can still need an app restart before every effect is active.
References: app/…/WebService.kt• L216-224 app/…/GatewayService.kt• L36-65 app/…/WebHooksService.kt• L36-45
Preference screens
The Android settings UI presents a small root screen and separate screens for local server, cloud server, messages, inbox, and webhooks. Each screen binds to the shared preference store, then adds validation or an action when a setting needs more than a plain text or choice control.
Screen structure
The root screen groups direct controls for encryption, ping, logs, system behavior, language, and app information. It links to the domain screens for server, gateway, message, inbox, and webhook settings. The app version is display-only, while language changes rebuild the main activity so the new locale appears at once.
References: app/…/root_preferences.xml• L3-86 app/…/SettingsFragment.kt• L21-47
Input validation
The screens reject values that would make a service unsafe or unusable. Examples include invalid local ports, short credentials, invalid JWT lifetimes, malformed cloud URLs, and invalid time or count values. Conditional controls also reflect related state, such as enabling message limits only when a limit period is active.
References: app/…/LocalServerSettingsFragment.kt• L32-76 app/…/MessagesSettingsFragment.kt• L37-79 app/…/CloudServerSettingsFragment.kt• L34-60
Sensitive actions
Some values are actions or protected credentials rather than ordinary preferences. The UI can regenerate the local JWT secret, change or clear the cloud password, and request a cloud login code. Password fields are hidden or protected by a prompt, and generated device identifiers are shown as read-only information.
References: app/…/LocalServerSettingsFragment.kt• L17-29 app/…/CloudServerSettingsFragment.kt• L62-141 app/…/cloud_server_preferences.xml• L24-57
Import and export flow
Import and export move a nested map of named settings groups through the local API or the cloud gateway. Each domain decides which keys it accepts and how to validate them, so unknown keys do not become new stored settings and invalid values stop the update.
Local transfer
The local API transfer follows this sequence:
- An authenticated client requests the transferable settings or sends a partial update.
- The route passes the group map to
SettingsService. - The service asks each matching provider to export or import its supported keys.
- The provider validates values and stores accepted changes in the shared preference store.
- The API returns the current settings map after a write.
The export is selective. Gateway export includes the cloud URL and notification mode, while its private token is accepted on import but is not returned by export. Encryption accepts a passphrase on import but does not export it. Device settings can accept their supported imported value, but they do not add device state to the exported map. This makes import useful for provisioning without treating export as a secret dump.
References: app/…/SettingsRoutes.kt• L23-54 app/…/SettingsService.kt• L29-69 app/…/GatewaySettings.kt• L62-107 app/…/EncryptionSettings.kt• L43-56 app/…/DeviceSettings.kt• L33-46
Cloud synchronization
The gateway uses the cloud API as a source of remote settings. A periodic worker fetches the cloud settings and applies them through the same SettingsService used by the local API. An incoming settings event can start that worker again, which keeps the device responsive to cloud-side changes without giving the gateway a second settings format.
The cloud settings request uses the registered device token. If a setting changes, the application posts a notification that a restart may be needed. The gateway remains disabled for this work when cloud gateway settings are not active.
References: app/…/GatewayApi.kt• L122-126 app/…/SettingsUpdateWorker.kt• L19-69 app/…/EventsReceiver.kt• L76-84 app/…/EventsRouter.kt• L41-44
Webhook configuration transfer
Webhook configuration has two layers. General webhook policy uses the settings map, while webhook records use dedicated list operations and keep their source as local or cloud. The cloud gateway can fetch and synchronize cloud webhook records, and the local API can create, list, or delete local records. Delivery checks both the record source and the matching gateway or local-server state before it queues an event.
References: app/…/WebhooksRoutes.kt• L18-50 app/…/WebHooksService.kt• L63-77 app/…/WebHooksService.kt• L126-168
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the group names and provider registration aligned across
SettingsService, each domain provider, the local API contract, and the cloud settings response. - If a setting changes from local-only to transferable, review whether it contains a device identity, credential, token, or generated secret before adding it to export.
- Keep import-only device values out of export and check that their remote key names remain stable.
- Keep enum names and time or count validation compatible between preference values and imported JSON values.
- When startup-owned settings change, update the restart or reinitialization path so the running server or gateway does not keep stale values.
- Treat webhook policy settings and webhook records as separate contracts. A change to one must not silently omit the other from local or cloud synchronization.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A client writes a setting group without settings:write | The local API rejects the update before it reaches the settings service | Require the matching auth scope for writes |
| An imported cloud URL is not HTTPS | The gateway settings import fails and the request is rejected | Validate the URL scheme before storing it |
| An imported count or lifetime is zero or negative | The related feature may be disabled or behave outside its supported policy | Enforce positive values in the domain provider |
| A settings update changes a value captured at service start | The stored value is correct but the running service can keep the old behavior | Show the restart notice and restart the affected service or app |
| A cloud or local webhook has no active matching source or device ID | The event is skipped instead of being sent to an unintended endpoint | Check source enablement and device identity before queueing delivery |
| Export is treated as a full secret backup | Passwords, passphrases, and some tokens are missing from the exported map | Use an explicit import path for secrets and do not assume export round-trips every preference |
Key files
| File | Why to read it |
|---|---|
| app/…/SettingsService.kt | Shows the shared boundary for settings reads, updates, import, and export. |
| app/…/Module.kt | Shows which settings providers participate in the shared settings system and which storage groups they use. |
| app/…/PreferencesStorage.kt | Explains the common persistent value model and group key isolation. |
| app/…/SettingsUpdateWorker.kt | Shows how cloud settings reach the device on a schedule and retry after failure. |
| app/…/SettingsRoutes.kt | Shows the authenticated local API contract for settings transfer. |
| app/…/root_preferences.xml | Shows the top-level user view and the domain screens exposed from it. |
| app/…/MessagesSettings.kt | Shows how a broad policy domain maps stored choices to message behavior. |
| app/…/WebHooksService.kt | Shows the boundary between webhook policy settings and webhook records. |
Parent: Application lifecycle and module composition
Related: Event routing, Persistent storage, Cloud gateway integration, Local HTTP API, Webhook delivery, User interface and operations