Switch from background service to some system-wide Android feature #725
Labels
No labels
android: closed alpha
android: open beta
app-parity
area: devops
area: discovery
area: docs
area: livestream
area: proposal
consider soon
creator
Epic
good first issue
hacktoberfest
help wanted
icebox
Invalid
level: 1
level: 2
level: 3
level: 4
needs: exploration
needs: grooming
needs: priority
needs: repro
needs: tech design
on hold
priority: blocker
priority: high
priority: low
priority: medium
product review
resilience
Tom's Wishlist
type: bug
type: discussion
type: improvement
type: new feature
type: refactor
type: task
type: testing
unplanned
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: LBRYCommunity/lbry-android#725
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The Issue
Currently LBRY on Android creates a foreground service reportedly to provide a better user experience. That allows the app to load data even when the app is not on the foreground. This is a complete bad practice.
Foreground services must only be used when the user can notice if it is running. Typical examples are music or video players. Background services can be used for features which user cannot notice directly.
The feature which LBRY tries to provide can (and should) be implemented by a background service. Android is already offering a few options for this:
Expected behaviour
Don't use a foreground service
Actual behaviour
App is using a foreground service, even user is not going to notice it is running. Notification shows it is running but that's not the way foregrounbd services should be used on Android.
Anything Else
I propose a roadmap where first current implementation is moved into a background service which uses WorkManager to get the system ask it to do the background sync. As currently LBRY is already using accounts, the next step would be to implement a Sync Adapter, which would just leverage the previous phase but moving the preference settings into the Android native Account Manager.
EDIT: This would only affect the app while not on the foreground. The LbrynetService would still be syncing as it is already doing while LBRY is being shown on the screen. App would switch to the WorkManager when user is not seeing it on the screen.
I could be working on this in the future, if it is seen as something worth to be done. I would fork this repo and do the corresponding PRs.
Internal Use
Acceptance Criteria
Definition of Done
@kekkyojin Thanks so much for opening this issue and the feedback. We'll need to see if this is possible for our use case while running the LBRY-sdk in the background.
Can we show you some appreciation for the detailed issue?
LbrynetService
is just startinglbry.extras.daemon.Daemon
from the SDK. This action in a vacuum is not compatible with SyncAdapter/WorkManager -- it's ongoing by nature so there's no way to do it without a foreground Service.The question is whether or not this is even necessary. What is the app even doing that requires the Daemon when the app is in the background (true background -- not playing a video in PIP mode)? The Android app doesn't host videos, so why does the Daemon need to continue to run (serious question -- I don't know the app codebase or the protocol well)? Why not just stop the Service if you're not going into PIP mode? Without any real benchmarks, I'd say the main concern here is battery drain. I would imagine that maintaining a Python event loop through Kivy at all times is a great way to burn up your battery. It would not be abnormal for Apple's (human) App Store verification to block something like that.
@akinwale could you comment on what the Daemon is needed for when the app enters the background without a video playing in PIP? Can the LbrynetService simply be stopped in this case? Thanks for any info!
@aimkey That daemon could be rewritten into a SyncAdapter. The new SyncAdapter would download data every 15 minutes. When LBRY Android is in the foreground, the app could be requesting the SyncAdapter to download new data with a blocktime period so it is on sync.
The SDK is a Python process which performs a number of tasks while in the background:
Due to the amount of time that it takes for the sdk to get to a ready state in order to start handling requests, we keep it running in the background in order to improve the user experience when they close and reopen the app.
We stuck with Python (and Kivy) because it would be a time-consuming and expensive endeavour to reimplement the required bits of https://github.com/lbryio/lbry-sdk in native code.
It is possible to delegate the tasks listed above to lbry.tv but that leads to centralisation. It's something we're considering for a better experience, but we want to provide users with an option to choose.
you've made it into our chat 😁
sounds like a bit of time before we'd be able to make the adjustments SDK side