55 lines
3.1 KiB
Kotlin
55 lines
3.1 KiB
Kotlin
import android.content.Context
|
|
import android.content.ContextWrapper
|
|
import com.utun.chat.data.AutoSocketProtocols
|
|
import com.utun.chat.data.ConfigProvider
|
|
import com.utun.chat.data.ServerEntry
|
|
import kotlinx.coroutines.runBlocking
|
|
import java.io.File
|
|
import kotlin.system.exitProcess
|
|
|
|
/* Запуск через app_process с собранным APK в CLASSPATH: настоящие ConfigProvider/DataStore,
|
|
* отдельный каталог без доступа к профилю приложения. Полученные .cfg проверяет test_node_config --validate. */
|
|
fun main(args: Array<String>): Unit = runBlocking {
|
|
val directory = File(args.single())
|
|
check(directory.mkdirs()) { "Use a new output directory: $directory" }
|
|
val context = object : ContextWrapper(null) {
|
|
override fun getApplicationContext(): Context = this
|
|
override fun getFilesDir(): File = directory
|
|
}
|
|
val provider = ConfigProvider(context)
|
|
provider.setValue("node.name", "Android config probe")
|
|
provider.setValue("node.private_key", "704f2e012c8fa8768130cb0f988a997dccb628372bc5ceccacc78dcbfec5916f")
|
|
provider.setValue("node.public_key", "b3193173def895bd0fcea6f86af077c7d77216f10395275f627ac18242ec0f01")
|
|
provider.saveServersToConfig(emptyList())
|
|
val defaults = File(provider.configFilePath()).readText()
|
|
check("storage_unit_size=10M\n" in defaults && "storage_total_size=1G\n" in defaults)
|
|
File(directory, "default.cfg").writeText(defaults)
|
|
provider.setValue("chat.storage_autoload_maxsize_mb", "23")
|
|
provider.setValue("chat.storage_maxsize_gb", "7")
|
|
provider.setValue("debug.categories", "config=debug,chat_sync=info,stream=debug")
|
|
provider.setConnectionMode("manual")
|
|
for (protocols in AutoSocketProtocols.values()) {
|
|
provider.setAutoSocketProtocols(protocols)
|
|
val servers = protocols.createServers("probe", "127.0.0.1", emptyList()) +
|
|
protocols.createServers("probe", "::1", emptyList())
|
|
val inactive = listOf(ServerEntry("inactive", "offline", "192.0.2.1", "tcp", 4567))
|
|
for (utun in 0..1) {
|
|
provider.setValue("gui.utun_enabled", "$utun")
|
|
provider.saveServersToConfig(servers, inactive)
|
|
val saved = File(provider.configFilePath()).readText()
|
|
check("#[server:offline_v4_tcp]" in saved)
|
|
val text = provider.buildConfigText()
|
|
check("storage_unit_size=23M\n" in text && "storage_total_size=7G\n" in text)
|
|
check("storage_autoload_maxsize_mb=" !in text && "storage_maxsize_gb=" !in text)
|
|
check("auto_socket_protocols=${protocols.configValue}\n" in text && "utun_enabled=$utun\n" in text)
|
|
check("radio_vad_enabled=" !in text && "radio_auto_enabled=" in text)
|
|
check(!text.contains("[server:offline_v4_tcp]"))
|
|
val name = "${protocols.configValue.replace('+', '-')}-utun$utun"
|
|
File(directory, "$name-saved.cfg").writeText(saved)
|
|
File(directory, "$name-start.cfg").writeText(text)
|
|
}
|
|
}
|
|
println("PASS: real Android ConfigProvider defaults, storage sizes, TCP/UDP, IPv4/IPv6, inactive sockets and UTUN policy")
|
|
exitProcess(0)
|
|
}
|