Skip to content

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented Aug 27, 2025

Purpose

Cancel wrongly pending sync state.

Short description

  • Show sync adapter pending state again - stop always returning false on Android 14+
  • Activate the previously disabled workaround which cancels sync requests as they come in through sync adapter
  • Add a migration which cancels (possibly wrongly pending) syncs of all accounts and all authorities

Note: The added migration first creates dummy syncs for all authorities, then cancels by each authority specificly and then cancels one more time for all authorities using null as wildcard. I don't know why and please don't ask me why, but it seems like that's all needed to successfully clear the pending flag in the migration.
In SyncFrameworkIntegration.cancelSync it seems to be enough to cancel the specific incoming sync request.

Please double check. Maybe you want to try playing around with this PR too, where I added a FAB to cancel the syncs: #1691

You can also use list active, pending and periodic syncs with:
adb shell dumpsys content | grep -A 10 "Active Syncs"

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup self-assigned this Aug 27, 2025
@sunkup sunkup added the bug Something isn't working label Aug 27, 2025
@sunkup sunkup linked an issue Aug 27, 2025 that may be closed by this pull request
2 tasks
@sunkup sunkup requested a review from Copilot August 27, 2025 12:52
Copilot

This comment was marked as outdated.

@sunkup sunkup force-pushed the 1660-sync-progress-bars-are-pending-after-update branch from 38b5242 to 83e0e03 Compare August 28, 2025 11:34
@sunkup
Copy link
Member Author

sunkup commented Aug 28, 2025

@rfc2822 I have added the migration, but it seems like no migrations run when I try to test like this:

  1. Checkout commit "Bump version to 4.5.3-rc.2"
  2. gradle sync + install on device
  3. Checkout this branch (1660-sync-progress-bars-are-pending-after-update)
  4. gradle sync + install on device

How can I test the migration works?

@rfc2822
Copy link
Member

rfc2822 commented Aug 28, 2025

You have to increase AccountSettings.CURRENT_VERSION to 21.

KDoc for that constant is surely also a good idea. We should also mention it in the AccountSettingsMigration interface KDoc. I suggest to take it into this PR :)

@sunkup
Copy link
Member Author

sunkup commented Aug 28, 2025

ah, yes. Of course ... Thank you! Will do 👍

@sunkup sunkup requested a review from a team August 28, 2025 13:09
@sunkup sunkup marked this pull request as ready for review August 28, 2025 13:09
@rfc2822
Copy link
Member

rfc2822 commented Aug 28, 2025

So this is only needed for address book accounts? Can't there a sync be pending for normal accounts, too?

@sunkup
Copy link
Member Author

sunkup commented Sep 1, 2025

So this is only needed for address book accounts?

Yes. When I test this with calendars instead of contacts, the pending flag will go a away as soon as the internet connection is active and the pending/scheduled sync runs. I don't need to edit an event for it to be cleared.

Can't there a sync be pending for normal accounts, too?

No, well ... maybe, but I don't know how to reproduce that scenario then. Is it different for you? If you want to we could of course add the calendar account(s) too, just to be sure ...

@rfc2822
Copy link
Member

rfc2822 commented Sep 1, 2025

Yes. When I test this with calendars instead of contacts, the pending flag will go a away as soon as the internet connection is active and the pending/scheduled sync runs. I don't need to edit an event for it to be cleared.

I just wonder because AndroidSyncFrameworkTest tests CalendarContract.AUTHORITY and the sync flag stays pending for calendar syncs.

@sunkup
Copy link
Member Author

sunkup commented Sep 1, 2025

The forever pending sync flag is definitely a thing for the calendars too, but I can't reproduce it with the app update (no idea why), so I thought there is no need to handle it in the migration.

@rfc2822
Copy link
Member

rfc2822 commented Sep 1, 2025

The forever pending sync flag is definitely a thing for the calendars too, but I can't reproduce it with the app update (no idea why), so I thought there is no need to handle it in the migration.

I just wonder whether we can rely on that or assume that there may be pending calendar syncs that don't go away for some users. These users would surely be irratated. Maybe also cancel pending calendar syncs to be on the secure side?

@sunkup
Copy link
Member Author

sunkup commented Sep 1, 2025

Added 👍

@sunkup sunkup requested a review from a team September 1, 2025 13:33
@rfc2822 rfc2822 changed the title Add migration to cancel wrongly pending address book syncs Add migration to cancel wrongly pending syncs Sep 1, 2025
@sunkup sunkup requested a review from a team September 2, 2025 08:59
@rfc2822
Copy link
Member

