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

feat: add support for run v2 autorun #759

Merged
merged 1 commit into from
Jun 13, 2024
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 @@ -367,7 +367,7 @@ enum class OONITests(
}
}

fun autoRunTests(context: Context, preferenceManager: PreferenceManager): List<DynamicTestSuite> {
fun autoRunTests(context: Context, preferenceManager: PreferenceManager, testDescriptorManager: TestDescriptorManager): List<DynamicTestSuite> {

return ooniDescriptors(context).filter { ooniDescriptor ->
when (ooniDescriptor.name) {
Expand Down Expand Up @@ -439,6 +439,15 @@ fun autoRunTests(context: Context, preferenceManager: PreferenceManager): List<D
autoRun = true
}
}
}.toMutableList().also { descriptors ->
val runV2AtoRunTests: List<DynamicTestSuite> =
testDescriptorManager.getRunV2Descriptors(expired = false, autoRun = true)
.map { testDescriptor ->
testDescriptor.toDynamicTestSuite(context).apply {
autoRun = true
}
}
descriptors.addAll(runV2AtoRunTests)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ class TestDescriptorManager @Inject constructor(
}
}

fun getRunV2Descriptors(autoUpdate: Boolean? = null, expired: Boolean? = null): List<TestDescriptor> {
fun getRunV2Descriptors(autoUpdate: Boolean? = null, autoRun: Boolean? = null, expired: Boolean? = null): List<TestDescriptor> {
return SQLite.select().from(TestDescriptor::class.java)
.where(
autoUpdate?.let { TestDescriptor_Table.auto_update.eq(it) },
autoRun?.let { TestDescriptor_Table.auto_run.eq(it) },
expired?.let { TestDescriptor_Table.is_expired.eq(it) }
)
.orderBy(TestDescriptor_Table.is_expired.asc())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ReachabilityManager;
import org.openobservatory.ooniprobe.common.TestDescriptorManager;
import org.openobservatory.ooniprobe.domain.GenerateAutoRunServiceSuite;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite;
Expand Down Expand Up @@ -77,7 +78,7 @@ public static void startRunTestServiceUnattended(Application app) {
if (!d.generateAutoRunServiceSuite.shouldStart(config.isOnWiFi(), config.isCharging(), isVPNInUse)) {
return;
}
ServiceUtil.startRunTestServiceCommon(app, new ArrayList<>(autoRunTests(app, d.preferenceManager)), false, true);
ServiceUtil.startRunTestServiceCommon(app, new ArrayList<>(autoRunTests(app, d.preferenceManager, d.testDescriptorManager)), false, true);
d.generateAutoRunServiceSuite.markAsRan();

}
Expand Down Expand Up @@ -105,5 +106,8 @@ public static class Dependencies {

@Inject
PreferenceManager preferenceManager;

@Inject
TestDescriptorManager testDescriptorManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.openobservatory.ooniprobe.common.AppDatabase
import org.openobservatory.ooniprobe.common.LocaleUtils
import org.openobservatory.ooniprobe.common.PreferenceManager
import org.openobservatory.ooniprobe.common.resolveStatus
import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite
import java.io.Serializable
import java.util.Date
import com.raizlabs.android.dbflow.annotation.TypeConverter as TypeConverterAnnotation
Expand Down Expand Up @@ -104,6 +105,10 @@ class TestDescriptor(
fun localizedDescription() :String {
return descriptionIntl.getValueForKey(LocaleUtils.getLocale().language) ?: description
}

fun toDynamicTestSuite(context: Context) : DynamicTestSuite {
return InstalledDescriptor(this).getTest(context)
}
}

/**
Expand Down
Loading