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 6ba430581..d03c3810e 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/MeasurementDetailActivity.java @@ -143,7 +143,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { detail = TelegramFragment.newInstance(measurement); break; case WebConnectivity.NAME: - head = HeaderOutcomeFragment.newInstance(iconRes, getString(R.string.outcomeHeader, measurement.url.url, + head = HeaderOutcomeFragment.newInstance(iconRes, getString(R.string.outcomeHeader, measurement.url != null ? measurement.url.url : "", getString(measurement.is_anomaly ? R.string.TestResults_Details_Websites_LikelyBlocked_Hero_Title : R.string.TestResults_Details_Websites_Reachable_Hero_Title))); diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/MKException.java b/app/src/main/java/org/openobservatory/ooniprobe/common/MKException.java index 396743793..e60a46031 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/MKException.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/MKException.java @@ -6,6 +6,10 @@ import org.openobservatory.ooniprobe.model.jsonresult.EventResult; public class MKException extends Exception { + public MKException(String failure) { + super(failure); + } + public MKException(EventResult event) { super(new Gson().toJson(event.value)); } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt index e97855cf4..0c22a9173 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt @@ -298,7 +298,7 @@ enum class OONITests( BaseNettest(name = "echcheck"), ), longRunningTests = listOf( - BaseNettest(name = "torsf"), + // BaseNettest(name = "torsf"), BaseNettest(name = "vanilla_tor"), ) ); diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/service/RunTestService.java b/app/src/main/java/org/openobservatory/ooniprobe/common/service/RunTestService.java index c7e4be148..3afd5ca50 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/service/RunTestService.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/service/RunTestService.java @@ -11,7 +11,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.os.Binder; +import android.os.Build; import android.os.IBinder; import android.util.Log; @@ -48,26 +50,7 @@ public class RunTestService extends Service { @Override public void onCreate() { super.onCreate(); - IntentFilter filter = new IntentFilter(ACTION_INTERRUPT); - receiver = new ActionReceiver(); - ContextCompat.registerReceiver(this, receiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED); - - LocalBroadcastManager.getInstance(this).registerReceiver( - new ProgressBroadcastReceiver(), - new IntentFilter("org.openobservatory.ooniprobe.activity.RunningActivity") - ); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - @SuppressWarnings("unchecked") - ArrayList testSuites = (ArrayList) intent.getSerializableExtra("testSuites"); - if (testSuites == null || testSuites.isEmpty()) - return START_STICKY_COMPATIBILITY; - boolean store_db = intent.getBooleanExtra("storeDB", true); - boolean unattended = intent.getBooleanExtra("unattended", false); Application app = ((Application) getApplication()); - app.getTestStateRepository().getTestGroupStatus().postValue(TestGroupStatus.RUNNING); NotificationUtility.setChannel(getApplicationContext(), CHANNEL_ID, app.getString(R.string.Settings_AutomatedTesting_Label), false, false, false); Intent notificationIntent = new Intent(this, RunningActivity.class); notificationIntent.setPackage("org.openobservatory.ooniprobe"); @@ -89,7 +72,41 @@ public int onStartCommand(Intent intent, int flags, int startId) { broadcastIntent.setAction(RunTestService.ACTION_INTERRUPT); PendingIntent pIntent = pendingIntentGetBroadcast(this, 1, broadcastIntent); builder.addAction(0, getApplicationContext().getString(R.string.Notification_StopTest), pIntent); - startForeground(NOTIFICATION_ID, builder.build()); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground( + NOTIFICATION_ID, + builder.build(), + ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC + ); + } else { + startForeground(NOTIFICATION_ID, builder.build()); + } + + IntentFilter filter = new IntentFilter(ACTION_INTERRUPT); + receiver = new ActionReceiver(); + ContextCompat.registerReceiver(this, receiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED); + + LocalBroadcastManager.getInstance(this).registerReceiver( + new ProgressBroadcastReceiver(), + new IntentFilter("org.openobservatory.ooniprobe.activity.RunningActivity") + ); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Application app = ((Application) getApplication()); + + app.getTestStateRepository().getTestGroupStatus().postValue(TestGroupStatus.RUNNING); + + // Ensure notification is shown before the test starts + @SuppressWarnings("unchecked") + ArrayList testSuites = (ArrayList) intent.getSerializableExtra("testSuites"); + if (testSuites == null || testSuites.isEmpty()) + return START_STICKY_COMPATIBILITY; + + boolean store_db = intent.getBooleanExtra("storeDB", true); + boolean unattended = intent.getBooleanExtra("unattended", false); task = (TestAsyncTask) new TestAsyncTask(app, testSuites, store_db, unattended).execute(); /* diff --git a/app/src/main/java/org/openobservatory/ooniprobe/test/test/AbstractTest.java b/app/src/main/java/org/openobservatory/ooniprobe/test/test/AbstractTest.java index f2e7c0c1d..4e4eab94f 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/test/test/AbstractTest.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/test/test/AbstractTest.java @@ -218,10 +218,20 @@ void run(Context c, PreferenceManager pm, AppLogger logger, Gson gson, Settings case "failure.startup": case "failure.resolver_lookup": setFailureMsg(event.value, result); - ThirdPartyServices.logException(new MKException(event)); + String failure = event.value.failure; + if (failure != null) { + ThirdPartyServices.logException(new MKException(failure)); + } else { + ThirdPartyServices.logException(new MKException(event)); + } break; case "bug.json_dump": - ThirdPartyServices.logException(new MKException(event)); + String failureMsg = event.value.failure; + if (failureMsg != null) { + ThirdPartyServices.logException(new MKException(failureMsg)); + } else { + ThirdPartyServices.logException(new MKException(event)); + } break; case "task_terminated": onTaskTerminated(event.value, c);