Closed Bug 2065181 Opened 1 month ago Closed 26 days ago

Extend SyncManager APIs with the ability to connect and disconnect sync

Categories

(Firefox for Android :: Accounts and Sync, task)

All
Android
task
Points:
8

Tracking

()

RESOLVED FIXED

People

(Reporter: segun, Assigned: segun)

References

Details

(Whiteboard: [fxdroid] [android-activation-trust])

Attachments

(5 files)

As part of the technical decoupling of accounts & sync (bug 2060556), we need to extend the SyncManager APIs & FxaAccountManager APIs to connect and disconnect sync.

Android currently has an internal SyncManager API that is used via the FxaAccountManager - and we need to extend both of them to support connect(), disconnect()andisConnected` behaviours and states. The goal is to have something that looks like this:

// android components
internal abstract class SyncManager {
  val isConnected: StateFlow<Boolean>
  abstract fun connect()
  abstract fun disconnect()
}

The details of what each step should do might undergo revisions as we go on, but here are some known expected behaviours. At the time of implementation, we may decide to file separate bugs for those behaviours/actions if the code changes are too large.

Disconnect

To disconnect sync, we need to do the following:

  1. Call rust's syncmanager disconnect() API so that they can drop the internal states they maintain
  2. Clear the local "is sync enabled" state introduced in Bug 2065174
  3. Clear the "sync state" blob that we persist. See WorkManagerSyncWorker.doSync() to see where we set it
  4. Cancel scheduled work manager sync jobs

Connect

Connecting to sync is quite involved, so please double check with the folks in #fxa-mobile-integrations to check that it does what it should. A pseudocode of this flow is as follows:

function connect:
    if user is not authenticated:
        state = "disconnected"
        return
        
    if user does not have sync scope:
        start auth flow for sync
        return
        
    state = "connected"

    initiate first sync.
    schedule periodic sync.
Points: 3 → 8
Depends on: 2067189
Assignee: nobody → sfamisa
Status: NEW → ASSIGNED

This commit makes two changes

  1. Adds reset() - to handle updating the state to what would indicate that sync values have been reset. This includes resetting the last synced time, "is sync connected", and "persisted sync state"
    Reset is different from clear because clear removes the entries from the storage. Reset merely sets them back to a default state.

  2. SyncStateStorage.syncEnabled becomes SyncStateStorage.syncConnected, is now nullable, and has an observable variant. null indicates that the value has never been set.
    It also adds a storeSyncConnected for setting that value.

"Connected" rather than "enabled" because this preference records whether sync was connected on this device through an explicit action, which kinda sounds better with the planned connect() / disconnect() APIs on SyncManager.

The resolution of SyncStateStorage.syncConnected to true/false falls outside the storage layer, and this only tells us if any value has been set or not.

The syncConnectionState infers the state of "sync" based on a combination of sync decoupling is enabled, whether the user has explicitly turned off sync, or whether the account is not authenticated, connected or missing the sync scope.

This API connects & configures sync when a connected and authorised (with sync scope) account exists.
It also offers the possibility of starting sync immediately.

Attachment #9640469 - Attachment description: WIP: Bug 2065181 - Add `syncConnectionState` API to the SyncManager → Bug 2065181 - Add `syncConnectionState` API to the SyncManager
Attachment #9640470 - Attachment description: WIP: Bug 2065181 - Add `connect()` API to the SyncManager → Bug 2065181 - Add `connect()` API to the SyncManager
Attachment #9640472 - Attachment description: WIP: Bug 2065181 - Add `disconnect()` API to the SyncManager → Bug 2065181 - Add `disconnect()` API to the SyncManager
Keywords: leave-open
Blocks: 2071009
Pushed by sfamisa@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/51e7705f84e9 https://hg.mozilla.org/integration/autoland/rev/fa7b7f42eb7c Extend SyncStateStorage to add reset() API and make syncConnected nullable and observable r=android-reviewers,cbect https://github.com/mozilla-firefox/firefox/commit/9fa59f961398 https://hg.mozilla.org/integration/autoland/rev/35813eb14cc8 Add a flag for enabling sync decoupling to SyncConfig r=android-reviewers,cbect
Attachment #9640469 - Attachment description: Bug 2065181 - Add `syncConnectionState` API to the SyncManager → WIP: Bug 2065181 - Add `syncConnectionState` API to the SyncManager
Attachment #9640469 - Attachment description: WIP: Bug 2065181 - Add `syncConnectionState` API to the SyncManager → Bug 2065181 - Add `syncConnectionState` API to the SyncManager
Status: ASSIGNED → RESOLVED
Closed: 26 days ago
Keywords: leave-open
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: