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

Update SyncWorker to show notifications for foreground service #1403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yongsuk44
Copy link
Contributor

What I have done and why

Fix to ensure notifications are visible for foreground synchronization of Topic and News Data.

@@ -67,6 +67,7 @@ internal class SyncWorker @AssistedInject constructor(
traceAsync("Sync", 0) {
analyticsHelper.logSyncStarted()

setForeground(getForegroundInfo())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoroutineWorker#setForeground(ForegroundInfo)

Makes the CoroutineWorker run in the context of a foreground android.app.Service. This is a suspending function unlike the setForegroundAsync API which returns a ListenableFuture.
Calling setForeground will throw an IllegalStateException if the process is subject to foreground service restrictions. Consider using WorkRequest.Builder.setExpedited and getForegroundInfo instead.

Are we sure we want this since we are already using setExpedited?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonMarquis

In versions of Android prior to Android 12, overrid the getForegroundInfo() method would automatically display a notification when a CoroutineWorker was running in the foreground. However, from Android 12 onwards, this notification is no longer shown. This change could make it difficult for users to be aware that a foreground work is actively running. - link

Therefore, setForeground() was add to explicitly notify users of ongoing foreground works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this becomes redundant with the main loading indicator on the home page. Let's see what the maintainers expect 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants