diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java b/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java index 4c49d1fd6..40e8d351a 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java @@ -194,7 +194,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { @Override public void onSuccess(ApiMeasurement.Result result) { measurement.deleteEntryFile(c); - measurement.deleteLogFileAfterAWeek(c); isInExplorer = true; } @Override diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/Application.java b/app/src/main/java/org/openobservatory/ooniprobe/common/Application.java index 04afe26eb..1081f00a9 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/Application.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/Application.java @@ -9,6 +9,7 @@ import org.openobservatory.ooniprobe.BuildConfig; import org.openobservatory.ooniprobe.client.OONIAPIClient; import org.openobservatory.ooniprobe.client.OONIOrchestraClient; +import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.jsonresult.TestKeys; import java.io.IOException; @@ -46,7 +47,7 @@ public class Application extends android.app.Application { // Code commented to prevent callling API on app start //if (preferenceManager.canCallDeleteJson()) // Measurement.deleteUploadedJsons(this); - + Measurement.deleteOldLogs(this); } public OkHttpClient getOkHttpClient() { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Measurement.java b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Measurement.java index 34542f168..fa2ef1bf4 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/model/database/Measurement.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/model/database/Measurement.java @@ -75,6 +75,13 @@ public Measurement(Result result, String test_name, String report_id) { start_time = new java.util.Date(); } + public static Where selectDone() { + return SQLite.select().from(Measurement.class) + .where(Measurement_Table.is_failed.eq(false)) + .and(Measurement_Table.is_rerun.eq(false)) + .and(Measurement_Table.is_done.eq(true)); + } + public static Where selectUploadable() { // We check on both the report_id and is_uploaded as we // may have some unuploaded measurements which are marked @@ -116,6 +123,17 @@ public static List selectMeasurementsWithJson(Context c) { return measurementsJson; } + public static List selectMeasurementsWithLog(Context c) { + Where msmQuery = Measurement.selectDone(); + List measurementsLog = new ArrayList<>(); + List measurements = msmQuery.queryList(); + for (Measurement measurement : measurements){ + if (measurement.hasReportFile(c)) + measurementsLog.add(measurement); + } + return measurementsLog; + } + public static File getEntryFile(Context c, int measurementId, String test_name) { return new File(getMeasurementDir(c), measurementId + "_" + test_name + ".json"); } @@ -225,7 +243,6 @@ public static void deleteUploadedJsons(Application a){ @Override public void onSuccess(ApiMeasurement.Result result) { measurement.deleteEntryFile(a); - measurement.deleteLogFileAfterAWeek(a); } @Override @@ -237,6 +254,14 @@ public void onError(String msg) { pm.setLastCalled(); } + public static void deleteOldLogs(Application a){ + List measurements = Measurement.selectMeasurementsWithLog(a); + for (int i = 0; i < measurements.size(); i++) { + Measurement measurement = measurements.get(i); + measurement.deleteLogFileAfterAWeek(a); + } + } + public void setReRun(Context c){ this.deleteEntryFile(c); this.deleteLogFile(c);