Crash in CFRPopupFullScreenLayout.show @ [CFRPopupFullscreenLayout.kt]
Seeing this overnight (09/08) in very recent CFR changes on Firebase Test Lab @gabrielluong @mcarare @Mugurell
https://console.firebase.google.com/u/0/project/moz-fenix/testlab/histories/bh.66b7091e15d53d45/matrices/8268278885395658076/executions/bs.ef9cfb62a48b7d64/issues
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
FATAL EXCEPTION: main
Process: org.mozilla.fenix.debug, PID: 12447
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1068)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109)
at org.mozilla.fenix.compose.cfr.CFRPopupFullScreenLayout.show(CFRPopupFullscreenLayout.kt:121)
at org.mozilla.fenix.compose.cfr.CFRPopup.show$lambda-1(CFRPopup.kt:76)
at org.mozilla.fenix.compose.cfr.CFRPopup.$r8$lambda$TXBcbC1ZJIfV_BS4FJxo1uw7w5M(Unknown Source:0)
at org.mozilla.fenix.compose.cfr.CFRPopup$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
┆Issue is synchronized with this Jira Task
First introduced on main in https://github.com/mozilla-mobile/fenix/commit/812f073e3925fe2ce024a1f1861052bd97beca20
Might be related to https://github.com/mozilla-mobile/fenix/issues/26825.
Recent occurrences:
- https://console.firebase.google.com/u/0/project/moz-fenix/testlab/histories/bh.66b7091e15d53d45/matrices/7583996848406591471/details?stepId=bs.edfd17357db6a46d&testCaseId=1
- https://console.firebase.google.com/project/moz-fenix/testlab/histories/bh.66b7091e15d53d45/matrices/6894419708819635171
Reproducible locally running instrumented org.mozilla.fenix.ui.HomeScreenTest#verifyCustomizeHomepageTest on Pixel 2 API 30 AVD
If this reproduces locally then it should be fixable.
The issue seems to happen because of a weird race of the test finishing while the homescreen hasn't fully settled. When the test finishes it re-enables the "jump back in cfr", the homescreen is still updating and there is enough time for starting the process of showing the CFR but then interrupt it as the activity running under test finishes.
I'll let some logs tell the story:
17:46:55.117 HomeScreenTest: verifyCustomizeHomepageButton started running
17:48:06.044 HomeScreenTest: verifyCustomizeHomepageButton(true) was successful
17:48:06.044 HomeScreenTest: verifyCustomizeHomepageTest test ended
17:48:06.048 HomeScreenTest: tearDown: resetting all flags
17:48:06.221 SessionControlView: onLayoutCompleted: shouldShowJumpBackInCFR?: true
17:48:06.231 HomeCFRPresenter: show CFR for JumpBackIn(view=androidx.compose.ui.platform.ComposeView{e282734 V.E..V... ......I. 0,465-1440,756})
17:48:06.234 CFRPopup: called to show CFR anchored to androidx.compose.ui.platform.ComposeView{e282734 V.E..V... ......I. 0,465-1440,756}
Notes:
- a try-catch in code doesn't help. Presumably because it's a very low level exception.
-
mDevice.waitForIdle()also doesn't work for allowing the homescreen to settle.
Have to do a bit more tests but I'm now thinking that we could merge FeatureSettingsHelper with the activity rules to ensure the flags are only reset in afterActivityFinished when they won't be able to affect any functionality.
That would be helpful to have yeah. Less need to specify feature settings everywhere the better. Longer term, maybe related maybe not, about to handle the activity in test better with ActivityScenarioRule as TestScenarioRule is deprecated (There was some discussion I started here about how to handle after/before activities: https://github.com/android/android-test/issues/1282)
► 9/8 Main - Failed 4x 💥
Firebase link Firebase link Firebase link Firebase link Fireabse link Fireabse link Firebase link
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:1068) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at org.mozilla.fenix.compose.cfr.CFRPopupFullScreenLayout.show(CFRPopupFullscreenLayout.kt:121) at org.mozilla.fenix.compose.cfr.CFRPopup.show$lambda-1(CFRPopup.kt:76) at org.mozilla.fenix.compose.cfr.CFRPopup.$r8$lambda$TXBcbC1ZJIfV_BS4FJxo1uw7w5M(Unknown Source:0) at org.mozilla.fenix.compose.cfr.CFRPopup$$ExternalSyntheticLambda0.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Flaky 1x on 9/12 Main Firebase link
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:1068) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:409) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:109) at org.mozilla.fenix.compose.cfr.CFRPopupFullscreenLayout.show(CFRPopupFullscreenLayout.kt:121) at org.mozilla.fenix.compose.cfr.CFRPopup.show$lambda-1(CFRPopup.kt:76) at org.mozilla.fenix.compose.cfr.CFRPopup.$r8$lambda$TXBcbC1ZJIfV_BS4FJxo1uw7w5M(Unknown Source:0) at org.mozilla.fenix.compose.cfr.CFRPopup$$ExternalSyntheticLambda0.run(Unknown Source:2) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
We'll disable the test while the associated crash is under investigation here. Thanks @Mugurell @AndiAJ
There might be more bit more involved here @Mugurell as there some occurences happening after the above commits
https://console.firebase.google.com/u/1/project/moz-fenix/testlab/histories/bh.66b7091e15d53d45/matrices/4829562917930499997/details?stepId=bs.9650fc7799b14202&testCaseId=4
e.g, copyTextTest which has HomeActivity destroyed right before and then an UncaughtExceptionCrash
09-14 17:56:46.032: D/LifecycleMonitor(9797): Lifecycle status change: org.mozilla.fenix.HomeActivity@e5c81ef in: DESTROYED
and selectAllAndCopyTextTest https://console.firebase.google.com/u/1/project/moz-fenix/testlab/histories/bh.66b7091e15d53d45/matrices/4704917067157183627/details?stepId=bs.86cece146f35e336&testCaseId=2
Thank you for the ping.
Seems like the same general issue which would benefit from the same approach.
In the first patch I wanted to keep the changes small and update only where needed.
Updated there only HomeActivityTestRule and now I see both these failing tests using HomeActivityIntentTestRule.
I'll prepare a similar patch for it also.