mozilla-services/android-sync — comment on commit c0c8705c38f29bef2df7ae9c0c3184314be2ff6f
File: src/main/java/org/mozilla/gecko/sync/stage/SyncClientsEngineStage.java line 192
By rnewman:

Don't do this. Extend SyncConfiguration, around line 220, and set the appropriate value from GlobalSession's constructor — it'll have access to the appropriate value, which the SyncAdapter can extract.

Yes, this means that you'll need a channel back from the SyncConfiguration to the GlobalSession, and a callback from there to the SyncAdapter, to persist any change you wish to make to the Account object. Something like:

// We just generated a new GUID. Let's persist it.
GlobalSession.setAccountClientsData(guid, name);

which would do something like:

this.config.setAccountClientsData(guid, name);
this.clientsDelegate.persistAccountClientsData(guid, name;

The purpose of this is twofold.

Firstly, it makes testing much easier — we can't easily mock AccountManager.

Secondly, it puts control of the Account in the hands of code that already handles it. This means we'll have a much easier time when it comes to supporting multiple Accounts.

Another acceptable variant of this is to have the SyncConfiguration lazily compute and persist these fields. That handily avoids any potential for concurrency issues; you'd just ask for the values and it would generate new ones if it needed to… and take responsibility for saving them first.