From 145705464e393eb84437f7d596e4987bf8fdee79 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Wed, 18 Oct 2023 17:26:58 +0100 Subject: [PATCH] Fix: Update rules for displaying an error message when test starts (#614) Fixes https://github.com/ooni/probe/issues/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) --- .../ooniprobe/item/FailedItem.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java index 43171a5f4..4566b4341 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/FailedItem.java @@ -12,7 +12,9 @@ import org.openobservatory.ooniprobe.databinding.ItemFailedBinding; import org.openobservatory.ooniprobe.model.database.Result; +import java.util.Date; import java.util.Locale; +import static java.util.concurrent.TimeUnit.*; import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; @@ -39,8 +41,19 @@ public FailedItem(Result extra, View.OnClickListener onClickListener, View.OnLon viewHolder.binding.icon.setImageResource(extra.getTestSuite().getIcon()); viewHolder.binding.testName.setText(extra.getTestSuite().getTitle()); String failure_msg = viewHolder.itemView.getContext().getString(R.string.TestResults_Overview_Error); - if (extra.failure_msg != null) + if (extra.failure_msg != null) { failure_msg += " - " + extra.failure_msg; + } else { + // NOTE: If the test is running for more than 5 minutes, we assume it's stuck or failed, + // and we show the default error message. + long MAX_DURATION = MILLISECONDS.convert(5, MINUTES); + long duration = new Date().getTime() - extra.start_time.getTime(); + if (duration < MAX_DURATION) { + failure_msg = viewHolder.itemView.getContext() + .getString(R.string.Dashboard_Running_Running) + .replace(":",""); + } + } viewHolder.binding.subtitle.setText(failure_msg); viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); }