Android-ElectricSheep-Automator

 view release on metacpan or  search on metacpan

lib/Android/ElectricSheep/Automator.pm  view on Meta::CPAN

			$y2 = $h - $y1;
		}
		if( ($direction =~ /^u(p)?$/i) ){
			$y2 = int(0.2*$h);
			$y1 = $h - $y2;
		}
		@cmd = ('input', 'touchscreen', 'swipe', $x1, $y1, $x2, $y2, $dt);
	}

	# unfortunately Android::ADB uses IPC::Open2::open2() to run the adb shell command
	# which does not capture STDERR, and so either they use open3 or we capture stderr thusly:

	if( $verbosity > 0 ){ $log->info("${whoami} (via $parent), line ".__LINE__." : sending command to adb: @cmd") }
	my $res = $self->adb->shell(@cmd);
	if( ! defined $res ){ $log->error(join(" ", @cmd)."\n${whoami} (via $parent), line ".__LINE__." : error, above shell command has failed, got undefined result, most likely shell command did not run at all, this should not be happening."); return unde...
	if( $res->[0] != 0 ){ $log->error(join(" ", @cmd)."\n${whoami} (via $parent), line ".__LINE__." : error, above shell command has failed, with:\nSTDOUT:\n".$res->[1]."\n\nSTDERR:\n".$res->[2]."\nEND."); return undef }

	return 0; # success
}

# It finds all installed apps on device and appends with

lib/Android/ElectricSheep/Automator/ADB.pm  view on Meta::CPAN

	my @dev_args = $self->{device_serial} ? ('-s', $self->{device_serial}) : ();
	my $pid = open2 $out, $in, $self->{path}, @{$self->{args}}, @args;
	my $result = read_file $out;
	close $out;
	close $in;
	waitpid $pid, 0 or croak "$!";
	$result;
}

# returns an arrayref of
#   [statuscode, stdout, stderr]
# on success statuscode is 0 and stdout/stderr may or may not have something
# on failure statuscode is 1 and stdout/stderr may or may not have something
# the '$result' returned by original run2() is now the stdout,
# the 2nd item in the returned arrayref
sub run {
	my ($self, @args) = @_;
	my ($out, $in, $err);
	my @dev_args = $self->{device_serial} ? ('-s', $self->{device_serial}) : ();
	my @cmd = ($self->{path}, @{$self->{args}}, @args);
	if( $self->{verbosity} > 0 ){ print STDOUT __PACKAGE__.'::run()'." : executing command : ".join(' ', @cmd)."\n" }
	# check if undef is passed in @cmd, IPC does not like that
	for (@cmd){

lib/Android/ElectricSheep/Automator/ADB.pm  view on Meta::CPAN

	# e.g. adb shell input keycombination 1 2
	# will exit with $?=0 and print some error message!
	# Searching for 'Error:' in STDERR is ok?
	# TODO: this needs to be dealt with here.
	if( (! $res) || $@ || ($err=~/\bError\: /) ){
		carp "STDERR:\n${err}\nOTHER INFO: $@\n\n"
			.(($@=~/IPC::Run: .*timed out/)
			  ?"\nWARNING: it looks like a timeout has occured.\n\n"
			  :""
			 )
			.__PACKAGE__.'::run()'." : error, failed to execute command (see above for stderr): ".join(' ', @cmd)
		; # end carp
		return [1, $out, $err];
	}
	return [0, $out, $err];
}

sub start_server { shift->run('start-server') }
sub kill_server  { shift->run('kill-server') }

sub connect      { shift->run('connect', @_) }

lib/Android/ElectricSheep/Automator/ADB.pm  view on Meta::CPAN

  $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] }

=head1 DESCRIPTION

lib/Android/ElectricSheep/Automator/ADB.pm  view on Meta::CPAN

will return an empty array.

=item $adb->B<set_device>(I<$device>)

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

=item $adb->B<run>(I<$command>, [I<@args>])

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

=item $adb->B<start_server>

=item $adb->B<kill_server>

=item $adb->B<connect>(I<$host_and_port>)

=item $adb->B<disconnect>([I<$host_and_port>])

=item $adb->B<wait_for_device>



( run in 0.722 second using v1.01-cache-2.11-cpan-49f99fa48dc )