Last Comment Bug 786312 - android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java) at android.widget.PopupWindow.dismiss(PopupWindow.java)
: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original t...
Status: VERIFIED FIXED
[native-crash]
: crash, topcrash
Product: Firefox for Android
Classification: Client Software
Component: General (show other bugs)
: 17 Branch
: ARM Android
: -- critical (vote)
: Firefox 18
Assigned To: Chris Peterson [:cpeterson]
:
Mentors:
Depends on: 792702
Blocks: 769894 790180
  Show dependency treegraph
 
Reported: 2012-08-28 09:30 PDT by Scoobidiver (away)
Modified: 2016-07-29 14:29 PDT (History)
7 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
+
fixed
+
verified
verified
verified
verified
+


Attachments
create-dialog-on-UI-thread.patch (3.19 KB, patch)
2012-09-13 12:43 PDT, Chris Peterson [:cpeterson]
sriram.mozilla: review+
akeybl: approval‑mozilla‑aurora+
akeybl: approval‑mozilla‑beta+
Details | Diff | Splinter Review

Description Scoobidiver (away) 2012-08-28 09:30:56 PDT
There are three crashes from the same user in 17.0a2, including bp-58915590-e391-471f-910a-f758e2120828.

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4862)
	at android.view.ViewRootImpl.doDie(ViewRootImpl.java:4199)
	at android.view.ViewRootImpl.die(ViewRootImpl.java:4186)
	at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:394)
	at android.view.WindowManagerImpl$CompatModeWrapper.removeViewImmediate(WindowManagerImpl.java:170)
	at android.widget.PopupWindow.dismiss(PopupWindow.java:1288)
	at android.widget.Editor$HandleView.dismiss(Editor.java:3293)
	at android.widget.Editor$HandleView.hide(Editor.java:3300)
	at android.widget.Editor$1.onOrientationChanged(Editor.java:241)
	at android.view.OrientationEventListener$SensorEventListenerImpl.onSensorChanged(OrientationEventListener.java:143)
	at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:247)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4898)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
	at dalvik.system.NativeStart.main(Native Method)

More reports at:
https://crash-stats.mozilla.com/report/list?signature=android.view.ViewRootImpl%24CalledFromWrongThreadException%3A+Only+the+original+thread+that+created+a+view+hierarchy+can+touch+its+views.+at+android.view.ViewRootImpl.checkThread%28ViewRootImpl.java%29
Comment 1 Naoki Hirata :nhirata (please use needinfo instead of cc) 2012-08-28 09:38:29 PDT
about:blank was the only URL listed at this moment in time.
Comment 2 Chris Peterson [:cpeterson] 2012-08-28 10:46:32 PDT
sriram, the UI thread is complaining that it is touching a view created on another thread. Do you know why or where we would create a view on an background thread instead of the UI thread??
Comment 3 Sriram Ramasubramanian [:sriram] 2012-08-30 13:54:01 PDT
Probable option: 
https://hg.mozilla.org/mozilla-central/file/tip/mobile/android/base/AndroidImportPreference.java#l70
Dialog is created and shown in some thread, but dismissed in UI thread.
Comment 4 Aaron Train [:aaronmt] 2012-09-13 08:14:06 PDT
STR on Nightly (09/13)

Install Phony, pull up the Phony menu and scroll through it. I hit this crash each and every single.

