/
WebConnectivity.java
56 lines (46 loc) · 2.1 KB
/
WebConnectivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.openobservatory.ooniprobe.test.test;
import android.content.Context;
import com.google.gson.Gson;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.model.jsonresult.JsonResult;
import org.openobservatory.ooniprobe.model.settings.Settings;
import androidx.annotation.NonNull;
public class WebConnectivity extends AbstractTest {
public static final String NAME = "web_connectivity";
private static final String MK_NAME = "WebConnectivity";
public WebConnectivity() {
super(NAME, MK_NAME, R.string.Test_WebConnectivity_Fullname, 0, R.string.urlTestWeb, 5);
}
@Override public void run(Context c, PreferenceManager pm, Gson gson, Result result, int index, TestCallback testCallback) {
Settings settings = new Settings(c, pm);
run(c, pm, gson, settings, result, index, testCallback);
}
@Override public void onEntry(Context c, PreferenceManager pm, @NonNull JsonResult json, Measurement measurement) {
super.onEntry(c, pm, json, measurement);
if (json.test_keys.blocking == null)
measurement.is_failed = true;
else
measurement.is_anomaly = !json.test_keys.blocking.equals("false");
}
/*
if the option max_runtime is already set in the option and is not MAX_RUNTIME_DISABLED let's use it
else if the input are sets we calculate 5 seconds per input
at last we check if max_runtime is enabled, in that case we use the value in the settings
first two cases : test is already running and with options and/or URL s
last two cases : get max_runtime saved in the preference
*/
@Override public int getRuntime(PreferenceManager pm) {
if (getMax_runtime() != null &&
getMax_runtime() > PreferenceManager.MAX_RUNTIME_DISABLED)
return 30 + getMax_runtime();
else if (getInputs() != null)
return 30 + getInputs().size() * super.getRuntime(pm);
else if(pm.isMaxRuntimeEnabled())
return 30 + pm.getMaxRuntime();
else
return PreferenceManager.MAX_RUNTIME_DISABLED;
}
}