tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit c25e07ef5b3c775b314dd9af76688cf1ead8ee42
parent 08c6e2464d7ac105490e601eec1390e6edef190b
Author: Jonathan Almeida <jonalmeida942@gmail.com>
Date:   Mon,  6 Oct 2025 20:19:34 -0400

Bug 1992849 - Do not call getResult when we do not complete successfully. r=tcampbell

This patch fixes various bugs observed through our crash logs:
1. The documentation for [`Task.getResult`][0] says that it can throw
   multiple exceptions, so we shouldn't try to call it from a
   non-successful context. A simple attempt to pipe through the
   `reviewErrorCode` would allow telemetry to continue working, but
   a follow-up patch could make use of the propagated error code.
2. The `Task.getException` is not always a `ReviewException`, so
   type-casting it as such would mean that we crash at this point.
3. When we are in the case where the Play Store does not exist, we throw
   an `ActivityNotFoundException` and attempt to load the Play Store
   link to review the app (and I'm not sure why we would logically do
   that), we call `tryLaunchPlayStoreReview` which was written such that
   it would only navigate to the browser if called from the Settings. We
   change the direction to `FromGlobal` to circumvent this problem. Its
   unclear what the original intention might have been to use this value
   for if not telemetry.

[0]: https://developers.google.com/android/reference/com/google/android/gms/tasks/Task#getResult()

Differential Revision: https://phabricator.services.mozilla.com/D267713

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/PlayStoreReviewPromptController.kt | 21++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/PlayStoreReviewPromptController.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/PlayStoreReviewPromptController.kt @@ -12,7 +12,6 @@ import androidx.core.net.toUri import com.google.android.play.core.review.ReviewException import com.google.android.play.core.review.ReviewInfo import com.google.android.play.core.review.ReviewManager -import com.google.android.play.core.review.model.ReviewErrorCode import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import mozilla.components.support.base.log.logger.Logger @@ -42,20 +41,25 @@ class PlayStoreReviewPromptController( val reviewInfoFlow = withContext(Dispatchers.IO) { manager.requestReviewFlow() } reviewInfoFlow.addOnCompleteListener { - if (it.isSuccessful) { + val resultString = if (it.isSuccessful) { logger.info("Review flow launched.") // Launch the in-app flow. manager.launchReviewFlow(activity, it.result) + + it.result.toString() } else { // Launch the Play store flow. - @ReviewErrorCode val reviewErrorCode = (it.exception as ReviewException).errorCode + val reviewErrorCode = + (it.exception as? ReviewException)?.errorCode ?: ERROR_CODE_UNEXPECTED logger.warn("Failed to launch in-app review flow due to: $reviewErrorCode .") tryLaunchPlayStoreReview(activity) + + "reviewErrorCode=$reviewErrorCode" } recordReviewPromptEvent( - reviewInfoAsString = it.result.toString(), + reviewInfoAsString = resultString, numberOfAppLaunches = numberOfAppLaunches(), now = Date(), ) @@ -81,13 +85,20 @@ class PlayStoreReviewPromptController( (activity as HomeActivity).openToBrowserAndLoad( searchTermOrURL = SupportUtils.FENIX_PLAY_STORE_URL, newTab = true, - from = BrowserDirection.FromSettings, + from = BrowserDirection.FromGlobal, ) logger.warn("Failed to launch play store review flow due to: $e .") } logger.info("tryLaunchPlayStoreReview completed.") } + + companion object { + /** + * Placeholder for unexpected exception type. + */ + private const val ERROR_CODE_UNEXPECTED: Int = -42 + } } /**