5

I've been looking for a solution to this problem for a while (days, not minutes), but it eludes me quite effectively.

Please note that this is NOT a question about starting up the registration procedure. This must happen automatically without any user interaction.

I would like to add a Google account to my custom device (1000's of them). The account will mostly be used to activate Google Play store on the device so that the app can update when newer versions are available.

My existing code (the shortest snippet of those I tried):

AccountManager mgr = AccountManager.get(this);
Account acc = new Account("email@gmail.com", "com.google");
mgr.addAccountExplicitly(acc, "password", new Bundle()));

naturally yields a

java.lang.SecurityException: caller uid 10047 is different than the authenticator's uid

So how would I go about actually achieving this? My device is rooted so that's not an obstacle if it's the only way.

velis
  • 8,747
  • 4
  • 44
  • 64
  • As far as I am aware, you cannot create an account for another Apps authenticator. If you have the firmware and signing key, you may be able to share your user ID with the System user ID. In this case, you may be able to circumvent it. (not writing as answer, as I am not 100% certain about this information) – Knossos Dec 22 '15 at 14:46
  • Well, titanium backup can do it so ot must be doable somehow – velis Dec 22 '15 at 14:51
  • 2
    Since this is your custom device, and you claim to have the "Google Play store" on it, you must have licensed it from Google. You should ask Google what their policy is on pre-establishing Google accounts in these situations, not only to determine how best to do it, but also whether it is authorized in the first place. – CommonsWare Dec 22 '15 at 14:52
  • Device manufacturer rejected our request for this, and i have no information on actual cause of rejection. My guess is thay cause was political, but i cannot be sure. – velis Dec 22 '15 at 14:55
  • Did I run into something that violates Google's TOS? Should I too reject my employer? – velis Dec 22 '15 at 15:47

2 Answers2

0

Warning: this solution doesn't work well. See comments for explanation.

Well, as it turns out, this is not something easily solved. I ended up registering one device, then pulled the users file from it. Location of users file : /data/system/users/0/accounts.db (if there are multiple user profiles on the device, the last directory may differ according to profile in question).

I stored this file into my app's assets (gzipped, make sure the extension is not something.gz because that gets lost during packaging - didn't bother checking out why).

First I check if my user already exists:

AccountManager mgr = AccountManager.get(this);
for (Account acc: mgr.getAccountsByType("com.google")) {
  if (acc.name.equalsIgnoreCase("email@gmail.com"))
    return;
}

If it does, I just skip the step. Otherwise I unpack the users file and overwrite existing one (using su). I then also do a reboot to make sure changes are registered.

velis
  • 8,747
  • 4
  • 44
  • 64
  • Have you find a better way to do that? This assumes you have registered this user account manually once in order the accounts.db is populated with the email and hash of the password. Is there a way to do this skipping the first step, when knowing only the raw password and having no idea for its hashed form. Moreover, I am not sure if the hashed form of the password will be the same across devices, even if the model of such devices is exactly the same. – Thanasis Petsas Oct 26 '16 at 11:50
  • @ThanasisPetsas: Actually, no. As it turns out, Google has some detection in place. Once 50 devices were up using the same account, Play Store stopped functioning. So we were forced to implement our own package update mechanism. – velis Oct 26 '16 at 12:26
  • Ok, good to know! So, the 49 devices were fine with one account? The hashed form of password was the same for all the devices? – Thanasis Petsas Oct 26 '16 at 12:40
  • Well, technically, they all used the SAME database for the account. I don't know at which device Play Store stopped working, but I'm guessing it was a lot before 50 devices. We have thousands, so we didn't even attempt to find a way around this. The settings file itself is just a SQLite database, so technically you can do anythin with it you want, it's just hard to guess all the algorithms. – velis Oct 27 '16 at 06:45
0

It is not possible to add/create a Google account using addAccountExplicitly(). You can only add accounts for your own services. even your device is rooted because it will rejected by Google web server. For more detail check this link

Community
  • 1
  • 1
Rajesh N
  • 6,198
  • 2
  • 47
  • 58