20

I have a large set of devices that I want to add google accounts to. The google accounts are already setup so I just want to add these existing accounts to the devices through a command line script.

black hole
  • 246
  • 2
  • 6
  • 1
    maybe install via adb a dumb apk that auto starts and launches the code from the last response here http://stackoverflow.com/questions/3575303/programatically-starting-the-add-account-activity-in-android-2-2 – eduyayo Oct 27 '16 at 10:45
  • Do you have root access to these devices? – Alonme Dec 14 '19 at 12:33
  • @Alonme, suppose yes, what would you suggest? – a.t. Jan 06 '23 at 09:23
  • 1
    @a.t. - its been a while since i wrote that, so i am not sure if i have had a specific idea - or wanted to know if researching the "root" direction is interesting here. what i can think about now is to somehow use "/data/system/users/0/accounts.db" see https://stackoverflow.com/questions/3632237/where-does-android-account-manager-store-account-specific-preferences and https://forum.xda-developers.com/t/backup-and-restore-all-accounts-on-android.4222261/ – Alonme Jan 07 '23 at 10:58

1 Answers1

5

There are two possible ways (Non-Root):

#1 Develop an app that implements the Account Manager and facilates the login process.

#2 Use a series of ADB commands to pass the input strings and stimulate the touch events.

ADB Command Example:

Start the native add account settings screen

ADB shell am start -a android.settings.ADD_ACCOUNT_SETTINGS \
                   -n com.android.settings/.accounts.AddAccountSettings

Select the absolute coordinates of the screen where the Google account is located. Each device has different screen sizes, so you have to figure out the exact position of your device. If you have multiple apps with login accounts they will also appear here. E.g., Microsoft Office, Reddit, and WhatsApp.

adb shell input tap X Y

Tips: You can enable the Show taps and Pointer location from Developer Option. This will give you the precious location of the touch input.

Set the desired input text

adb shell input text "account@gmail.com"

If you want select a keyboard event, pass the event code from the KeyEvent constants

adb shell input keyevent 66

Here, 66 is the event code of "KEYCODE_ENTER"

Repeat the input/touch process until you successfully login to the system.

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • 1
    Thank you for your effort on the solution, this method you presented could be improved on robustness. For example, if a phone call comes in, or a request for updates, the script may lead to unintended side-effects. Similarly, an update of the app UI could lead to unintended side-effects. – a.t. Jan 07 '23 at 08:15
  • @a.t. Yes, this needs some improvements. Nevertheless, it's one of the only ways to achieve the goal without root permission. – Prokash Sarkar Jan 13 '23 at 08:48