WordPress-Android icon indicating copy to clipboard operation
WordPress-Android copied to clipboard

ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

Open sentry[bot] opened this issue 1 year ago • 5 comments

Sentry Issue: WORDPRESS-ANDROID-2Y5B

ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
    at org.wordpress.android.login.LoginBaseFormFragment.endProgress(LoginBaseFormFragment.java:273)
    at org.wordpress.android.ui.accounts.signup.SignupEpilogueFragment.access$200(SignupEpilogueFragment.java:103)
    public class SignupEpilogueFragment extends LoginBaseFormFragment<SignupEpilogueListener>
    at org.wordpress.android.ui.accounts.signup.SignupEpilogueFragment$13.onError(SignupEpilogueFragment.java:752)
    endProgress();
...
(20 additional frame(s) were not displayed)

sentry[bot] avatar Apr 30 '24 21:04 sentry[bot]

Thanks for reporting! 👍

dangermattic avatar Apr 30 '24 21:04 dangermattic

@maxme, I did a quick investigation about this issue and it looks like the new Gravatar-related code, introduced by you in https://github.com/wordpress-mobile/WordPress-Android/pull/20590, is causing this crash in WordPress 24.7, which currently seems to have affected only a few users.

I am adding you as an assignee but feel free to assign someone else if it makes sense.

What I believe to be the root cause of the issue is that the AvatarService.upload method runs inside a coroutine in a background thread and also calls the callbacks from GravatarListener from within that background thread, but endProgress called by both callbacks needs to run on the UI thread, and the thread is not being switched anywhere.

https://github.com/wordpress-mobile/WordPress-Android/blob/9eb84303b230f36698d7b03c5552f9239b42d85e/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java#L740-L758

A couple of quick fix suggestions I could think of are:

  1. Use getActivity().runOnUiThread in the WP-Android-side around any parts of callback code that interact with the UI (endProgress, setVisibility, etc)
  2. Make changes in the Gravatar-SDK-Android AvatarService to always call listener callbacks in the UI thread, which is usually the expected behavior in APIs than own their background execution (something like using withContext(Dispatchers.Main) around the code that calls onSuccess andonError).

Anyway, these are just suggestion I could come up with after doing a quick investigation, so feel free to ignore them if it doesn't make sense as well.

thomashorta avatar Apr 30 '24 21:04 thomashorta

Thanks @thomashorta for investigating, yeah I think having onSuccess and onError running on the main Android thread is best, I'll fix it in a 0.2.1 release of gravatar.

maxme avatar May 02 '24 08:05 maxme

Sentry Issue: JETPACK-ANDROID-R1X

sentry[bot] avatar May 09 '24 21:05 sentry[bot]

Sentry Issue: JETPACK-ANDROID-R3V

sentry[bot] avatar May 14 '24 16:05 sentry[bot]

This appears to have been resolved by #20795.

jkmassel avatar Aug 28 '24 03:08 jkmassel