Skip to content

Commit

Permalink
fix: restructure RunTestService start command and remove torsf fr…
Browse files Browse the repository at this point in the history
…om tests (#876)
  • Loading branch information
aanorbel authored Jan 21, 2025
1 parent 769349c commit 806621d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ enum class OONITests(
BaseNettest(name = "echcheck"),
),
longRunningTests = listOf(
BaseNettest(name = "torsf"),
// BaseNettest(name = "torsf"),
BaseNettest(name = "vanilla_tor"),
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AbstractSuite> testSuites = (ArrayList<AbstractSuite>) 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");
Expand All @@ -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<AbstractSuite> testSuites = (ArrayList<AbstractSuite>) 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();
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 806621d

Please sign in to comment.