Skip to content

Commit

Permalink
Fix kotlin lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Jul 31, 2024
1 parent 77fbbbf commit f80472d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import oonimkall.Oonimkall
import oonimkall.SessionConfig

class AndroidOonimkallBridge : OonimkallBridge {

override fun startTask(settingsSerialized: String): OonimkallBridge.Task {
val task = Oonimkall.startTask(settingsSerialized)
return object : OonimkallBridge.Task {
Expand All @@ -18,6 +17,7 @@ class AndroidOonimkallBridge : OonimkallBridge {
}

override fun isDone(): Boolean = task.isDone

override fun waitForNextEvent() = task.waitForNextEvent()
}
}
Expand Down Expand Up @@ -67,13 +67,16 @@ class AndroidOonimkallBridge : OonimkallBridge {
it.probeServicesURL = probeServicesURL
it.proxy = proxy

it.logger = logger?.let { logger ->
object : Logger {
override fun debug(msg: String?) = logger.debug(msg)
override fun info(msg: String?) = logger.info(msg)
override fun warn(msg: String?) = logger.warn(msg)
it.logger =
logger?.let { logger ->
object : Logger {
override fun debug(msg: String?) = logger.debug(msg)

override fun info(msg: String?) = logger.info(msg)

override fun warn(msg: String?) = logger.warn(msg)
}
}
}
it.verbose = verbose
}

Expand All @@ -85,11 +88,12 @@ class AndroidOonimkallBridge : OonimkallBridge {
it.runType = runType
it.softwareName = softwareName
it.softwareVersion = softwareVersion
it.webConnectivity = CheckInConfigWebConnectivity().also {
webConnectivityCategories.forEach { category ->
it.addCategory(category)
}
}
it.webConnectivity =
CheckInConfigWebConnectivity().also {
webConnectivityCategories.forEach { category ->
it.addCategory(category)
}
}
}

private fun OonimkallBridge.HTTPRequest.toMk() =
Expand All @@ -114,7 +118,6 @@ class AndroidOonimkallBridge : OonimkallBridge {
}
}


companion object {
private const val CONTEXT_TIMEOUT = -1L
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ooni.engine

interface OonimkallBridge {

@Throws(Exception::class)
fun startTask(settingsSerialized: String): Task

Expand All @@ -14,11 +13,13 @@ interface OonimkallBridge {
}

@Throws(Exception::class)
fun newSession(sessionConfig: SessionConfig) : Session
fun newSession(sessionConfig: SessionConfig): Session

interface Logger {
fun debug(msg: String?)

fun info(msg: String?)

fun warn(msg: String?)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ object NetworkTypeSerializer : KSerializer<NetworkType> {
override val descriptor =
PrimitiveSerialDescriptor("NetworkType", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: NetworkType) {
override fun serialize(
encoder: Encoder,
value: NetworkType,
) {
encoder.encodeString(value.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ object TaskLogLevelSerializer : KSerializer<TaskLogLevel> {
override val descriptor =
PrimitiveSerialDescriptor("TaskLogLevel", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: TaskLogLevel) {
override fun serialize(
encoder: Encoder,
value: TaskLogLevel,
) {
encoder.encodeString(value.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import kotlinx.serialization.encoding.Encoder
@Serializable(with = TaskOriginSerializer::class)
enum class TaskOrigin(val value: String) {
AutoRun("autorun"),
OoniRun("ooni-run")
OoniRun("ooni-run"),
}

object TaskOriginSerializer : KSerializer<TaskOrigin> {
override val descriptor =
PrimitiveSerialDescriptor("TaskOrigin", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: TaskOrigin) {
override fun serialize(
encoder: Encoder,
value: TaskOrigin,
) {
encoder.encodeString(value.value)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ data class TaskSettings(
@SerialName("log_level") val logLevel: TaskLogLevel,
@SerialName("disabled_events") val disabledEvents: List<String> = emptyList(),
@SerialName("proxy") val proxy: String? = null,

@SerialName("state_dir") val stateDir: String? = null,
@SerialName("temp_dir") val tempDir: String? = null,
@SerialName("tunnel_dir") val tunnelDir: String? = null,
@SerialName("assets_dir") val assetsDir: String? = null,

@SerialName("options") val options: Options,
@SerialName("annotations") val annotations: Annotations,
) {
@Serializable
data class Options(
@SerialName("no_collector") val noCollector: Boolean, // upload results or not
@SerialName("software_name") val softwareName: String, // built from the flavors + debug or not + -unattended if autorun
// upload results or not
@SerialName("no_collector") val noCollector: Boolean,
// built from the flavors + debug or not + -unattended if autorun
@SerialName("software_name") val softwareName: String,
@SerialName("software_version") val softwareVersion: String,
)

@Serializable
data class Annotations(
@SerialName("network_type") val networkType: NetworkType,
@SerialName("flavor") val flavor: String, // OONI or DW
@SerialName("origin") val origin: TaskOrigin, // "autorun" or "ooni-run"
// OONI or DW
@SerialName("flavor") val flavor: String,
// "autorun" or "ooni-run"
@SerialName("origin") val origin: TaskOrigin,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ class DashboardViewModel(
name = "web_connectivity",
inputs = listOf("https://ooni.org"),
logLevel = TaskLogLevel.Info,
options = TaskSettings.Options(
noCollector = true,
softwareName = Config.BASE_SOFTWARE_NAME,
softwareVersion = "1.0"
),
annotations = TaskSettings.Annotations(
networkType = NetworkType.Wifi,
flavor = Config.BASE_SOFTWARE_NAME,
origin = TaskOrigin.OoniRun
)
options =
TaskSettings.Options(
noCollector = true,
softwareName = Config.BASE_SOFTWARE_NAME,
softwareVersion = "1.0",
),
annotations =
TaskSettings.Annotations(
networkType = NetworkType.Wifi,
flavor = Config.BASE_SOFTWARE_NAME,
origin = TaskOrigin.OoniRun,
),
)
}
}

0 comments on commit f80472d

Please sign in to comment.