-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ooni/engine-bridge
Engine bridge interface + Android implementation
- Loading branch information
Showing
12 changed files
with
346 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
composeApp/src/commonMain/kotlin/org/ooni/engine/TaskSettings.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ain/kotlin/org/ooni/engine/EventResult.kt → ...lin/org/ooni/engine/models/EventResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
composeApp/src/commonMain/kotlin/org/ooni/engine/models/NetworkType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.ooni.engine.models | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable(with = NetworkTypeSerializer::class) | ||
enum class NetworkType(val value: String) { | ||
VPN("vpn"), | ||
Wifi("wifi"), | ||
Mobile("mobile"), | ||
NoInternet("no_internet"), | ||
} | ||
|
||
object NetworkTypeSerializer : KSerializer<NetworkType> { | ||
override val descriptor = | ||
PrimitiveSerialDescriptor("NetworkType", PrimitiveKind.STRING) | ||
|
||
override fun serialize( | ||
encoder: Encoder, | ||
value: NetworkType, | ||
) { | ||
encoder.encodeString(value.value) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): NetworkType { | ||
val string = decoder.decodeString() | ||
return NetworkType.entries.firstOrNull { it.value == string } ?: NetworkType.NoInternet | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nMain/kotlin/org/ooni/engine/TaskEvent.kt → ...otlin/org/ooni/engine/models/TaskEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.ooni.engine | ||
package org.ooni.engine.models | ||
|
||
sealed interface TaskEvent { | ||
data class Log( | ||
|
31 changes: 31 additions & 0 deletions
31
composeApp/src/commonMain/kotlin/org/ooni/engine/models/TaskLogLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.ooni.engine.models | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable(with = TaskLogLevelSerializer::class) | ||
enum class TaskLogLevel(val value: String) { | ||
Debug("DEBUG2"), | ||
Info("INFO"), | ||
} | ||
|
||
object TaskLogLevelSerializer : KSerializer<TaskLogLevel> { | ||
override val descriptor = | ||
PrimitiveSerialDescriptor("TaskLogLevel", PrimitiveKind.STRING) | ||
|
||
override fun serialize( | ||
encoder: Encoder, | ||
value: TaskLogLevel, | ||
) { | ||
encoder.encodeString(value.value) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): TaskLogLevel { | ||
val string = decoder.decodeString() | ||
return TaskLogLevel.entries.firstOrNull { it.value == string } ?: TaskLogLevel.Info | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
composeApp/src/commonMain/kotlin/org/ooni/engine/models/TaskOrigin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.ooni.engine.models | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
@Serializable(with = TaskOriginSerializer::class) | ||
enum class TaskOrigin(val value: String) { | ||
AutoRun("autorun"), | ||
OoniRun("ooni-run"), | ||
} | ||
|
||
object TaskOriginSerializer : KSerializer<TaskOrigin> { | ||
override val descriptor = | ||
PrimitiveSerialDescriptor("TaskOrigin", PrimitiveKind.STRING) | ||
|
||
override fun serialize( | ||
encoder: Encoder, | ||
value: TaskOrigin, | ||
) { | ||
encoder.encodeString(value.value) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): TaskOrigin { | ||
val string = decoder.decodeString() | ||
return TaskOrigin.entries.firstOrNull { it.value == string } ?: TaskOrigin.OoniRun | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
composeApp/src/commonMain/kotlin/org/ooni/engine/models/TaskSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.ooni.engine.models | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TaskSettings( | ||
// Required | ||
@SerialName("name") val name: String, | ||
@SerialName("inputs") val inputs: List<String>, | ||
@SerialName("version") val version: Int = 1, | ||
@SerialName("log_level") val logLevel: TaskLogLevel, | ||
@SerialName("disabled_events") val disabledEvents: List<String> = emptyList(), | ||
@SerialName("options") val options: Options, | ||
@SerialName("annotations") val annotations: Annotations, | ||
// Optional | ||
@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, | ||
) { | ||
@Serializable | ||
data class Options( | ||
// 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, | ||
// OONI or DW | ||
@SerialName("flavor") val flavor: String, | ||
// "autorun" or "ooni-run" | ||
@SerialName("origin") val origin: TaskOrigin, | ||
) | ||
} |
Oops, something went wrong.