rfc2822 commented Sep 2, 2025

@ArnyminerZ For reviewing please also use these steps; but instead of installing the 4.5.3 APK you can just checkout the v4.5.3-ose tag and install it from Android Studio. Then update

  • one time to main-ose (problem should be there),
  • and then everything again to the branch of this PR (problem should be gone).

I wonder whether the problem can also be reproduced for events/tasks. But anyway if the update works and doesn't leave progress bars behind, I hope we're good.

In worst case we have to disable the "sync pending" progress bar again for Android >= 14, but I don't hope so.

@rfc2822 rfc2822 force-pushed the 1660-sync-progress-bars-are-pending-after-update branch from 7290310 to 96d0fa3 Compare September 3, 2025 08:39
@rfc2822
Copy link
Member

rfc2822 commented Sep 3, 2025

(I have rebased)

Progress bar still there, tested like this:

  • checkout / install v4.5.3, set up DAVx5 (with jtxBoard)
  • sync collections
  • activate flight mode
  • created a subtask of an existing tasks and an event
  • no pending sync bar because 4.5.3
  • checkout / install main-ose
  • pending sync bar appears as expected
  • checkout / install this PR
  • pending sync bar still there :/

And then just to be sure:

  • leave flight mode to make sure that it's not an actual sync that will disappear
  • also force sync
  • pending sync bar still there

Seems to come from address books because when I open the account screen, the pending sync bar is in the CardDAV tab, but not in the CalDAV tab. Logs:

V  Sync pending(Account {name=test, type=bitfire.at.davdroid}, com.android.calendar) = false
V  Sync pending(Account {name=test, type=bitfire.at.davdroid}, at.techbee.jtx.provider) = false
…
V  Sync pending(Account {name=Contacts (test) #1, type=at.bitfire.davdroid.address_book}, com.android.contacts) = true

@sunkup
Copy link
Member Author

sunkup commented Sep 3, 2025

That is really strange, because it has been working fine for me. I will try your steps to reproduce

@rfc2822
Copy link
Member

rfc2822 commented Sep 3, 2025

PS After rebooting the emulator the pending sync is gone…

@sunkup
Copy link
Member Author

sunkup commented Sep 3, 2025

You're right. Happens to me too. It also happens for calendars when adding the authorities to the call like this: ContentResolver.cancelSync(account, authority).

What does seem to work is canceling the sync via request (with Bundle()), so maybe we should just go back to that:
syncFrameworkIntegration.cancelSync(account, authority, Bundle()). Leaves, however, the question whether it works in all cases with the empty bundle. That is:

If for instance the last sync had a manual flag, would this correctly cancel the pending sync that would be left?

So we will need to test canceling with the different sync flags ContentResolver.SYNC_EXTRAS_MANUAL, ContentResolver.SYNC_EXTRAS_UPLOAD and maybe others.

On Android 16 in the logs I saw upload can be true and false too (not just on Android 7):

12:51:53.320  I  Sync request via sync framework for Account {name=Contacts (test) #6, type=at.bitfire.davdroid.address_book} com.android.contacts (upload=true)

@sunkup sunkup marked this pull request as draft September 4, 2025 11:49
@sunkup sunkup changed the title Add migration to cancel wrongly pending syncs Support sync adapter pending sync indication on Android 14+ Sep 4, 2025
@sunkup sunkup force-pushed the 1660-sync-progress-bars-are-pending-after-update branch from 0287a2b to 155618b Compare September 11, 2025 09:45
@sunkup sunkup force-pushed the 1660-sync-progress-bars-are-pending-after-update branch from a9ce43f to 6ae10e9 Compare September 18, 2025 12:57
@sunkup sunkup marked this pull request as ready for review September 18, 2025 13:05
@sunkup sunkup requested a review from a team September 18, 2025 13:06
@sunkup
Copy link
Member Author

sunkup commented Sep 18, 2025

@bitfireAT/app-dev I have updated the issue description too. Please check and let me know if you find an easier way to cancel the forever pending sync flag or know of an easier way to test it.

misclicked Did not mean to close.

@sunkup sunkup closed this Sep 18, 2025
@sunkup sunkup reopened this Sep 18, 2025
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

Successfully merging this pull request may close these issues.

Sync progress bars are pending after update
2 participants