Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ooni/probe-multiplatform into issue…
Browse files Browse the repository at this point in the history
…s/174
  • Loading branch information
aanorbel committed Dec 3, 2024
2 parents 8c0c5d8 + 9c8fd59 commit 1f47c8f
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 44 deletions.
1 change: 1 addition & 0 deletions composeApp/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustNothing"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,4 @@
<item quantity="other">@string/Measurements_Count_Other</item>
</plurals>

<string-array name="Common_Months" translatable="false">
<item>@string/Common_Months_January</item>
<item>@string/Common_Months_February</item>
<item>@string/Common_Months_March</item>
<item>@string/Common_Months_April</item>
<item>@string/Common_Months_May</item>
<item>@string/Common_Months_June</item>
<item>@string/Common_Months_July</item>
<item>@string/Common_Months_August</item>
<item>@string/Common_Months_September</item>
<item>@string/Common_Months_October</item>
<item>@string/Common_Months_November</item>
<item>@string/Common_Months_December</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.ooni.probe.domain.UploadMissingMeasurements
class RunBackgroundTask(
private val getPreferenceValueByKey: (SettingsKey) -> Flow<Any?>,
private val uploadMissingMeasurements: (ResultModel.Id?) -> Flow<UploadMissingMeasurements.State>,
private val checkSkipAutoRunNotUploadedLimit: () -> Flow<Boolean>,
private val checkSkipAutoRunNotUploadedLimit: suspend () -> Boolean,
private val getNetworkType: () -> NetworkType,
private val getAutoRunSpecification: suspend () -> RunSpecification.Full,
private val runDescriptors: suspend (RunSpecification.Full) -> Unit,
Expand Down Expand Up @@ -106,7 +106,7 @@ class RunBackgroundTask(
}

private suspend fun ProducerScope<RunBackgroundState>.runTests(spec: RunSpecification.Full?) {
if (checkSkipAutoRunNotUploadedLimit().first()) {
if (checkSkipAutoRunNotUploadedLimit()) {
Logger.i("Skipping auto-run tests: too many not-uploaded results")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ data class Descriptor(
}

fun isInstalledNonDefaultDescriptor(): Boolean {
return !source.isDefaultTestDescriptor
return !source.isDefaultTestDescriptor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlinx.datetime.format.char
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import ooniprobe.composeapp.generated.resources.Common_Months
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_Description
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdated
import ooniprobe.composeapp.generated.resources.Res
Expand All @@ -23,12 +22,12 @@ 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.stringArrayResource
import org.jetbrains.compose.resources.stringResource
import org.ooni.probe.data.TestDescriptor
import org.ooni.probe.shared.InstalledDescriptorIcons
import org.ooni.probe.shared.hexToColor
import org.ooni.probe.shared.now
import org.ooni.probe.shared.stringMonthArrayResource
import org.ooni.probe.shared.toEpoch

@Serializable
Expand Down Expand Up @@ -85,7 +84,7 @@ fun InstalledTestDescriptorModel.toDescriptor(updateStatus: UpdateStatus = Updat
shortDescription = { shortDescriptionIntl?.getCurrent() ?: shortDescription },
description = { descriptionIntl?.getCurrent() ?: description },
metadata = {
val monthNames = stringArrayResource(Res.array.Common_Months)
val monthNames = stringMonthArrayResource()
val formattedDate = { date: LocalDateTime? -> date?.format(dateTimeFormat(monthNames)) }
formattedDate(dateCreated)?.let { formattedDateCreated ->
stringResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sealed interface RunSpecification {
val netTests: List<NetTest>,
) {
companion object {
fun fromDescriptor(descriptor: Descriptor) =descriptor.source.id
fun fromDescriptor(descriptor: Descriptor) = descriptor.source.id
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package org.ooni.probe.domain

import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import org.ooni.probe.data.models.SettingsKey

class CheckSkipAutoRunNotUploadedLimit(
private val countResultsMissingUpload: () -> Flow<Long>,
private val getPreferenceValueByKey: (SettingsKey) -> Flow<Any?>,
) {
operator fun invoke(): Flow<Boolean> =
combine(
getPreferenceValueByKey(SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT),
countResultsMissingUpload(),
) { limit, count ->
val notUploadedLimit = (limit as? Int)
?.coerceAtLeast(1)
?: BootstrapPreferences.NOT_UPLOADED_LIMIT_DEFAULT
count >= notUploadedLimit
suspend operator fun invoke(): Boolean {
val limitPreference =
getPreferenceValueByKey(SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT).first()
val count = countResultsMissingUpload().first()

val notUploadedLimit = (limitPreference as? Int)
?.coerceAtLeast(1)
?: BootstrapPreferences.NOT_UPLOADED_LIMIT_DEFAULT
val shouldSkip = count >= notUploadedLimit

if (shouldSkip) {
Logger.w(
"Skipping auto-run due to not uploaded limit",
SkipAutoRunException("Results missing upload: $count (limit=$notUploadedLimit)"),
)
}

return shouldSkip
}
}

class SkipAutoRunException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GetTestDescriptors(
val updatedDescriptors = installedDescriptors.map { item ->
item.toDescriptor(updateStatus = descriptorUpdates.getStatusOf(item.id))
}
return@combine updatedDescriptors
return@combine updatedDescriptors
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class RunNetTest(

is TaskEvent.Log -> {
Logger.log(
severity = when (event.level) {
"WARNING" -> Severity.Warn
"DEBUG" -> Severity.Debug
severity = when {
event.level == "WARNING" && !LOGS_TO_LOWER_LEVEL.contains(event.message) ->
Severity.Warn

event.level == "DEBUG" -> Severity.Debug
else -> Severity.Info
},
message = event.message,
Expand Down Expand Up @@ -314,4 +316,10 @@ class RunNetTest(
Failure(message, value)

inner class BugJsonDump(value: TaskEventResult.Value?) : Failure(null, value)

companion object {
private val LOGS_TO_LOWER_LEVEL = listOf(
"Picking from default OpenVPN endpoints",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class UploadMissingMeasurements(
var uploaded = 0
var failedToUpload = 0

if (total > 0) {
Logger.i("Uploading missing measurements: $total")
}

measurements.forEach { measurement ->
if (!isActive) return@channelFlow // Check is coroutine was cancelled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -53,9 +55,7 @@ fun ChooseWebsitesScreen(
onEvent: (ChooseWebsitesViewModel.Event) -> Unit,
) {
Column(
modifier = Modifier
.padding(WindowInsets.navigationBars.asPaddingValues())
.background(MaterialTheme.colorScheme.background),
modifier = Modifier.background(MaterialTheme.colorScheme.background),
) {
TopBar(
title = { Text(stringResource(Res.string.Settings_Websites_CustomURL_Title)) },
Expand All @@ -71,6 +71,7 @@ fun ChooseWebsitesScreen(

Box(Modifier.fillMaxSize()) {
LazyColumn(
modifier = Modifier.imePadding(),
contentPadding = PaddingValues(
bottom = WindowInsets.navigationBars.asPaddingValues()
.calculateBottomPadding() + 64.dp,
Expand Down Expand Up @@ -137,7 +138,8 @@ fun ChooseWebsitesScreen(
onClick = { onEvent(ChooseWebsitesViewModel.Event.RunClicked) },
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(WindowInsets.navigationBars.asPaddingValues())
.imePadding()
.navigationBarsPadding()
.padding(bottom = 16.dp),
) {
Icon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class RunViewModel(
tests =
selectedTests.map { (descriptor, tests) ->
RunSpecification.Test(
source = descriptor.source.id,
source = descriptor.source.id,
netTests = tests,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RunBackgroundTaskTest {
private fun buildSubject(
getPreferenceValueByKey: (SettingsKey) -> Flow<Any?> = { flowOf(true) },
uploadMissingMeasurements: (ResultModel.Id?) -> Flow<UploadMissingMeasurements.State> = { emptyFlow() },
checkSkipAutoRunNotUploadedLimit: () -> Flow<Boolean> = { flowOf(false) },
checkSkipAutoRunNotUploadedLimit: suspend () -> Boolean = { false },
getNetworkType: () -> NetworkType = { NetworkType.Wifi },
getAutoRunSpecification: suspend () -> RunSpecification.Full = {
RunSpecification.Full(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.ooni.probe.domain

import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
Expand All @@ -20,7 +19,7 @@ class CheckSkipAutoRunNotUploadedLimitTest {
CheckSkipAutoRunNotUploadedLimit(
countResultsMissingUpload = { flowOf(count) },
getPreferenceValueByKey = { flowOf(limit) },
)().first(),
)(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android-minSdk = "24"
android-targetSdk = "35"

compose-plugin = "1.7.0"
kotlin = "2.0.20"
kotlin = "2.1.0"
sqldelight = "2.0.2"
dataStoreVersion = "1.1.1"
junitKtx = "1.2.1"
Expand Down

0 comments on commit 1f47c8f

Please sign in to comment.