Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ kotlin {

jvm("desktop")
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.JETBRAINS)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AndroidOonimkallBridge : OonimkallBridge {
private fun OonimkallBridge.CheckInConfig.toMk() =
CheckInConfig().also {
it.charging = charging
it.onWiFi = onWiFi
if (onWiFi != null) it.onWiFi = onWiFi
it.platform = platform
it.runType = runType
it.softwareName = softwareName
Expand Down
7 changes: 6 additions & 1 deletion composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ class Engine(
val sessionConfig = buildSessionConfig(taskOrigin, preferences)
val session = session(sessionConfig)
try {
val networkType = networkTypeFinder()
session.checkIn(
OonimkallBridge.CheckInConfig(
charging = isBatteryCharging(),
onWiFi = networkTypeFinder() == NetworkType.Wifi,
onWiFi = if (networkType !is NetworkType.Unknown) {
networkType == NetworkType.Wifi
} else {
null
},
platform = platformInfo.platform.value,
runType = taskOrigin.runType,
softwareName = sessionConfig.softwareName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface OonimkallBridge {

data class CheckInConfig(
val charging: Boolean,
val onWiFi: Boolean,
val onWiFi: Boolean?,
// "android" or "ios"
val platform: String,
// "timed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class Dependencies(
getAutoRunSettings = getAutoRunSettings::invoke,
getNetworkType = networkTypeFinder::invoke,
getBatteryState = getBatteryState::invoke,
knownNetworkType = platformInfo.knownNetworkType,
knownBatteryState = platformInfo.knownBatteryState,
resultRepository::countMissingUpload,
)
Expand Down Expand Up @@ -317,6 +318,7 @@ class Dependencies(
observeStorageUsed = getStorageUsed::observe,
clearStorage = clearStorage::invoke,
supportsCrashReporting = flavorConfig.isCrashReportingEnabled,
knownNetworkType = platformInfo.knownNetworkType,
knownBatteryState = platformInfo.knownBatteryState,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CheckAutoRunConstraints(
private val getAutoRunSettings: suspend () -> Flow<AutoRunParameters>,
private val getNetworkType: () -> NetworkType,
private val getBatteryState: () -> BatteryState,
private val knownNetworkType: Boolean,
private val knownBatteryState: Boolean,
private val countResultsMissingUpload: () -> Flow<Long>,
) {
Expand All @@ -27,7 +28,10 @@ class CheckAutoRunConstraints(
return false
}

if (autoRunParameters.wifiOnly && getNetworkType() != NetworkType.Wifi) {
if (knownNetworkType &&
autoRunParameters.wifiOnly &&
getNetworkType() != NetworkType.Wifi
) {
Logger.i("Not starting auto-run because of Wi-Fi constraint")
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class GetSettings(
private val clearStorage: suspend (Boolean) -> Unit,
val observeStorageUsed: () -> Flow<Long>,
private val supportsCrashReporting: Boolean,
private val knownNetworkType: Boolean,
private val knownBatteryState: Boolean,
) {
operator fun invoke(): Flow<List<SettingsCategoryItem>> {
Expand Down Expand Up @@ -114,7 +115,7 @@ class GetSettings(
icon = Res.drawable.ic_settings,
title = Res.string.Settings_TestOptions_Label,
route = PreferenceCategoryKey.TEST_OPTIONS,
settings = listOf(
settings = listOfNotNull(
SettingsItem(
title = Res.string.Settings_Sharing_UploadResults,
key = SettingsKey.UPLOAD_RESULTS,
Expand All @@ -138,32 +139,29 @@ class GetSettings(
)
},
),
) + if (autoRunEnabled) {
listOf(
if (autoRunEnabled && knownNetworkType) {
SettingsItem(
title = Res.string.Settings_AutomatedTesting_RunAutomatically_WiFiOnly,
key = SettingsKey.AUTOMATED_TESTING_WIFIONLY,
type = PreferenceItemType.SWITCH,
enabled = autoRunEnabled && uploadResultsEnabled,
indentation = 1,
),
) + if (knownBatteryState) {
listOf(
SettingsItem(
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
type = PreferenceItemType.SWITCH,
enabled = autoRunEnabled && uploadResultsEnabled,
indentation = 1,
),
)
} else {
emptyList()
}
} else {
emptyList()
} + if (hasWebsitesDescriptor) {
listOfNotNull(
null
},
if (autoRunEnabled && knownBatteryState) {
SettingsItem(
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
type = PreferenceItemType.SWITCH,
enabled = autoRunEnabled && uploadResultsEnabled,
indentation = 1,
)
} else {
null
},
if (hasWebsitesDescriptor) {
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntimeEnabled_New,
key = SettingsKey.MAX_RUNTIME_ENABLED,
Expand All @@ -175,27 +173,26 @@ class GetSettings(
)
},
indentation = 0,
),
if (maxRuntimeEnabled) {
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntime_New,
key = SettingsKey.MAX_RUNTIME,
type = PreferenceItemType.INT,
supportingContent = {
maxRuntime?.let {
Text(it.coerceAtLeast(0).seconds.shortFormat())
}
},
indentation = 1,
)
} else {
null
},
)
} else {
emptyList()
} + if (hasWebsitesDescriptor) {
listOf(
)
} else {
null
},
if (hasWebsitesDescriptor && maxRuntimeEnabled) {
SettingsItem(
title = Res.string.Settings_Websites_MaxRuntime_New,
key = SettingsKey.MAX_RUNTIME,
type = PreferenceItemType.INT,
supportingContent = {
maxRuntime?.let {
Text(it.coerceAtLeast(0).seconds.shortFormat())
}
},
indentation = 1,
)
} else {
null
},
if (hasWebsitesDescriptor) {
SettingsCategoryItem(
title = Res.string.Settings_Websites_Categories_Label,
route = PreferenceCategoryKey.WEBSITES_CATEGORIES,
Expand All @@ -207,11 +204,11 @@ class GetSettings(
),
)
},
),
)
} else {
emptyList()
},
)
} else {
null
},
),
footerContent = {
SettingsDescription(
Res.string.Settings_AutomatedTesting_RunAutomatically_Footer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class PlatformInfo(
val model: String,
val requestNotificationsPermission: Boolean,
val knownBatteryState: Boolean = true,
val knownNetworkType: Boolean = true,
val sentryDsn: String,
) {
val version get() = "$buildName ($buildNumber)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CheckAutoRunConstraintsTest {
},
getNetworkType = { NetworkType.Wifi },
getBatteryState = { BatteryState.Charging },
knownNetworkType = true,
knownBatteryState = true,
countResultsMissingUpload = { flowOf(count) },
)(),
Expand All @@ -55,6 +56,7 @@ class CheckAutoRunConstraintsTest {
},
getNetworkType = { NetworkType.VPN },
getBatteryState = { BatteryState.Charging },
knownNetworkType = true,
knownBatteryState = true,
countResultsMissingUpload = { flowOf(0) },
)
Expand All @@ -80,6 +82,7 @@ class CheckAutoRunConstraintsTest {
},
getNetworkType = { NetworkType.Wifi },
getBatteryState = { batteryState },
knownNetworkType = true,
knownBatteryState = knownBatteryState,
countResultsMissingUpload = { flowOf(0) },
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DesktopOonimkallBridge : OonimkallBridge {
private fun OonimkallBridge.CheckInConfig.toMk() =
CheckInConfig().also {
it.charging = charging
it.onWiFi = onWiFi
if (onWiFi != null) it.onWiFi = onWiFi
it.platform = platform
it.runType = runType
it.softwareName = softwareName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private fun buildPlatformInfo() =
model = "model",
requestNotificationsPermission = false,
knownBatteryState = false,
knownNetworkType = false,
sentryDsn = "https://e33da707dc40ab9508198b62de9bc269@o155150.ingest.sentry.io/4509084408610816",
)

Expand All @@ -68,8 +69,11 @@ private fun readAssetFile(path: String): String {
throw NotImplementedError()
}

// TODO: Desktop - buildDatabaseDriver persist in storage instead of in memory
private fun networkTypeFinder() = NetworkType.Wifi
/*
* This is a dummy implementation for now.
* In the future we can write a proper implement using native APIs.
*/
private fun networkTypeFinder() = NetworkType.Unknown("unknown")

// TODO: Desktop - Confirm appropriate path and configuration
private fun buildDataStore() =
Expand Down
4 changes: 3 additions & 1 deletion iosApp/iosApp/engine/IosOonimkallBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ extension OonimkallBridgeCheckInConfig {
func toMk() -> OonimkallCheckInConfig {
let config = OonimkallCheckInConfig()
config.charging = charging
config.onWiFi = onWiFi
if onWiFi != nil {
config.onWiFi = onWiFi
}
config.platform = platform
config.runType = runType
config.softwareName = softwareName
Expand Down
Loading