Skip to content

Commit 9d8aee6

Browse files
committed
Implement desktop network type as unknown
1 parent 12a3a76 commit 9d8aee6

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
@@ -90,10 +90,15 @@ class Engine(
9090
val sessionConfig = buildSessionConfig(taskOrigin, preferences)
9191
val session = session(sessionConfig)
9292
try {
93+
val networkType = networkTypeFinder()
9394
session.checkIn(
9495
OonimkallBridge.CheckInConfig(
9596
charging = isBatteryCharging(),
96-
onWiFi = networkTypeFinder() == NetworkType.Wifi,
97+
onWiFi = if (networkType !is NetworkType.Unknown) {
98+
networkType == NetworkType.Wifi
99+
} else {
100+
null
101+
},
97102
platform = platformInfo.platform.value,
98103
runType = taskOrigin.runType,
99104
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
@@ -233,6 +233,7 @@ class Dependencies(
233233
getAutoRunSettings = getAutoRunSettings::invoke,
234234
getNetworkType = networkTypeFinder::invoke,
235235
getBatteryState = getBatteryState::invoke,
236+
knownNetworkType = platformInfo.knownNetworkType,
236237
knownBatteryState = platformInfo.knownBatteryState,
237238
resultRepository::countMissingUpload,
238239
)
@@ -317,6 +318,7 @@ class Dependencies(
317318
observeStorageUsed = getStorageUsed::observe,
318319
clearStorage = clearStorage::invoke,
319320
supportsCrashReporting = flavorConfig.isCrashReportingEnabled,
321+
knownNetworkType = platformInfo.knownNetworkType,
320322
knownBatteryState = platformInfo.knownBatteryState,
321323
supportsNotificationSettings = platformInfo.supportsNotificationSettings,
322324
)

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
@@ -74,6 +74,7 @@ class GetSettings(
7474
private val clearStorage: suspend (Boolean) -> Unit,
7575
val observeStorageUsed: () -> Flow<Long>,
7676
private val supportsCrashReporting: Boolean,
77+
private val knownNetworkType: Boolean,
7778
private val knownBatteryState: Boolean,
7879
private val supportsNotificationSettings: Boolean,
7980
) {
@@ -140,7 +141,7 @@ class GetSettings(
140141
icon = Res.drawable.ic_settings,
141142
title = Res.string.Settings_TestOptions_Label,
142143
route = PreferenceCategoryKey.TEST_OPTIONS,
143-
settings = listOf(
144+
settings = listOfNotNull(
144145
SettingsItem(
145146
title = Res.string.Settings_Sharing_UploadResults,
146147
key = SettingsKey.UPLOAD_RESULTS,
@@ -164,32 +165,29 @@ class GetSettings(
164165
)
165166
},
166167
),
167-
) + if (autoRunEnabled) {
168-
listOf(
168+
if (autoRunEnabled && knownNetworkType) {
169169
SettingsItem(
170170
title = Res.string.Settings_AutomatedTesting_RunAutomatically_WiFiOnly,
171171
key = SettingsKey.AUTOMATED_TESTING_WIFIONLY,
172172
type = PreferenceItemType.SWITCH,
173173
enabled = autoRunEnabled && uploadResultsEnabled,
174174
indentation = 1,
175-
),
176-
) + if (knownBatteryState) {
177-
listOf(
178-
SettingsItem(
179-
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
180-
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
181-
type = PreferenceItemType.SWITCH,
182-
enabled = autoRunEnabled && uploadResultsEnabled,
183-
indentation = 1,
184-
),
185175
)
186176
} else {
187-
emptyList()
188-
}
189-
} else {
190-
emptyList()
191-
} + if (hasWebsitesDescriptor) {
192-
listOfNotNull(
177+
null
178+
},
179+
if (autoRunEnabled && knownBatteryState) {
180+
SettingsItem(
181+
title = Res.string.Settings_AutomatedTesting_RunAutomatically_ChargingOnly,
182+
key = SettingsKey.AUTOMATED_TESTING_CHARGING,
183+
type = PreferenceItemType.SWITCH,
184+
enabled = autoRunEnabled && uploadResultsEnabled,
185+
indentation = 1,
186+
)
187+
} else {
188+
null
189+
},
190+
if (hasWebsitesDescriptor) {
193191
SettingsItem(
194192
title = Res.string.Settings_Websites_MaxRuntimeEnabled_New,
195193
key = SettingsKey.MAX_RUNTIME_ENABLED,
@@ -201,27 +199,26 @@ class GetSettings(
201199
)
202200
},
203201
indentation = 0,
204-
),
205-
if (maxRuntimeEnabled) {
206-
SettingsItem(
207-
title = Res.string.Settings_Websites_MaxRuntime_New,
208-
key = SettingsKey.MAX_RUNTIME,
209-
type = PreferenceItemType.INT,
210-
supportingContent = {
211-
maxRuntime?.let {
212-
Text(it.coerceAtLeast(0).seconds.shortFormat())
213-
}
214-
},
215-
indentation = 1,
216-
)
217-
} else {
218-
null
219-
},
220-
)
221-
} else {
222-
emptyList()
223-
} + if (hasWebsitesDescriptor) {
224-
listOf(
202+
)
203+
} else {
204+
null
205+
},
206+
if (hasWebsitesDescriptor && maxRuntimeEnabled) {
207+
SettingsItem(
208+
title = Res.string.Settings_Websites_MaxRuntime_New,
209+
key = SettingsKey.MAX_RUNTIME,
210+
type = PreferenceItemType.INT,
211+
supportingContent = {
212+
maxRuntime?.let {
213+
Text(it.coerceAtLeast(0).seconds.shortFormat())
214+
}
215+
},
216+
indentation = 1,
217+
)
218+
} else {
219+
null
220+
},
221+
if (hasWebsitesDescriptor) {
225222
SettingsCategoryItem(
226223
title = Res.string.Settings_Websites_Categories_Label,
227224
route = PreferenceCategoryKey.WEBSITES_CATEGORIES,
@@ -233,11 +230,11 @@ class GetSettings(
233230
),
234231
)
235232
},
236-
),
237-
)
238-
} else {
239-
emptyList()
240-
},
233+
)
234+
} else {
235+
null
236+
},
237+
),
241238
footerContent = {
242239
SettingsDescription(
243240
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
@@ -9,6 +9,7 @@ data class PlatformInfo(
99
val needsToRequestNotificationsPermission: Boolean,
1010
val supportsNotificationSettings: Boolean = true,
1111
val knownBatteryState: Boolean = true,
12+
val knownNetworkType: Boolean = true,
1213
val sentryDsn: String,
1314
) {
1415
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)