Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App shows a black screen when restarting the app during metadata download #769

Closed
vanessa-chang opened this issue Aug 28, 2023 · 15 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@vanessa-chang
Copy link

The app would show a black screen for around 1.5 minutes when restarting the app during metadata download.

Step to reproduce:

  1. Install the app and download a content pack
  2. Go to Library page and check how many channels are avalible
  3. Go to Discovery page and wait for 5 minutes
  4. Quit the app and re-launch the app
  5. Check if the app restarts correctly

Actual result:
The app displays a black screen for around 1.5 minutes.

Log:
blackscreen_log.txt

*Note: This issue cannot be reproduced in the Windows version.

@jofilizola
Copy link

I have this here, but it hasn't finished downloading the pack when I got the black screen and it's not going away.

@dbnicholson
Copy link
Member

I was able to reproduce this on ChromeOS but not pure Android. I'm pretty confident this is particular to the Android app and it looks like it's a lifecycle issue. On Android when you dismiss the app by swiping it away, Android kills it. On ChromeOS, it appears that it tries to destroy the app and waits a while for it to happen. This is a problem right now because Kolibri doesn't actually stop the downloads running in the background.

So, when you reopen the app, it will sit at the empty webview because the activity hasn't actually stopped. If you actually wait for a while, it will eventually start. What happens is that ChromeOS finally steps in and kills the process and then starts the activity again.

This should be much better in Kolibri 0.16.0-beta4 since learningequality/kolibri@6562962 will actually stop the downloads and the activity will be destroyed quickly. That just got released, so I'm going to test it out.

@dbnicholson dbnicholson self-assigned this Aug 28, 2023
@dbnicholson
Copy link
Member

I tried out 0.16.0-beta4 and it does indeed shut down much faster. However, the scheme in place to restart canceled jobs fails due to learningequality/kolibri#11169. We never hit that before because Kolibri wasn't actually canceling the jobs. Well, they're going to try to release beta5 in a day or two, so I'm going to try to hustle in a fix for that upstream.

@dbnicholson
Copy link
Member

With 0.16.0-beta4 and learningequality/kolibri#11170 it works a lot better, but I can still get the black screen if I cycle it too fast. I don't think there's a lot more we can do without rearchitecting the app with chaquopy to be a proper Android app.

@dbnicholson
Copy link
Member

I think I understand what's going on, and it's a limitation of python-for-android. python-for-android runs a single python interpreter in a process that runs a single script until completion. If it tries to start another python interpreter, bad things happen (this is actually a general python problem). Therefore, when the activity is being destroyed, p4a kills its own process to ensure that it can't come back and try to start another python interpreter from the same process.

However, the activity manager operates differently. If the activity process is still alive, it will try to start another activity instance in that process. When you close the window, you start destroying the activity instance. If you open the app again before the activity has finished destroying, the activity manager will see the existing process and try to start another activity instance in it. Meanwhile, when the existing p4a activity instance gets done destroying itself, it kills its own process.

If ChromeOS has already sent the signal to start the activity again, it thinks everything is fine. In actuality, it sits there with an empty window. If you minimize the window and open it again, ChromeOS activates the task again and this starts things going with a whole new process.

So, I think this is an unsolvable issue with python-for-android. Chaquopy approaches this differently by running one python interpreter for the lifetime of the process. You can then call into the interpreter to run python code instead of a single blocking script.

That said, I think kolibri 0.16.0-beta5 makes it more reliable by actually stopping the tasks correctly. Still, Kolibri doesn't stop quickly, so there's a decent window between the app stopping and actually killing the process. If you try to restart the app within that window, you can probably get the black screen.

dbnicholson added a commit to endlessm/kolibri-installer-android that referenced this issue Sep 8, 2023
This release fixes cancelling of tasks so that stopping the worker
instance actually stops the running tasks instead of waiting until they
complete.

The patch is no longer needed since it was merged upstream.

Helps: endlessm/kolibri-explore-plugin#769
dylanmccall pushed a commit to endlessm/kolibri-installer-android that referenced this issue Sep 12, 2023
This release fixes cancelling of tasks so that stopping the worker
instance actually stops the running tasks instead of waiting until they
complete.

The patch is no longer needed since it was merged upstream.

Helps: endlessm/kolibri-explore-plugin#769
@dbnicholson
Copy link
Member

@vanessa-chang can you test this out and see if it behaves any better? I don't think this can be fully solved, but I think it should be harder to get into that state.

@vanessa-chang
Copy link
Author

vanessa-chang commented Sep 13, 2023

@dbnicholson
The test is blocked with version Manatee 6.46.400 due to #806

I remembered I can still reproduce the issue yesterday in Manatee 6.44-397, but I didn't pay too much attention on that.
I will re-test this issue again once #806 is fixed.

I feel that #740 is less reproduced if I recall it correctly. I will check both issue once the app is working.

@vanessa-chang
Copy link
Author

@dbnicholson I've tested the latest 6.46.401:

The black screen can still be observed, but it happens at the 2nd time of re-starting the app.
(it happens when you restarting the app before IIRC)

@vanessa-chang
Copy link
Author

Tested the latest package, 6.47.402:

The blackscreen can be reproduced, but it will not be recovered after 1.5 minutes unless you refresh the app.

blackscreen_log.txt

@dbnicholson
Copy link
Member

OK, I have 2 questions.

  1. Is this actually a regression from the production version? I haven't looked closely at the commits, but I feel like after going through a couple changes the lifecycle handling is back where it was before.
  2. Just to get an idea of if this is in the right direction, can you try installing the debug APK from https://github.com/dbnicholson/kolibri-chaquopy/actions/runs/6228917817? You'll have to unzip it before installing with adb, but that's pretty much how I'd expect to handle the lifecycle long term.

@vanessa-chang
Copy link
Author

@dbnicholson

i. Not really. Because we have changed the way the metadata is downloaded for #739 after the production is released.
The black screen is introduced with the new process, although the issue seems to behave differently with the current testings.

ii. I have tried the APK, it works pretty well and the black screen cannot be reproduced. (Note: I cannot access the welcome screen, but it will go downloading the inventor pack after I restart the app. )

@vanessa-chang
Copy link
Author

Tested the latest package, Narwhal 7.0-405, It works pretty much like 6.47.402.
The issue seems to happen if I quit the app after 5 mins of the first launch.
It can be workaround by switching to another app, or refresh the app by minimizing it then re-launch it.

@erikos
Copy link
Contributor

erikos commented Sep 27, 2023

Talking to Vanessa, we are fine with living with that issue for now. Is not as severe and often anymore.

@dbnicholson
Copy link
Member

With the conversion to chaquopy landed now in endlessm/kolibri-installer-android#185, I think this is testable again. I ran this on my Chromebook and didn't have any issues with the black screen. I was able to close the app and restart it while there were background downloads happening. I also couldn't get a black screen when minimizing and restoring the window. It will show up as a white screen (the browser's about:blank page) until we have time to make the transition pretty again.

@vanessa-chang could you QA this again with 420 Narwhal 7.8 from internal testing?

@vanessa-chang
Copy link
Author

@dbnicholson thanks. I have tested this with Narwhal 7.8, I cannot reproduce this issue. I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants