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

Use WorkManager for Upload/Download #5492

Merged
merged 9 commits into from
Feb 22, 2024
Merged

Conversation

westnordost
Copy link
Member

@westnordost westnordost commented Feb 20, 2024

StreetComplete update got rejected from the Google Play Store because all apps targeting API 34 must declare for what they use the foreground service and policy-wise, it is quite limited what Google will allow as foreground services.

StreetComplete uses a foreground service (that notification that tells you "Data syncing...") for the upload and download, so I declared it being used for "data sync". Now, however, as far as I understand the rejection notice, for the "data sync" use case some very strict rules apply. One of these rules is that the action that triggers the data sync must either be user-initiated or clearly perceptible to the user. With the latter, they mean something like e.g. music playing, i.e. a notification is not enough.


Expand to read full rejection notice

Issue found: Permission use is either not declared or incorrectly declared

We found that one or more of the use cases utilizing the foreground service permission in your app has either been incorrectly submitted or is missing from your Console declaration.

  • Your in-app experience or video does not match the Data Sync - Local Processing: Import Export in your declaration.

We found that one or more of the declared use cases is not compliant with how foreground service permission is allowed to be used. Specifically, the user is not made aware of functionality requiring permission when active.

  • Use of FGS is not perceptible to the user when performing Data Sync - Network Other , Data Sync - Local Processing: Import Export functionality.

Issue details

We found an issue in the following area(s):

  • Version code 5602
  • Version code 5700

To bring your app into compliance, follow these steps:

  • Please submit an updated declaration, being sure to include all uses of the foreground service permission in your app.
  • Ensure that all use cases declared match the app experience.
  • Review the list of foreground service type permissions to ensure that the appropriate type is being used for each declared use case.
  • Remove the use of FOREGROUND_SERVICE in cases where it is not required.

To make APK/App bundle-level updates, follow these steps:

  • Go to App bundle explorer and search for the noncompliant version codes. Click on the details page to navigate to the track(s) with the policy issue (Closed / Open testing / Production). Click Manage track > Create new release.
  • If the release with the violating app bundles/APKs are in a draft state, discard the release.
  • Otherwise, add the policy-compliant version of app bundles/APKs.
  • Make sure that the noncompliant version is under the "Not included" section of this release.
  • Enter a release name and click Save. Once saved, click Review release, and then proceed to roll out the release to 100% and completely deactivate the noncompliant APK.
  • If the noncompliant versions are released to multiple tracks, repeat step 1 on each track.
  • You can check the App bundle explorer page again, and the noncompliant version code should show as “Inactive” and “0 releases” in the details page.

If all declared use cases are impacted, the FOREGROUND_SERVICE permission must also be removed.

About the Permissions for Foreground Services

The Foreground Service permission ensures the appropriate use of user-facing foreground services. For apps targeting Android 14 and above, you must specify a valid foreground service type for each foreground service used in your app, and declare the foreground service permission that is appropriate for that type. For example, if your app’s use case requires map geolocation, you must declare the FOREGROUND_SERVICE_LOCATION permission in your app’s manifest.
With the exceptions of systemExempted and shortService foreground service types, apps are only allowed to declare a foreground service permission if the use:

  • Provides a feature that is beneficial to the user and relevant to the core functionality of the app.
  • Is initiated by the user or is user perceptible (for example, audio from playing a song, cast media to another device, accurate and clear user notification, user request to upload a photo to the cloud).
  • Can be terminated or stopped by the user.
  • Can’t be interrupted or deferred by the system without causing a negative user experience or causing the user anticipated feature to not work as intended (for example, a phone call needs to start immediately and can’t be deferred by the system).
  • Runs only for as long as necessary to complete the task.

The use of foreground service is further explained on this Play Console Help Center page.


So, if the download (and upload) was always triggered by the user, I understand that using a foreground service would continue to be okay. But since the app downloads map data around the user's location automatically, this use case is not okay.

The PR now migrates away from foreground services and instead uses the WorkManager for upload and download. (Luckily) it looks like that WorkManager work is started immediately when the app is in foreground.
On Android versions below 12, the WorkManager actually uses a foreground service to execute the work, so on these versions, you'll continue to see a "syncing data" notification. Bonus: You'll actually cancel it now. Not on Android 13 and above, though, because there is no notification anymore ... Google 🙄

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Code looks good but I haven't run it. I just have two small comment suggestions.

westnordost and others added 4 commits February 21, 2024 22:05
- rename isPriority to isUserInitiated
- add isUserInitiated for upload through upload button
- rethrow exceptions so that worker fails
- call onSuccess for download if no error occurs
@westnordost westnordost merged commit 80ed0ed into master Feb 22, 2024
@FloEdelmann FloEdelmann deleted the workmanager-for-sync branch February 22, 2024 11:34
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.

2 participants