AccountManager fails to add account on Sony XZ 7.1.1
Asked Answered
A

2

7

The app I'm currently developing has recently been showing problems when users update to 7.1.1 om Sony mobiles

On a Sony XZ we can see this in the log when trying to addAccountExplicitly:

AccountManagerService( 1503): insertAccountIntoDatabase: Account {[email protected], type=com.myapplication.go}, skipping since the account already exists

The application was installed and the account was added by our app prior to upgrade. It seems as if the account has not been completely removed/readded.

How can we in our app recover from this? Why is this happening? I have read of similar problems in Nougat preview but we can not recover from it with removeAccountExplicitly and then add it again as suggested in link below. The result is the same as above and uninstallation of the app does not clear the account and neither does a phone restart.

AccountManager does not add custom account in Android N preview

Absorbing answered 27/4, 2017 at 17:36 Comment(0)
T
6

We found a possible cause and solution for the problem.

Symptoms

TL;DR It's Sony's fault.

From our user base, it looked like only Sony XZ users who used our app prior to upgrading their device to 7.1.1.

We went as far as buying several Sony XZ devices (and eventually returning them back to the shop), upgrading them from Android 6.0 to 7.1.1 and trying to reproduce the issue. But with no luck.

However, we found another way to achieve the same "symptoms" using the Android emulator. The steps are:

  1. Launch emulator
  2. Login into your app (so that user is added to AccountManager)
  3. Go to the terminal, and do the following

Steps:

adb shell
su
cd /data/system_de/0/
rm accounts_de.db
  1. Restart your emulator
  2. From now on your issue is reproducible.

Moreover, if you'll check /data/system_ce/0/accounts_ce.db you will see that this is a database which still contains your previous user. That is most likely why AccountManager does not allow you to insert same user again.

It looks like that during update to Android 7.1.1, Sony somehow corrupted accounts_de.db which contained the original account.

Solution

Since account with the same name is already in the database (and you can't really remove it from there), we basically can't insert user with the same username again. However, we can insert account with slightly updated username:

if (!accountManager.addAccountExplicitly(account, password, bundle)) {
    // We failed to add the account. Fallback to workaround.
    accountManager.addAccountExplicitly(
        new Account(username + "\n", accountType), // this line solves the issue
        password,
        bundle
    );
}

Since this account is now different from original account (thanks to \n character), it can be inserted into AccountManager database.

Trakas answered 29/6, 2017 at 11:57 Comment(4)
I was able to reproduce this issue. But the "\n" suffix should probably just be used as a fallback if adding the account in the regular manner failed, right? Otherwise users that didn't update their devices to Android 7.1.1 yet will face the same issue again.Coltson
@Coltson yes, we add "\n" only if addAccountExplicitly returns us falseTrakas
@DmitryZaytsev Was the old account still accessible by calling accountManager.getAccountsByType()? Or was it for all for all intents and purposes hidden, but continuing to block adding new accounts?Bertilla
@DmitryZaytsev Thanks! Just incase anybody else is googling this issue, it happened to one of our users after they cleared the google play services data.Bertilla
D
0

The issue is known by Google: https://issuetracker.google.com/issues/142699760

Denni answered 7/11, 2019 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.