Skip to content

Commit

Permalink
Merge pull request #20112 from wordpress-mobile/fix-in-app-reviews-crash
Browse files Browse the repository at this point in the history
Fix in app reviews crash
  • Loading branch information
notandyvee authored Feb 2, 2024
2 parents a5b16a5 + 7cbbb26 commit 6157742
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
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.ReviewManagerFactory;
import com.google.android.play.core.review.model.ReviewErrorCode;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
Expand Down Expand Up @@ -184,6 +182,7 @@
import static org.wordpress.android.login.LoginAnalyticsListener.CreatedAccountSource.EMAIL;
import static org.wordpress.android.push.NotificationsProcessingService.ARG_NOTIFICATION_TYPE;
import static org.wordpress.android.ui.JetpackConnectionSource.NOTIFICATIONS;
import static org.wordpress.android.util.extensions.InAppReviewExtensionsKt.logException;

import dagger.hilt.android.AndroidEntryPoint;

Expand Down Expand Up @@ -854,12 +853,7 @@ private void launchInAppReviews() {
Task<Void> flow = manager.launchReviewFlow(this, reviewInfo);
flow.addOnFailureListener(e -> AppLog.e(T.MAIN, "Error launching google review API flow.", e));
} else {
@ReviewErrorCode int reviewErrorCode = ((ReviewException) task.getException()).getErrorCode();
AppLog.e(
T.MAIN,
"Error fetching ReviewInfo object from Review API to start in-app review process",
reviewErrorCode
);
logException(task);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.google.android.material.snackbar.Snackbar
import com.google.android.play.core.review.ReviewException
import com.google.android.play.core.review.ReviewManagerFactory
import com.google.android.play.core.review.model.ReviewErrorCode
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.databinding.PostListActivityBinding
Expand Down Expand Up @@ -66,6 +64,7 @@ import org.wordpress.android.util.SnackbarItem
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import org.wordpress.android.util.extensions.logException
import org.wordpress.android.util.extensions.redirectContextClickToLongPressListener
import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout
import org.wordpress.android.viewmodel.observeEvent
Expand Down Expand Up @@ -360,12 +359,7 @@ class PostsListActivity : LocaleAwareActivity(),
AppLog.e(AppLog.T.POSTS, "Error launching google review API flow.", e)
}
} else {
@ReviewErrorCode val reviewErrorCode = (task.exception as ReviewException).errorCode
AppLog.e(
AppLog.T.POSTS,
"Error fetching ReviewInfo object from Review API to start in-app review process",
reviewErrorCode
)
task.logException()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.wordpress.android.util.extensions

import com.google.android.gms.tasks.Task
import com.google.android.play.core.review.ReviewException
import com.google.android.play.core.review.ReviewInfo
import com.google.android.play.core.review.model.ReviewErrorCode
import org.wordpress.android.util.AppLog

fun Task<ReviewInfo>.logException() {
val errorMessage = "Error fetching ReviewInfo object from Review API to start in-app review process"
(exception as? ReviewException)?.let {
@ReviewErrorCode val reviewErrorCode = it.errorCode
AppLog.e(AppLog.T.UTILS, errorMessage, reviewErrorCode)
} ?: AppLog.e(AppLog.T.UTILS, "$errorMessage: ${exception?.message}")
}

0 comments on commit 6157742

Please sign in to comment.