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)

VERIFIED FIXED in Firefox 16

Status

()

Firefox for Android
General
--
critical
VERIFIED FIXED
5 years ago
9 months ago

People

(Reporter: Scoobidiver (away), Assigned: cpeterson)

Tracking

({crash, topcrash})

17 Branch
Firefox 18
ARM
Android
crash, topcrash
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox16+ fixed, firefox17+ verified, firefox18 verified, firefox19 verified, firefox20 verified, fennec+)

Details

(Whiteboard: [native-crash], crash signature)

Attachments

(1 attachment)

(Reporter)

Description

5 years ago
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
about:blank was the only URL listed at this moment in time.
(Assignee)

Comment 2

5 years ago
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??
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.
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

Updated

5 years ago
tracking-fennec: --- → ?
status-firefox18: --- → affected
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)

Updated

5 years ago
Whiteboard: [native-crash] → [native-crash][str in comment #4]

Updated

5 years ago
status-firefox17: --- → affected
(Reporter)

Comment 6

5 years ago
(In reply to Aaron Train [:aaronmt] from comment #4)
> bp-d34aece7-7f52-4130-a20c-bbafe2120913
It's bug 790180, not this bug.
Whiteboard: [native-crash][str in comment #4] → [native-crash]
Chris - Is this related to the other "dialog not handled on the UI thread" bug you and sriram just fixed?
Assignee: nobody → cpeterson
tracking-fennec: ? → +
(Assignee)

Comment 8

5 years ago
(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.
Status: NEW → ASSIGNED
(Assignee)

Comment 9

5 years ago
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.
Attachment #660935 - Flags: review?(sriram)
(Assignee)

Updated

5 years ago
Blocks: 769894
(Assignee)

Updated

5 years ago
Blocks: 790180
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.
Attachment #660935 - Flags: review?(sriram) → review+
(Assignee)

Comment 11

5 years ago
(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. :)
(Assignee)

Comment 12

5 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/9980650215af
status-firefox18: affected → fixed
(Assignee)

Comment 13

5 years ago
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
Attachment #660935 - Flags: approval-mozilla-beta?
Attachment #660935 - Flags: approval-mozilla-aurora?
(Reporter)

Comment 14

5 years ago
https://hg.mozilla.org/mozilla-central/rev/9980650215af
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED

Updated

5 years ago
Keywords: topcrash
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.
Attachment #660935 - Flags: approval-mozilla-beta?
Attachment #660935 - Flags: approval-mozilla-beta+
Attachment #660935 - Flags: approval-mozilla-aurora?
Attachment #660935 - Flags: approval-mozilla-aurora+

Updated

5 years ago
status-firefox16: --- → affected
tracking-firefox16: --- → +
tracking-firefox17: --- → +
(Assignee)

Comment 16

5 years ago
https://hg.mozilla.org/releases/mozilla-aurora/rev/541adb1639bb
status-firefox17: affected → fixed
(Assignee)

Comment 17

5 years ago
https://hg.mozilla.org/releases/mozilla-beta/rev/4442bb93e91a
status-firefox16: affected → fixed
Target Milestone: --- → Firefox 18
(Assignee)

Updated

5 years ago
Depends on: 792702
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
Status: RESOLVED → VERIFIED
status-firefox17: fixed → verified
status-firefox18: fixed → verified
status-firefox19: --- → verified
status-firefox20: --- → verified
You need to log in before you can comment on or make changes to this bug.