From ee373da8a5ff61fadf61c1217234b8e51941282a Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Mon, 28 Oct 2024 19:46:46 +0100 Subject: [PATCH] fix: prominent google play errors. --- .../ooniprobe/activity/ResultDetailActivity.kt | 10 +++++++++- .../ooniprobe/common/service/RunTestService.java | 10 ++++++++-- .../ooniprobe/fragment/ProgressFragment.kt | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/ResultDetailActivity.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/ResultDetailActivity.kt index a6ef2de56..f84be8dee 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/ResultDetailActivity.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/ResultDetailActivity.kt @@ -24,6 +24,7 @@ import org.openobservatory.ooniprobe.common.OONIDescriptor import org.openobservatory.ooniprobe.common.OONITests import org.openobservatory.ooniprobe.common.PreferenceManager import org.openobservatory.ooniprobe.common.ResubmitTask +import org.openobservatory.ooniprobe.common.ThirdPartyServices import org.openobservatory.ooniprobe.databinding.ActivityResultDetailBinding import org.openobservatory.ooniprobe.domain.GetResults import org.openobservatory.ooniprobe.domain.GetTestSuite @@ -85,7 +86,14 @@ class ResultDetailActivity : AbstractActivity(), View.OnClickListener, OnConfirm else -> { result = iResult - result.getTestSuite(this@ResultDetailActivity).get()?.themeLight?.let { setTheme(it) } + val optionalSuite = result.getTestSuite(this@ResultDetailActivity) + if (optionalSuite.isPresent){ + try { + setTheme(optionalSuite.get().themeLight) + } catch (e: Exception) { + ThirdPartyServices.logException(e) + } + } binding = ActivityResultDetailBinding.inflate(layoutInflater) setContentView(binding.root) setSupportActionBar(binding.toolbar) 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 d434722c6..c7e4be148 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 @@ -84,13 +84,14 @@ public int onStartCommand(Intent intent, int flags, int startId) { .setProgress(100, 0, false) .build(); - task = (TestAsyncTask) new TestAsyncTask(app, testSuites, store_db, unattended).execute(); //This intent is used to manage the stop test button in the notification Intent broadcastIntent = new Intent(); 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()); + + task = (TestAsyncTask) new TestAsyncTask(app, testSuites, store_db, unattended).execute(); /* START_NOT_STICKY says that, after returning from onStartCreated(), if the process is killed with no remaining start commands to deliver, @@ -202,7 +203,12 @@ public void stopTest() { public synchronized void interrupt() { task.interrupt(); if (task.isInterrupted()) { - ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE); + try { + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE); + stopSelf(); + } catch (Exception e) { + ThirdPartyServices.logException(e); + } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ProgressFragment.kt b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ProgressFragment.kt index aff9e330a..3b3c5d8ff 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ProgressFragment.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ProgressFragment.kt @@ -91,7 +91,7 @@ class ProgressFragment : Fragment() { } private fun updateUI(service: RunTestService?) { - if ((requireActivity().application as Application).isTestRunning) { + if (isAdded && (requireActivity().application as Application).isTestRunning) { val progressLevel = testProgressRepository.progress.value when { progressLevel != null -> {