Skip to content

Commit 1457054

Browse files
authored
Fix: Update rules for displaying an error message when test starts (#614)
Fixes ooni/probe#2468 ## Proposed Changes - Only display an error message if the `start_time` of the test is more than 5 minutes ago. ![Screenshot_20230904_090258](https://github.com/ooni/probe-android/assets/17911892/57af92a1-464c-4a89-8fc4-c899ee11a62c)
1 parent bccb236 commit 1457054

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.openobservatory.ooniprobe.databinding.ItemFailedBinding;
1313
import org.openobservatory.ooniprobe.model.database.Result;
1414

15+
import java.util.Date;
1516
import java.util.Locale;
17+
import static java.util.concurrent.TimeUnit.*;
1618

1719
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;
1820

@@ -39,8 +41,19 @@ public FailedItem(Result extra, View.OnClickListener onClickListener, View.OnLon
3941
viewHolder.binding.icon.setImageResource(extra.getTestSuite().getIcon());
4042
viewHolder.binding.testName.setText(extra.getTestSuite().getTitle());
4143
String failure_msg = viewHolder.itemView.getContext().getString(R.string.TestResults_Overview_Error);
42-
if (extra.failure_msg != null)
44+
if (extra.failure_msg != null) {
4345
failure_msg += " - " + extra.failure_msg;
46+
} else {
47+
// NOTE: If the test is running for more than 5 minutes, we assume it's stuck or failed,
48+
// and we show the default error message.
49+
long MAX_DURATION = MILLISECONDS.convert(5, MINUTES);
50+
long duration = new Date().getTime() - extra.start_time.getTime();
51+
if (duration < MAX_DURATION) {
52+
failure_msg = viewHolder.itemView.getContext()
53+
.getString(R.string.Dashboard_Running_Running)
54+
.replace(":","");
55+
}
56+
}
4457
viewHolder.binding.subtitle.setText(failure_msg);
4558
viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time));
4659
}

0 commit comments

Comments
 (0)