NAME

Android::ElectricSheep::Automator::ADB - thin wrapper over the 'adb' command

SYNOPSIS

use Android::ElectricSheep::Automator::ADB;;
my $adb = Android::ElectricSheep::Automator::ADB->new(path => '/opt/android/platform-tools/adb');
my @devices = $adb->devices;
$adb->set_device($devices[0]);
$adb->push('file.txt', '/sdcard/');
sleep 10;
$adb->reboot('recovery');

# Version 0.002
# run() is now using IPC::Run::run() to spawn commands
# a lot of other methods depend on it, e.g. shell(), pull(), push(), devices(), etc.
# they all return what it returns.
# the changes make it easy to find out if there was an error
# in executing external commands and getting the stderr from that.
# $ret is [ $statuscode, $stdout, $stderr]
# for success, $statuscode must be 0 ($stdout, $stderr may be blank in any case)
my $ret = $adb->run("adb devices");
if( $ret->[0] != 0 ){ croak "command has failed: ".$ret->[2] }

my $ret = $adb->shell("getevent");
if( $ret->[0] != 0 ){ croak "command has failed: ".$ret->[2] }

my $ret = $adb->push('file.txt', '/sdcard/');
if( $ret->[0] != 0 ){ croak "command has failed: ".$ret->[2] }

DESCRIPTION

This module is a minimal wrapper over the Android Debug Bridge (adb) command for manipulating Android devices.

Methods die on non-zero exit code and return the text printed by the adb command. The available methods are:

Android::ElectricSheep::Automator::ADB->new([args])

Create a new Android::ElectricSheep::Automator::ADB object. The available arguments are path, the path to the adb executable (defaults to the value of the environment variable ADB or the string adb), verbosity which can be 0 for a silent run or a positive integer denoting increased verbosity (default is 0), and args, an arrayref of arguments passed to every adb command (defaults to []).

$adb->devices

Returns a list of Android::ElectricSheep::Automator::ADB::Device objects representing connected devices. In case of failure running the query, it will return an empty array.

$adb->set_device($device)

Takes an Android::ElectricSheep::Automator::ADB::Device and directs all further commands to that device by passing -s serialno to every command.

$adb->run($command, [@args])

Run an arbitrary ADB command and return its output (among other things). Its return is an ARRAYref as [$statuscode, $stdout, $stderr]. $statuscode is zero on success or 1 on failure. $stdout is the stdout from running the command (it can be empty) and $stderr is the stderr.

$adb->start_server
$adb->kill_server
$adb->connect($host_and_port)
$adb->disconnect([$host_and_port])
$adb->wait_for_device
$adb->get_state
$adb->get_serialno
$adb->get_devpath
$adb->remount
$adb->reboot([$where])
$adb->reboot_bootloader
$adb->root
$adb->usb
$adb->tcpip($port)
$adb->push($local, $remote)
$adb->pull($remote, $local)
$adb->shell(@args)

Analogues of the respective adb commands.

$adb->pull_archive($remote, $local)

Same as adb pull -a $remote $local.

AUTHOR

Marius Gavrilescu, <marius@ieval.ro>

Changes in Version 0.002 by Andreas Hadjiprocopis <bliako@cpan.org>.

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Marius Gavrilescu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.2 or, at your option, any later version of Perl 5 you may have available.