NAME

Android::ElectricSheep::Automator - Do Androids Dream of Electric Sheep? Smartphone control from your desktop

VERSION

Version 0.02

WARNING

Current distribution is extremely alpha. API may change.

SYNOPSIS

The present package fascilitates the control of a USB-debugging-enabled Android smartphone from a desktop computer.

use Android::ElectricSheep::Automator;

my $mother = Android::ElectricSheep::Automator->new({
  'configfile' => $configfile,
  'verbosity' => 1,
  # we already have a device connected and ready to control
  'device-is-connected' => 1,
});

# find the devices connected to desktop and set one.
my @devices = $mother->adb->devices;
$mother->connect_device({'serial' => $devices->[0]->serial})
    or die;
# no device needs to be specified if just one:
$mother->connect_device() if scalar(@devices)==0;

# Go Home
$mother->home_screen() or die;

# swipe up/down/left/right
$mother->swipe({'direction'=>up}) or die;
# dt is the time to swipe in millis,
# the shorter the faster the swipe
$mother->swipe({'direction'=>left, 'dt'=>100}) or die;

# tap
$mother->tap({'position'=>[100,200]});

# uses swipe() to move in screens (horizontally):
$mother->next_screen() or die;
$mother->previous_screen() or die;

# bottom navigation:
# the "triangle" back button
$mother->navigation_menu_back_button() or die;
# the "circle" home button
$mother->navigation_menu_home_button() or die;
# the "square" overview button
$mother->navigation_menu_overview_button() or die;

# open/close apps
$mother->open_app({'package'=>qr/calendar$/i}) or die;
$mother->close_app({'package'=>qr/calendar$/i}) or die;

# push pull files
$mother->adb->pull($deviceFile, $localFile);
$mother->adb->push($localFile, $deviceFileOrDir);

# guess what!
my $xmlstr = $mother->dump_current_screen_ui();

CONSTRUCTOR

new($params)

Creates a new Android::ElectricSheep::Automator object. $params is a hash reference used to pass initialization options which may or should include the following:

METHODS

SCRIPTS

For convenience, a few simple scripts are provided:

PREREQUISITES

Android Studio

This is not a prerequisite but it is highly recommended to install (from https://developer.android.com/studio) on your desktop computer because it contains all the executables you will need, saved in a well documented file system hierarchy, which can then be accessed from the command line.

Additionally, Android Studio offers possibly the easiest way to create Android Virtual Devices (AVD) which emulate an Android phone of various specifications. I mention this because one can install apps on an AVD and control them from your desktop as long as you are able to receive sms verification codes from a real phone. This is great for experimenting without pluggin in your real smartphone on your desktop.

The bottom line is that by installing Android Studio, you have all the executables you need for running things from the command line and, additionally, you have the easiest way for creating Android Virtual Devices, which emulate Android devices: phones, tablets, automotive displays. Once you have this set up, you will not need to open Android Studio ever again unless you want to update your kit. All the functionality will be accessible from the command line.

ADB

Android Debug Bridge (ADB) is the program which communicates with your smartphone or an Android Virtual Device from your desktop (Linux, osx and the unnamed 0$).

If you do not want to install Android Studio, the adb executable is included in the package called "Android SDK Platform Tools" available from the Android official site, here: https://developer.android.com/tools/releases/platform-tools#downloads

You will need the adb executable to be on your path or specify its fullpath in the configuration file supplied to Android::ElectricSheep::Automator's constructor.

USB Debugging

The targeted smartphone must have "USB Debugging" enabled via the "Developer mode". This is not to be confused with 'rooted' or 'jailbroken' modes, none of these are required for experimenting with the current modul.

In order to enable "USB Debugging", you need to set the smartphone to enter "Developer" mode by following this procedure:

Go to Settings->System->About Phone Tap on Build Number 7 times [sic!]. Enter your phone pin and you are in developer mode.

You can exit Developer Mode by going to Settings->System->Developer and turn it off. It is highly advised to turn off Developer Mode for everyday use of your phone. Do not connect your smartphone to public WIFI networks with Developer Mode ON.

Do not leave home with Developer Mode ON.

Once you have enabled "USB Debugging", you have two options for making your device visible to your desktop and, consequently, to ADB and to this module:

Android Emulators

It is possible to do most things your smartphone does with an Android Virtual Device. You can install apps on the the virtual device which you can register by supplying your real smartphone number.

List all virtual devices currently available in your desktop computer, with emulator -list-avds which outputs something like:

Pixel_2_API_27_x86_
Pixel_2_API_30_x86_

Start a virtual device with emulator -avd Pixel_2_API_30_x86_

And hey, you have an android phone running on your desktop in its own space, able to access the network but not the telephone network.

It is possible to create a virtual device from the command line. But perhaps it is easier if you download Android Studio from: https://developer.android.com/studio and follow the setup there using the GUI. It will download all the required files and will create some Android Virtual Devices (the "emulators") for you. It will also be easy to update your stack in the future. Once you have done the above, you no longer need to run Android Studio except perhaps for checking for updates and all the required executables by this package will be available from the command line.

Otherwise, download "Android SDK Platform Tools" available from the Android official site, here: https://developer.android.com/tools/releases/platform-tools#downloads (this download is mentioned in ADB if you already fetched it).

Fetch the required packages with this command:

sdkmanager --sdk_root=/usr/local/android-sdk "platform-tools" "platforms;android-30" "cmdline-tools;latest" "emulator"

Note that sdkmanager --list will list the latest android versions etc.

Now you should have access to avdmanager executable (it should be located here: /usr/local/android-sdk/cmdline-tools/latest/bin/avdmanager) which you can use to create an emulator.

List all available android virtual devices you can create: avdmanager list target

List all available devices you can emulate: avdmanager list device

List all available devices you have created already: avdmanager list avd

Create virtual device: avdmanager create avd -d "Nexus 6" -n myavd -k "system-images;android-29;google_apis;x86"

See https://stackoverflow.com/a/77599934

USING YOUR REAL SMARTPHONE

AUTHOR

Andreas Hadjiprocopis, <bliako at cpan.org>

BUGS

Please report any bugs or feature requests to bug-Android-ElectricSheep-Automator at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Android-ElectricSheep-Automator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Android::ElectricSheep::Automator

You can also look for information at:

SEE ALSO

HUGS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2025 by Andreas Hadjiprocopis.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)