File Coverage

blib/lib/Android/ADB.pm
Criterion Covered Total %
statement 20 65 30.7
branch 0 8 0.0
condition 0 7 0.0
subroutine 7 29 24.1
pod 22 22 100.0
total 49 131 37.4


line stmt bran cond sub pod time code
1             package Android::ADB;
2              
3 1     1   45850 use 5.014000;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         17  
5 1     1   4 use warnings;
  1         4  
  1         41  
6              
7             our $VERSION = '0.001';
8              
9 1     1   222 use Android::ADB::Device;
  1         3  
  1         8  
10 1     1   43 use Carp;
  1         3  
  1         61  
11 1     1   311 use File::Slurp;
  1         10120  
  1         53  
12 1     1   243 use IPC::Open2;
  1         3097  
  1         560  
13              
14             sub new {
15 0     0 1   my ($class, %args) = @_;
16 0   0       $args{path} //= $ENV{ADB};
17 0   0       $args{path} //= 'adb';
18 0   0       $args{args} //= [];
19 0           bless \%args, $class
20             }
21              
22             sub run {
23 0     0 1   my ($self, @args) = @_;
24 0           my ($out, $in);
25 0 0         my @dev_args = $self->{device_serial} ? ('-s', $self->{device_serial}) : ();
26 0           my $pid = open2 $out, $in, $self->{path}, @{$self->{args}}, @args;
  0            
27 0           my $result = read_file $out;
28 0           close $out;
29 0           close $in;
30 0 0         waitpid $pid, 0 or croak "$!";
31 0           $result;
32             }
33              
34 0     0 1   sub start_server { shift->run('start-server') }
35 0     0 1   sub kill_server { shift->run('kill-server') }
36              
37 0     0 1   sub connect { shift->run('connect', @_) }
38 0     0 1   sub disconnect { shift->run('disconnect', @_) }
39              
40             sub devices {
41 0     0 1   my @devices = split '\n', shift->run('devices', '-l');
42 0           my @result;
43 0           for (@devices) {
44 0 0         next if /^List of devices/;
45 0 0         next unless / /;
46 0           push @result, Android::ADB::Device->new(split)
47             }
48             @result
49 0           }
50              
51             sub set_device {
52 0     0 1   my ($self, $device) = @_;
53 0           $self->{device_serial} = $device->serial;
54             }
55              
56 0     0 1   sub wait_for_device { shift->run('wait-for-device') }
57 0     0 1   sub get_state { shift->run('get-state') }
58 0     0 1   sub get_serialno { shift->run('get-serialno') }
59 0     0 1   sub get_devpath { shift->run('get-devpath') }
60 0     0 1   sub remount { shift->run('remount') }
61 0     0 1   sub reboot { shift->run('reboot', @_) }
62 0     0 1   sub reboot_bootloader { shift->run('reboot-bootloader') }
63 0     0 1   sub root { shift->run('root') }
64 0     0 1   sub usb { shift->run('usb') }
65 0     0 1   sub tcpip { shift->run('tcpip', @_) }
66              
67             sub push {
68 0     0 1   my ($self, $local, $remote) = @_;
69 0           $self->run(push => $local, $remote)
70             }
71              
72             sub pull {
73 0     0 1   my ($self, $remote, $local) = @_;
74 0           $self->run(push => $remote, $local)
75             }
76              
77             sub pull_archive {
78 0     0 1   my ($self, $remote, $local) = @_;
79 0           $self->run(push => '-a', $remote, $local)
80             }
81              
82 0     0 1   sub shell { shift->run(shell => @_) }
83              
84             1;
85             __END__