-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ooni test descriptors. #275
base: main
Are you sure you want to change the base?
Changes from 8 commits
6616957
ac4a5ac
70aa880
e79880a
b246b77
8c0c5d8
1f47c8f
f792ba0
0ea31fd
cd43b4e
f4054c1
1323b3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,16 @@ import kotlinx.serialization.json.Json | |
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_Description | ||
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdated | ||
import ooniprobe.composeapp.generated.resources.Res | ||
import ooniprobe.composeapp.generated.resources.TestResults_NotAvailable | ||
import ooniprobe.composeapp.generated.resources.performance_datausage | ||
import ooniprobe.composeapp.generated.resources.small_datausage | ||
import ooniprobe.composeapp.generated.resources.test_circumvention | ||
import ooniprobe.composeapp.generated.resources.test_experimental | ||
import ooniprobe.composeapp.generated.resources.test_instant_messaging | ||
import ooniprobe.composeapp.generated.resources.test_performance | ||
import ooniprobe.composeapp.generated.resources.test_websites | ||
import ooniprobe.composeapp.generated.resources.websites_datausage | ||
import org.jetbrains.compose.resources.StringResource | ||
import org.jetbrains.compose.resources.stringResource | ||
import org.ooni.probe.data.TestDescriptor | ||
import org.ooni.probe.shared.InstalledDescriptorIcons | ||
|
@@ -52,6 +57,21 @@ data class InstalledTestDescriptorModel( | |
|
||
val isExpired get() = expirationDate != null && expirationDate < LocalDateTime.now() | ||
|
||
val isDefaultTestDescriptor get() = id.value in 10470..10474 // TODO(aanorbel): switch to OONI reserved namespace | ||
|
||
val key get() = if (isDefaultTestDescriptor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more like a settings key now no? Just to make it clear why we still need this. Because for all other purposes now we can use the ID. |
||
when (id.value) { | ||
10470L -> "websites" | ||
10471L -> "instant_messaging" | ||
10472L -> "circumvention" | ||
10473L -> "performance" | ||
10474L -> "experimental" | ||
else -> id.value.toString() | ||
} | ||
} else { | ||
id.value.toString() | ||
} | ||
|
||
fun shouldUpdate(other: InstalledTestDescriptorModel): Boolean { | ||
return dateUpdated != null && other.dateUpdated != null && other.dateUpdated > dateUpdated | ||
} | ||
|
@@ -79,13 +99,24 @@ fun InstalledTestDescriptorModel.toDescriptor(updateStatus: UpdateStatus = Updat | |
icon = icon?.let(InstalledDescriptorIcons::getIconFromValue), | ||
color = color?.hexToColor(), | ||
animation = icon?.let { determineAnimation(it) } ?: animation?.let(Animation::fromFileName), | ||
dataUsage = { null }, | ||
dataUsage = { if (isDefaultTestDescriptor) stringResource(getDataUsage()) else null }, | ||
expirationDate = expirationDate, | ||
netTests = netTests.orEmpty(), | ||
source = Descriptor.Source.Installed(this), | ||
source = this, | ||
updateStatus = updateStatus, | ||
) | ||
|
||
fun InstalledTestDescriptorModel.getDataUsage(): StringResource { | ||
return when (this.key) { | ||
"websites" -> Res.string.websites_datausage | ||
"instant_messaging" -> Res.string.small_datausage | ||
"circumvention" -> Res.string.small_datausage | ||
"performance" -> Res.string.performance_datausage | ||
"experimental" -> Res.string.TestResults_NotAvailable | ||
else -> Res.string.TestResults_NotAvailable | ||
} | ||
} | ||
|
||
private val iconAnimationMap = mapOf( | ||
Res.drawable.test_websites to Animation.Websites, | ||
Res.drawable.test_instant_messaging to Animation.InstantMessaging, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,11 @@ sealed interface RunSpecification { | |
|
||
@Serializable | ||
data class Test( | ||
val source: Source, | ||
val source: InstalledTestDescriptorModel.Id? = null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this sourceId or descriptorId to avoid confusion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this should never be null right? |
||
val netTests: List<NetTest>, | ||
) { | ||
@Serializable | ||
sealed interface Source { | ||
@Serializable | ||
data class Default(val name: String) : Source | ||
|
||
@Serializable | ||
data class Installed(val id: InstalledTestDescriptorModel.Id) : Source | ||
|
||
companion object { | ||
fun fromDescriptor(descriptor: Descriptor) = | ||
when (descriptor.source) { | ||
is Descriptor.Source.Default -> Default(descriptor.name) | ||
is Descriptor.Source.Installed -> Installed(descriptor.source.value.id) | ||
} | ||
} | ||
companion object { | ||
fun fromDescriptor(descriptor: Descriptor) = descriptor.source.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This companion object isn't needed, it should return an object of the type |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,6 @@ class ChooseWebsitesViewModel( | |
RunSpecification.Full( | ||
tests = listOf( | ||
RunSpecification.Test( | ||
source = RunSpecification.Test.Source.Default("websites"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should fetch it from the DB, or hardcode the websites descriptor ID somewhere. |
||
netTests = listOf( | ||
NetTest( | ||
test = TestType.WebConnectivity, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also check if they are in
OoniTest
now.