Add remote configuration support and fix app name

Features:
- Fixed app name from "Dark Side Admin" to "SilverDROID"
- Added remote configuration loader with AppStore integration
- Support for user-specific configurations
- Bearer token authentication for secure config retrieval
- Automatic fallback to local config if remote fails
- Remote config refresh interval support

Configuration example updated with remoteConfig section.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-05 19:58:19 +01:00
parent 9f33b5a332
commit d173c08a0c
5 changed files with 172 additions and 32 deletions

View File

@@ -16,6 +16,9 @@ data class AppConfig(
val showUrlBar: Boolean = false,
val allowNavigation: Boolean = true,
// Remote configuration
val remoteConfig: RemoteConfigSettings? = null,
// VPN configuration (optional)
val vpn: VpnConfig? = null,
@@ -26,6 +29,15 @@ data class AppConfig(
val theme: ThemeConfig = ThemeConfig()
)
@Serializable
data class RemoteConfigSettings(
val enabled: Boolean = true,
val url: String,
val authToken: String? = null,
val userSpecific: Boolean = false,
val refreshInterval: Long = 3600000 // 1 hour in milliseconds
)
@Serializable
data class VpnConfig(
val enabled: Boolean = false,

View File

@@ -0,0 +1,121 @@
package uk.silverlabs.silverdroid.config
import android.content.Context
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import java.net.HttpURLConnection
import java.net.URL
/**
* Loads configuration from remote AppStore server
*/
object RemoteConfigLoader {
private val json = Json {
ignoreUnknownKeys = true
isLenient = true
}
/**
* Fetch configuration from remote URL with optional authentication
*/
suspend fun fetchConfig(
remoteSettings: RemoteConfigSettings,
userId: String? = null
): Result<AppConfig> = withContext(Dispatchers.IO) {
try {
val url = buildConfigUrl(remoteSettings, userId)
Log.i(TAG, "Fetching config from: $url")
val connection = URL(url).openConnection() as HttpURLConnection
connection.requestMethod = "GET"
connection.connectTimeout = 10000
connection.readTimeout = 10000
// Add authentication if provided
remoteSettings.authToken?.let {
connection.setRequestProperty("Authorization", "Bearer $it")
}
// Add user ID if user-specific config
userId?.let {
connection.setRequestProperty("X-User-ID", it)
}
val responseCode = connection.responseCode
if (responseCode == HttpURLConnection.HTTP_OK) {
val response = connection.inputStream.bufferedReader().use { it.readText() }
val config = json.decodeFromString<AppConfig>(response)
Log.i(TAG, "Successfully loaded remote config for: ${config.appName}")
Result.success(config)
} else {
val error = "HTTP $responseCode: ${connection.responseMessage}"
Log.e(TAG, "Failed to fetch config: $error")
Result.failure(Exception(error))
}
} catch (e: Exception) {
Log.e(TAG, "Error fetching remote config", e)
Result.failure(e)
}
}
private fun buildConfigUrl(settings: RemoteConfigSettings, userId: String?): String {
var url = settings.url
// Add user parameter if user-specific
if (settings.userSpecific && userId != null) {
url = if (url.contains("?")) {
"$url&userId=$userId"
} else {
"$url?userId=$userId"
}
}
return url
}
/**
* Load config with remote fallback
* 1. Try to load local config
* 2. If remote is configured, fetch from server
* 3. Merge remote with local (remote takes precedence)
*/
suspend fun loadConfigWithRemote(
context: Context,
userId: String? = null
): AppConfig {
// Load local config first
val localConfig = ConfigLoader.loadConfig(context)
// Check if remote config is enabled
val remoteSettings = localConfig.remoteConfig
if (remoteSettings == null || !remoteSettings.enabled) {
Log.i(TAG, "Remote config disabled, using local config")
return localConfig
}
// Fetch remote config
return when (val result = fetchConfig(remoteSettings, userId)) {
is Result.Success -> {
Log.i(TAG, "Using remote configuration")
result.value
}
is Result.Failure -> {
Log.w(TAG, "Remote config failed, falling back to local", result.error)
localConfig
}
}
}
companion object {
private const val TAG = "RemoteConfigLoader"
}
}
sealed class Result<out T> {
data class Success<T>(val value: T) : Result<T>()
data class Failure(val error: Exception) : Result<Nothing>()
}