1

I've followed the syncadapter example to create an AccountManager and a sync adapter. I wanted to have two different types of authtokens for different purposes (access to different services - the sync adapter uses one of them) under the same account.

Things work but I have found that when I authenticate (via getauthtoken) for one authtoken type, the process of saving it replaces the other authtoken type. I looked in the accounts.db file before and after. Before the call to get a token for authtoken type "B", the authtoken table in accounts.db has an authtoken for auth type "A". After the call, the authtoken table in accounts.db has an authtoken for type "B" but "A" was removed. No matter the order, the accountmanager subsystem never seems to store more than a single authtoken per account for my account type.

Is there something special you need to configure in some xml file somewhere when you have more than one authtoken type?

BJV
  • 1,133
  • 8
  • 15
  • When you save the token, are you sure you save it to a particular type? – CChi Sep 10 '14 at 21:03
  • I first thought that could be it, but I didn't see a way to specify the type. The token is set using the inherited setAccountAuthenticatorResult() method from AccountAuthenticatorActivity. The values in the extras bundles don't specify a type - the type was passed using getAuthToken(). None of the keys in AccountManager (such as KEY_ACCOUNT_NAME) refer to the authtoken type unless I am missing it. But I see that the authtoken type is set correctly in the accounts.db - just that the other authtoken type record was removed. – BJV Sep 10 '14 at 21:28
  • in the extras bundle, you could specify the type, pass in AccountManager.KEY_ACCOUNT_TYPE as key, and the string representation of the account type as the value. – CChi Sep 10 '14 at 21:30
  • Yes, I have my account type specified by the KEY_ACCOUNT_TYPE in the return bundle (as in the sample syncadapter). The account type is different than the authtoken type. – BJV Sep 11 '14 at 02:44
  • You are right. How about when you call setAuthToken, have you provided a auth token type? – CChi Sep 11 '14 at 18:15

1 Answers1

2

I found my problem. If you call AccountManager.setPassword() as a result of a successful authentication/login, it will invalidate all of the authentication tokens for your account. This is an undocumented side effect and in some cases, it kind of makes sense. Software that sets the password to the same value indiscriminately will accidentally invalidate their auth tokens.

BJV
  • 1,133
  • 8
  • 15