]>
iEval git - android-adb.git/blob - lib/Android/ADB.pm
7 our $VERSION = '0.001';
9 use Android
::ADB
::Device
;
15 my ($class, %args) = @_;
16 $args{path
} //= $ENV{ADB
};
17 $args{path
} //= 'adb';
23 my ($self, @args) = @_;
25 my @dev_args = $self->{device_serial
} ?
('-s', $self->{device_serial
}) : ();
26 my $pid = open2
$out, $in, $self->{path
}, @
{$self->{args
}}, @args;
27 my $result = read_file
$out;
30 waitpid $pid, 0 or croak
"$!";
34 sub start_server
{ shift->run('start-server') }
35 sub kill_server
{ shift->run('kill-server') }
37 sub connect { shift->run('connect', @_) }
38 sub disconnect
{ shift->run('disconnect', @_) }
41 my @devices = split '\n', shift->run('devices', '-l');
44 next if /^List of devices/;
46 push @result, Android
::ADB
::Device
->new(split)
52 my ($self, $device) = @_;
53 $self->{device_serial
} = $device->serial;
56 sub wait_for_device
{ shift->run('wait-for-device') }
57 sub get_state
{ shift->run('get-state') }
58 sub get_serialno
{ shift->run('get-serialno') }
59 sub get_devpath
{ shift->run('get-devpath') }
60 sub remount
{ shift->run('remount') }
61 sub reboot
{ shift->run('reboot', @_) }
62 sub reboot_bootloader
{ shift->run('reboot-bootloader') }
63 sub root
{ shift->run('root') }
64 sub usb
{ shift->run('usb') }
65 sub tcpip
{ shift->run('tcpip', @_) }
68 my ($self, $local, $remote) = @_;
69 $self->run(push => $local, $remote)
73 my ($self, $remote, $local) = @_;
74 $self->run(push => $remote, $local)
78 my ($self, $remote, $local) = @_;
79 $self->run(push => '-a', $remote, $local)
82 sub shell
{ shift->run(shell
=> @_) }
91 Android::ADB - thin wrapper over the 'adb' command
96 my $adb = Android::ADB->new(path => '/opt/android/platform-tools/adb');
97 my @devices = $adb->devices;
98 $adb->set_device($devices[0]);
99 $adb->push('file.txt', '/sdcard/');
101 $adb->reboot('recovery');
105 This module is a minimal wrapper over the Android Debug Bridge
106 (C<adb>) command for manipulating Android devices.
108 Methods die on non-zero exit code and return the text printed by the
109 C<adb> command. The available methods are:
113 =item Android::ADB->B<new>([I<args>])
115 Create a new Android::ADB object. The available arguments are C<path>,
116 the path to the C<adb> executable (defaults to the value of the
117 environment variable C<ADB> or the string C<adb>) and C<args>, an
118 arrayref of arguments passed to every adb command (defaults to []).
120 =item $adb->B<devices>
122 Returns a list of L<Android::ADB::Device> objects representing
125 =item $adb->B<set_device>(I<$device>)
127 Takes an L<Android::ADB::Device> and directs all further commands to
128 that device by passing C<-s serialno> to every command.
130 =item $adb->B<run>(I<$command>, [I<@args>])
132 Run an arbitrary ADB command and return its output.
134 =item $adb->B<start_server>
136 =item $adb->B<kill_server>
138 =item $adb->B<connect>(I<$host_and_port>)
140 =item $adb->B<disconnect>([I<$host_and_port>])
142 =item $adb->B<wait_for_device>
144 =item $adb->B<get_state>
146 =item $adb->B<get_serialno>
148 =item $adb->B<get_devpath>
150 =item $adb->B<remount>
152 =item $adb->B<reboot>([I<$where>])
154 =item $adb->B<reboot_bootloader>
160 =item $adb->B<tcpip>(I<$port>)
162 =item $adb->B<push>(I<$local>, I<$remote>)
164 =item $adb->B<pull>(I<$remote>, I<$local>)
166 =item $adb->B<shell>(I<@args>)
168 Analogues of the respective adb commands.
170 =item $adb->B<pull_archive>(I<$remote>, I<$local>)
172 Same as C<adb pull -a $remote $local>.
178 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
180 =head1 COPYRIGHT AND LICENSE
182 Copyright (C) 2017 by Marius Gavrilescu
184 This library is free software; you can redistribute it and/or modify
185 it under the same terms as Perl itself, either Perl version 5.24.2 or,
186 at your option, any later version of Perl 5 you may have available.
This page took 0.056147 seconds and 4 git commands to generate.