Skip to content

Commit 24977d2

Browse files
authored
Merge pull request #661 from ooni/desktop-network-unknown
Implement desktop network type as unknown
2 parents 6212bed + 88031b3 commit 24977d2

File tree

12 files changed

+72
-54
lines changed

12 files changed

+72
-54
lines changed

composeApp/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ kotlin {
6262

6363
jvm("desktop")
6464
jvmToolchain {
65-
languageVersion.set(JavaLanguageVersion.of(21))
65+
languageVersion.set(JavaLanguageVersion.of(17))
6666
vendor.set(JvmVendorSpec.JETBRAINS)
6767
}
6868

composeApp/src/androidMain/kotlin/org/ooni/engine/AndroidOonimkallBridge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AndroidOonimkallBridge : OonimkallBridge {
8585
private fun OonimkallBridge.CheckInConfig.toMk() =
8686
CheckInConfig().also {
8787
it.charging = charging
88-
it.onWiFi = onWiFi
88+
if (onWiFi != null) it.onWiFi = onWiFi
8989
it.platform = platform
9090
it.runType = runType
9191
it.softwareName = softwareName

composeApp/src/commonMain/kotlin/org/ooni/engine/Engine.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ class Engine(
9595
val sessionConfig = buildSessionConfig(taskOrigin, preferences)
9696
val session = session(sessionConfig)
9797
try {
98+
val networkType = networkTypeFinder()
9899
session.checkIn(
99100
OonimkallBridge.CheckInConfig(
100101
charging = isBatteryCharging(),
101-
onWiFi = networkTypeFinder() == NetworkType.Wifi,
102+
onWiFi = if (networkType !is NetworkType.Unknown) {
103+
networkType == NetworkType.Wifi
104+
} else {
105+
null
106+
},
102107
platform = platformInfo.platform.value,
103108
runType = taskOrigin.runType,
104109
softwareName = sessionConfig.softwareName,

composeApp/src/commonMain/kotlin/org/ooni/engine/OonimkallBridge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface OonimkallBridge {
5858

5959
data class CheckInConfig(
6060
val charging: Boolean,
61-
val onWiFi: Boolean,
61+
val onWiFi: Boolean?,
6262
// "android" or "ios"
6363
val platform: String,
6464
// "timed"

composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class Dependencies(
235235
getAutoRunSettings = getAutoRunSettings::invoke,
236236
getNetworkType = networkTypeFinder::invoke,
237237
getBatteryState = getBatteryState::invoke,
238+
knownNetworkType = platformInfo.knownNetworkType,
238239
knownBatteryState = platformInfo.knownBatteryState,
239240
resultRepository::countMissingUpload,
240241
)
@@ -319,6 +320,7 @@ class Dependencies(
319320
observeStorageUsed = getStorageUsed::observe,
320321
clearStorage = clearStorage::invoke,
321322
supportsCrashReporting = flavorConfig.isCrashReportingEnabled,
323+
knownNetworkType = platformInfo.knownNetworkType,
322324
knownBatteryState = platformInfo.knownBatteryState,
323325
)
324326
}

composeApp/src/commonMain/kotlin/org/ooni/probe/domain/CheckAutoRunConstraints.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CheckAutoRunConstraints(
1111
private val getAutoRunSettings: suspend () -> Flow<AutoRunParameters>,
1212
private val getNetworkType: () -> NetworkType,
1313
private val getBatteryState: () -> BatteryState,
14+
private val knownNetworkType: Boolean,
1415
private val knownBatteryState: Boolean,
1516
private val countResultsMissingUpload: () -> Flow<Long>,
1617
) {
@@ -27,7 +28,10 @@ class CheckAutoRunConstraints(
2728
return false
2829
}
2930

30-
if (autoRunParameters.wifiOnly && getNetworkType() != NetworkType.Wifi) {
31+
if (knownNetworkType &&
32+
autoRunParameters.wifiOnly &&
33+
getNetworkType() != NetworkType.Wifi
34+
) {
3135
Logger.i("Not starting auto-run because of Wi-Fi constraint")
3236
return false
3337
}

composeApp/src/commonMain/kotlin/org/ooni/probe/domain/GetSettings.kt

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class GetSettings(
7070
private val clearStorage: suspend (Boolean) -> Unit,
7171
val observeStorageUsed: () -> Flow<Long>,
7272
private val supportsCrashReporting: Boolean,
73+
private val knownNetworkType: Boolean,
7374
private val knownBatteryState: Boolean,
7475
) {
7576
operator fun invoke(): Flow<List<SettingsCategoryItem>> {
@@ -114,7 +115,7 @@ class GetSettings(
114115
icon = Res.drawable.ic_settings,
115116
title = Res.string.Settings_TestOptions_Label,
116117
route = PreferenceCategoryKey.TEST_OPTIONS,
117-
settings = listOf(
118+
settings = listOfNotNull(
118119
SettingsItem(
119120
title = Res.string.Settings_Sharing_UploadResults,
120121
key = SettingsKey.UPLOAD_RESULTS,
@@ -138,32 +139,29 @@ class GetSettings(
138139
)
139140
},
140141
),
141-
) + if (autoRunEnabled) {
142-
listOf(
142+
if (autoRunEnabled && knownNetworkType) {
143143
SettingsItem(
144144
title = Res.string.Settings_AutomatedTesting_RunAutomatically_WiFiOnly,
145145
key = SettingsKey.AUTOMATED_TESTING_WIFIONLY,
146146
type = PreferenceItemType.SWITCH,
147147
enabled = autoRunEnabled && uploadResultsEnabled,
148148
indentation = 1,
149-
),
150-
) + if (knownBatteryState) {
151-
listOf(
152-
SettingsItem(
153-
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
154-
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
155-
type = PreferenceItemType.SWITCH,
156-
enabled = autoRunEnabled && uploadResultsEnabled,
157-
indentation = 1,
158-
),
159149
)
160150
} else {
161-
emptyList()
162-
}
163-
} else {
164-
emptyList()
165-
} + if (hasWebsitesDescriptor) {
166-
listOfNotNull(
151+
null
152+
},
153+
if (autoRunEnabled && knownBatteryState) {
154+
SettingsItem(
155+
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
156+
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
157+
type = PreferenceItemType.SWITCH,
158+
enabled = autoRunEnabled && uploadResultsEnabled,
159+
indentation = 1,
160+
)
161+
} else {
162+
null
163+
},
164+
if (hasWebsitesDescriptor) {
167165
SettingsItem(
168166
title = Res.string.Settings_Websites_MaxRuntimeEnabled_New,
169167
key = SettingsKey.MAX_RUNTIME_ENABLED,
@@ -175,27 +173,26 @@ class GetSettings(
175173
)
176174
},
177175
indentation = 0,
178-
),
179-
if (maxRuntimeEnabled) {
180-
SettingsItem(
181-
title = Res.string.Settings_Websites_MaxRuntime_New,
182-
key = SettingsKey.MAX_RUNTIME,
183-
type = PreferenceItemType.INT,
184-
supportingContent = {
185-
maxRuntime?.let {
186-
Text(it.coerceAtLeast(0).seconds.shortFormat())
187-
}
188-
},
189-
indentation = 1,
190-
)
191-
} else {
192-
null
193-
},
194-
)
195-
} else {
196-
emptyList()
197-
} + if (hasWebsitesDescriptor) {
198-
listOf(
176+
)
177+
} else {
178+
null
179+
},
180+
if (hasWebsitesDescriptor && maxRuntimeEnabled) {
181+
SettingsItem(
182+
title = Res.string.Settings_Websites_MaxRuntime_New,
183+
key = SettingsKey.MAX_RUNTIME,
184+
type = PreferenceItemType.INT,
185+
supportingContent = {
186+
maxRuntime?.let {
187+
Text(it.coerceAtLeast(0).seconds.shortFormat())
188+
}
189+
},
190+
indentation = 1,
191+
)
192+
} else {
193+
null
194+
},
195+
if (hasWebsitesDescriptor) {
199196
SettingsCategoryItem(
200197
title = Res.string.Settings_Websites_Categories_Label,
201198
route = PreferenceCategoryKey.WEBSITES_CATEGORIES,
@@ -207,11 +204,11 @@ class GetSettings(
207204
),
208205
)
209206
},
210-
),
211-
)
212-
} else {
213-
emptyList()
214-
},
207+
)
208+
} else {
209+
null
210+
},
211+
),
215212
footerContent = {
216213
SettingsDescription(
217214
Res.string.Settings_AutomatedTesting_RunAutomatically_Footer,

composeApp/src/commonMain/kotlin/org/ooni/probe/shared/PlatformInfo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class PlatformInfo(
88
val model: String,
99
val requestNotificationsPermission: Boolean,
1010
val knownBatteryState: Boolean = true,
11+
val knownNetworkType: Boolean = true,
1112
val sentryDsn: String,
1213
) {
1314
val version get() = "$buildName ($buildNumber)"

composeApp/src/commonTest/kotlin/org/ooni/probe/domain/CheckAutoRunConstraintsTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CheckAutoRunConstraintsTest {
3131
},
3232
getNetworkType = { NetworkType.Wifi },
3333
getBatteryState = { BatteryState.Charging },
34+
knownNetworkType = true,
3435
knownBatteryState = true,
3536
countResultsMissingUpload = { flowOf(count) },
3637
)(),
@@ -55,6 +56,7 @@ class CheckAutoRunConstraintsTest {
5556
},
5657
getNetworkType = { NetworkType.VPN },
5758
getBatteryState = { BatteryState.Charging },
59+
knownNetworkType = true,
5860
knownBatteryState = true,
5961
countResultsMissingUpload = { flowOf(0) },
6062
)
@@ -80,6 +82,7 @@ class CheckAutoRunConstraintsTest {
8082
},
8183
getNetworkType = { NetworkType.Wifi },
8284
getBatteryState = { batteryState },
85+
knownNetworkType = true,
8386
knownBatteryState = knownBatteryState,
8487
countResultsMissingUpload = { flowOf(0) },
8588
)()

composeApp/src/desktopMain/kotlin/org/ooni/engine/DesktopOonimkallBridge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class DesktopOonimkallBridge : OonimkallBridge {
8585
private fun OonimkallBridge.CheckInConfig.toMk() =
8686
CheckInConfig().also {
8787
it.charging = charging
88-
it.onWiFi = onWiFi
88+
if (onWiFi != null) it.onWiFi = onWiFi
8989
it.platform = platform
9090
it.runType = runType
9191
it.softwareName = softwareName

0 commit comments

Comments
 (0)