bp-d34aece7-7f52-4130-a20c-bbafe2120913
Comment 5 Aaron Train [:aaronmt] 2012-09-13 08:15:44 PDT
W/dalvikvm( 7439): threadid=10: thread exiting with uncaught exception (group=0x41dda300)
E/GeckoAppShell( 7439): >>> REPORTING UNCAUGHT EXCEPTION FROM THREAD 638 ("GeckoBackgroundThread")
E/GeckoAppShell( 7439): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
E/GeckoAppShell( 7439): 	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4607)
E/GeckoAppShell( 7439): 	at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:835)
E/GeckoAppShell( 7439): 	at android.view.View.requestLayout(View.java:15129)
E/GeckoAppShell( 7439): 	at android.view.View.requestLayout(View.java:15129)
E/GeckoAppShell( 7439): 	at android.widget.AbsListView.requestLayout(AbsListView.java:1928)
E/GeckoAppShell( 7439): 	at android.widget.ListView.setSelectionFromTop(ListView.java:1927)
E/GeckoAppShell( 7439): 	at android.widget.ListView.setSelection(ListView.java:1889)
E/GeckoAppShell( 7439): 	at android.widget.ListPopupWindow.setSelection(ListPopupWindow.java:673)
E/GeckoAppShell( 7439): 	at android.widget.Spinner$DropdownPopup.show(Spinner.java:969)
E/GeckoAppShell( 7439): 	at android.widget.ListPopupWindow$ResizePopupRunnable.run(ListPopupWindow.java:1260)
E/GeckoAppShell( 7439): 	at android.os.Handler.handleCallback(Handler.java:615)
E/GeckoAppShell( 7439): 	at android.os.Handler.dispatchMessage(Handler.java:92)
E/GeckoAppShell( 7439): 	at android.os.Looper.loop(Looper.java:137)
E/GeckoAppShell( 7439): 	at org.mozilla.gecko.util.GeckoBackgroundThread.run(GeckoBackgroundThread.java:31)
I/Choreographer( 7439): Skipped 39 frames!  The application may be doing too much work on its main thread.
I/WindowState(  328): WIN DEATH: Window{42ed83b8 org.mozilla.fennec/org.mozilla.fennec.App paused=false}
I/ActivityManager(  328): Process org.mozilla.fennec (pid 7439) has died.
W/ActivityManager(  328): Force removing ActivityRecord{431160f8 org.mozilla.fennec/.App}: app died, no saved state
I/WindowState(  328): WIN DEATH: Window{42ef63d0 SurfaceView paused=false}
I/WindowState(  328): WIN DEATH: Window{42ec2960 PopupWindow:42b4cad8 paused=false}
I/WindowState(  328): WIN DEATH: Window{42ecf210 org.mozilla.fennec/org.mozilla.fennec.App paused=false}
D/Zygote  (  124): Process 7439 terminated by signal (11)
Comment 6 Scoobidiver (away) 2012-09-13 08:28:08 PDT
(In reply to Aaron Train [:aaronmt] from comment #4)
> bp-d34aece7-7f52-4130-a20c-bbafe2120913
It's bug 790180, not this bug.
Comment 7 Mark Finkle (:mfinkle) (use needinfo?) 2012-09-13 10:33:39 PDT
Chris - Is this related to the other "dialog not handled on the UI thread" bug you and sriram just fixed?
Comment 8 Chris Peterson [:cpeterson] 2012-09-13 10:50:34 PDT
(In reply to Mark Finkle (:mfinkle) from comment #7)
> Chris - Is this related to the other "dialog not handled on the UI thread"
> bug you and sriram just fixed?

This crash is likely related or a dupe. Our fix for that other bug was purely speculative. We did not have STR.
Comment 9 Chris Peterson [:cpeterson] 2012-09-13 12:43:57 PDT
Created attachment 660935 [details] [diff] [review]
create-dialog-on-UI-thread.patch

My original chemspill patch posted the AlertDialog's builder.create() to the UI thread, but left the AlertDialog.Builder initialization on the GeckoBackgroundThread. My patch now moves the entire PromptService.show() method to the UI thread instead of GeckoBackgroundThread.

If PromptService.show() is running on the UI thread, is layerView.post(new Runnable(...)) still necessary? I assume layerView.post() is just posting to the UI thread (which we are already running on).

We should uplift this fix to Beta 16 or even Firefox 15, if we have the chance.
Comment 10 Sriram Ramasubramanian [:sriram] 2012-09-17 16:10:48 PDT
Comment on attachment 660935 [details] [diff] [review]
create-dialog-on-UI-thread.patch

This looks good to me. But I don't understand what significant change it would bring in to fix the crash.
Comment 11 Chris Peterson [:cpeterson] 2012-09-17 17:20:08 PDT
(In reply to Sriram Ramasubramanian [:sriram] from comment #10)
> Comment on attachment 660935 [details] [diff] [review]
> create-dialog-on-UI-thread.patch
> 
> This looks good to me. But I don't understand what significant change it
> would bring in to fix the crash.

My guess is that creating the views on GeckoBackgroundThread causes them to "attach" themselves to the background thread instead of the UI thread. I adjusted which PromptService code is posted to the UI thread and I identified that this code block will, if executed on the GeckoBackgroundThread, cause PromptService to crash when it is scrolled:

    View content = mInputs[i].getView();
    linearLayout.addView(content);

I think creating or modifying Views on any thread other than the UI thread is probably asking for trouble. :)
Comment 12 Chris Peterson [:cpeterson] 2012-09-17 17:28:08 PDT
https://hg.mozilla.org/integration/mozilla-inbound/rev/9980650215af
Comment 13 Chris Peterson [:cpeterson] 2012-09-17 17:45:42 PDT
Comment on attachment 660935 [details] [diff] [review]
create-dialog-on-UI-thread.patch

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 
User impact if declined: This bug will continue to be the #2 or #3 topcrash on Beta 16 and Firefox 15.
Testing completed (on m-c, etc.): Tested locally with STR
Risk to taking this patch (and alternatives if risky): Low risk. This fix is a more conservative version of my first attempt to fix this crash before I had STR (bug 769894). This code path is already crashing today, so it can't be made much worse. <:)
String or UUID changes made by this patch: None
Comment 14 Scoobidiver (away) 2012-09-18 05:54:30 PDT
https://hg.mozilla.org/mozilla-central/rev/9980650215af
Comment 15 Alex Keybl [:akeybl] 2012-09-18 11:48:13 PDT
Comment on attachment 660935 [details] [diff] [review]
create-dialog-on-UI-thread.patch

[Triage Comment]
Low risk fix for a top crash. As Chris pointed out, worst case scenario is that we crash when we already crash. Please land asap.
Comment 16 Chris Peterson [:cpeterson] 2012-09-18 12:31:54 PDT
https://hg.mozilla.org/releases/mozilla-aurora/rev/541adb1639bb
Comment 17 Chris Peterson [:cpeterson] 2012-09-18 12:32:25 PDT
https://hg.mozilla.org/releases/mozilla-beta/rev/4442bb93e91a
Comment 18 Cristian Nicolae (:xti) 2012-11-21 06:28:19 PST
I cannot reproduce this issue on any branch using the STR from comment #4. Closing bug as verified fixed on:

Firefox 20.0a1 (2012-11-21)
Device: Galaxy S2
OS: Android 4.0.3

Note You need to log in before you can comment on or make changes to this bug.