smtddr's notes

[Things I find interesting]

When suddenly Google Account disappears from your Android device.

f:id:smtddr:20180409145538p:plain

Recently, my Google account suddenly disappeared from my Android phone. Google related apps wouldn't let me sign-in, or would crash on start-up. In my device's Settings->AddAccount, the account-type "Google" was just plain gone. In the past this somehow got corrected by me removing/UninstallUpdates for all Google apps, clearing cache, rebooting phone. But the 2nd time this happened, that solution didn't work. Online, I saw suggestions for factory-reset. No way did I want to do that; not to mention that I also saw that for some people that didn't even work. So I set out to understand exactly what state my phone was in and how to get it back to working.

NOTE: I have no idea how you'd fix this without rooting the device.

  • Enable DevMode, then using DevMode enable adb-debugging so you can use "adb shell" to get into your device.

  • Do this command: logcat *:* | grep -E AccountManagerService|AccountChooser

Then try to log into your Gmail, or Inbox, or Youtube, or start Google Hangouts.. anything that requires a Google Account. See what kind of logcat messages you get. I saw things like this:

D/AccountChooser( 5488): ChooseTypeAndAccountActivity.onActivityResult: unable to find added account, pretending the request was canceled
D/AccountManagerService(  853): bind attempt failed for Session: expectLaunch false, connected false, stats (0/0/0), lifetime 0.0, addAccount, accountType com.google, requiredFeatures null
  • Do this command: dumpsys account

You'll see various account types & Service types, e.g. twitter if you have twitter installed and logged in. What you will be probably missing is anything mentioning "com.google". Now go try this same command on a known properly working Android device and you'll see some "com.google" accounts & services. That stuff is what your messed-up device is missing, you need to get them back somehow.

  • Do this command: am start android/.accounts.ChooseTypeAndAccountActivity , A list will appear on the Android device's screen. Select "Add Account" at the bottom of this list.

You'll see a list of a bunch of account-types, this should be every account type your device is aware of. If this is a phone you might even see account type "Phone" and or type "SIM". What you probably do NOT see, is a Google Account type.

  • Where do account-types come from?

Well, on my phone I have the following from dumpsys account:

 Accounts: 4
    Account {name=PHONE, type=com.android.localphone}
    Account {name=********@gmail.com, type=com.google}
    Account {name=SMTDDR, type=com.twitter.android.auth.login}
    Account {name=SIM1, type=com.android.sim}

We definitely can take an educated guess that the account type "com.twitter.android.auth.login" is only here because we installed the Twitter App and logged in. What needs to be installed to get com.google? Turns out, that you get this by installing Google Play Services(com.google.android.gms) and/or GoogleAccountManager(com.google.android.gsf.login).

  • Do this command: pm list packages|grep com.google

To see what packages you have installed, where part of the name is "com.google". You probably already have the 2 packages mentioned above installed.

  • Now, you probably need root

How the account-type "com.google" was removed from the device, I have no idea. But to get it back, you need to somehow re-register the apps that created it. Only with root can you remove, then re-install these 2 apps. You can find the APKs on apkmirror.com .

Warning, should you trust apkmirror.com? That's your decision

These apps you're about to reinstall will probably have full access to your Google Account and probably can see your password during the sign-in process. You don't want to end up with compromised APKs. Chances are though, that these apps are actually still on your phone.

/data/app/com.google.android.gsf.login-1.apk
/data/app/com.google.android.gms-2.apk

If not there, check also:

/system/app
/system/priv-app

Copy the apks to a safe place, probably do a cp command to copy them to /sdcard then from there upload them to your GoogleDrive/Dropbox/etc, just get copies of those apks to some place outside of your android device.

Now, as root you're going to remove those apks. If they're on /system you'll probably need to remount /system as a readwrite rather than its default state of read-only, mount -o remount,rw /system. Also, find the folder for the app cache at /data/data, completely delete these folders. They will be regenerated later. Now reboot the phone, stuff will still be broken. Use the command pm install to re-install the apks you copied to /sdcard. Reboot the phone again. Now, if you adb shell into the phone and type dumpsys account, you should see something mentioning "com.google". Again run the command am start android/.accounts.ChooseTypeAndAccountActivity , on the android-device select "Add Account" at the bottom of the list to see all account types available. Hopefully you now see a Google Account type. So now if you go to your Device's Settings->AddAccount, you should be able to select a Google type again.

Chances are, when you try to add an account it either won't work for some reason or you'll suddenly see your previous account just reappear, but still stuff isn't working right. At this point, you nee to delete this file:

  • /data/system/users/0/accounts.db

And Go to Settings->Apps, clear the caches of GooglePlayServices, GoogleAccountManager, GooglePartnerSetup and probably ever other Google-made app... then reboot.

Now add your Google account, chances are everything will work correctly now! One catch though, if you notice a problem with Notifications not working on your device, re-install GooglePartnerSetup, clear cache of all Google related products (and whatever app has broken notifications), reboot.

That's about it! -^_^-