Skip to content
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

Persist rejected descriptor updates #425

Merged
merged 2 commits into from
Jan 31, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AndroidApplication : Application() {
startSingleRunInner = appWorkerManager::startSingleRun,
configureAutoRun = appWorkerManager::configureAutoRun,
configureDescriptorAutoUpdate = appWorkerManager::configureDescriptorAutoUpdate,
fetchDescriptorUpdate = appWorkerManager::fetchDescriptorUpdate,
startDescriptorsUpdate = appWorkerManager::startDescriptorsUpdate,
launchAction = ::launchAction,
batteryOptimization = batteryOptimization,
flavorConfig = FlavorConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AppWorkerManager(
}
}

suspend fun fetchDescriptorUpdate(descriptors: List<InstalledTestDescriptorModel>?) {
suspend fun startDescriptorsUpdate(descriptors: List<InstalledTestDescriptorModel>?) {
withContext(backgroundDispatcher) {
workManager
.enqueueUniqueWork(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

onboarding1.webp
onboarding2.webp
onboarding3.webp
onboarding.webp
onboarding3.webp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

onboarding1.webp
onboarding2.webp
onboarding3.webp
onboarding.webp
onboarding3.webp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

onboarding1.webp
onboarding2.webp
onboarding3.webp
onboarding.webp
onboarding3.webp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

onboarding1.webp
onboarding2.webp
onboarding3.webp
onboarding.webp
onboarding3.webp
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

onboarding1.webp
onboarding2.webp
onboarding3.webp
onboarding.webp
onboarding3.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,13 @@
<string name="Modal_EnableNotifications_Title">Get updates on internet censorship</string>

<string name="Dashboard_Runv2_Overview_LastUpdated">Last updated %1$s</string>
<string name="Dashboard_Runv2_Overview_RejectedUpdate">Rejected update</string>
<string name="Dashboard_Runv2_Overview_UndoRejectedUpdate">Undo</string>
<string name="Dashboard_RunTests_RunButton_Label_One">Run %1$d test</string>
<string name="Dashboard_RunTests_RunButton_Label_Other">Run %1$d tests</string>
<string name="Dashboard_Update_Ready">The app update has just been downloaded</string>
<string name="Dashboard_Update_Restart">Restart</string>
<string name="Dashboard_ReviewDescriptor_Reject">Reject Update</string>

<string name="AddDescriptor_Toasts_Unsupported_Url">Unsupported URL</string>

Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fun App(
dependencies.bootstrapTestDescriptors()
dependencies.bootstrapPreferences()
dependencies.configureDescriptorAutoUpdate()
dependencies.fetchDescriptorUpdate(null)
dependencies.startDescriptorsUpdate(null)
dependencies.startSingleRunInner(RunSpecification.OnlyUploadMissingResults)
}
LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ data class Descriptor(

val isExpired get() = expirationDate != null && expirationDate < LocalDateTime.now()

val updatable get() = updatedDescriptor != null

val updatedDescriptor
get() = when (updateStatus) {
is UpdateStatus.Updatable -> updateStatus.updatedDescriptor
is UpdateStatus.UpdateRejected -> updateStatus.updatedDescriptor
else -> null
}
get() = (updateStatus as? UpdateStatus.Updatable)?.updatedDescriptor

val key: String
get() = when (source) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.ooni.probe.data.models

enum class DescriptorUpdateOperationState {
Idle,
FetchingUpdates,
ReviewNecessaryNotice,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ooni.probe.data.models

data class DescriptorsUpdateState(
val availableUpdates: List<InstalledTestDescriptorModel> = emptyList(),
val autoUpdated: List<InstalledTestDescriptorModel> = emptyList(),
val operationState: DescriptorUpdateOperationState = DescriptorUpdateOperationState.Idle,
) {
private val availableUpdatesMap = availableUpdates.associateBy { it.id.value }
private val autoUpdatesMap = autoUpdated.associateBy { it.id.value }

fun getStatusOf(id: InstalledTestDescriptorModel.Id): UpdateStatus =
autoUpdatesMap[id.value]?.let { UpdateStatus.AutoUpdated }
?: availableUpdatesMap[id.value]?.let { UpdateStatus.Updatable(it) }
?: UpdateStatus.NoNewUpdate
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ data class InstalledTestDescriptorModel(
val dateCreated: LocalDateTime?,
val dateUpdated: LocalDateTime?,
val revisions: List<String>? = emptyList(),
val rejectedRevision: Long? = null,
val autoUpdate: Boolean,
) {
@Serializable
Expand Down Expand Up @@ -145,4 +146,5 @@ fun InstalledTestDescriptorModel.toDb(json: Json) =
Logger.e(e) { "Failed to encode revisions" }
null
},
rejected_revision = rejectedRevision,
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.ooni.probe.data.models

sealed class UpdateStatus {
data object Unknown : UpdateStatus()
sealed interface UpdateStatus {
data object Unknown : UpdateStatus

data object UpToDate : UpdateStatus()
data object NoNewUpdate : UpdateStatus

data class Updatable(val updatedDescriptor: InstalledTestDescriptorModel) : UpdateStatus()
data class Updatable(val updatedDescriptor: InstalledTestDescriptorModel) : UpdateStatus

data object AutoUpdated : UpdateStatus()
data object AutoUpdated : UpdateStatus

data object NotApplicable : UpdateStatus()

data class UpdateRejected(val updatedDescriptor: InstalledTestDescriptorModel) : UpdateStatus()
data object NotApplicable : UpdateStatus
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class TestDescriptorRepository(
date_updated = installedModel.date_updated,
auto_update = installedModel.auto_update,
revisions = installedModel.revisions,
rejected_revision = installedModel.rejected_revision,
)
}
}
Expand Down Expand Up @@ -103,6 +104,7 @@ class TestDescriptorRepository(
date_updated = installedModel.date_updated,
auto_update = installedModel.auto_update,
revisions = installedModel.revisions,
rejected_revision = installedModel.rejected_revision,
)
database.testDescriptorQueries.clearOldNetTests(
installedModel.runId,
Expand All @@ -125,6 +127,18 @@ class TestDescriptorRepository(
}
}

suspend fun updateRejectedRevision(
runId: InstalledTestDescriptorModel.Id,
rejectedRevision: Long?,
) {
withContext(backgroundContext) {
database.testDescriptorQueries.updateRejectedRevision(
runId = runId.value,
rejected_revision = rejectedRevision,
)
}
}

suspend fun deleteByRunId(runId: InstalledTestDescriptorModel.Id) {
withContext(backgroundContext) {
database.testDescriptorQueries.deleteByRunId(runId.value)
Expand Down Expand Up @@ -160,5 +174,6 @@ class TestDescriptorRepository(
emptyList()
}
},
rejectedRevision = rejected_revision,
)
}
Loading