Module: ADB
- Includes:
- Instrumentation
- Defined in:
- lib/ADB.rb,
lib/ADB/errors.rb,
lib/ADB/version.rb,
lib/ADB/instrumentation.rb
Overview
which is a part of the android toolset.
Defined Under Namespace
Modules: Instrumentation Classes: ADBError, Error
Constant Summary collapse
- VERSION =
"0.5.6"
Instance Attribute Summary collapse
-
#last_stderr ⇒ Object
readonly
Returns the value of attribute last_stderr.
-
#last_stdout ⇒ Object
readonly
Returns the value of attribute last_stdout.
Instance Method Summary collapse
-
#connect(hostname = 'localhost', port = '5555', timeout = 30) ⇒ Object
connect to a running device via TCP/IP.
-
#devices(timeout = 30) ⇒ Object
list all connected devices.
-
#disconnect(hostname = 'localhost', port = '5555', timeout = 30) ⇒ Object
disconnect from a device.
-
#format_date_for_adb(date = Date.new) ⇒ Object
format a date for adb shell date command.
-
#forward(source, destination, target = {}, timeout = 30) ⇒ Object
setup port forwarding.
-
#install(installable, options = nil, target = {}, timeout = 30) ⇒ Object
install an apk file to a device.
-
#list_packages(switches = '', target = {}, timeout = 30) ⇒ Object
execute shell list packages command.
-
#pull(source, destination, target = {}, timeout = 30) ⇒ Object
pull a file.
-
#push(source, destination, target = {}, timeout = 30) ⇒ Object
push a file.
-
#remount(target = {}, timeout = 30) ⇒ Object
remount /system as read-write.
-
#root(target = {}, timeout = 30) ⇒ Object
restarts the adb daemon with root permissions.
-
#shell(command, target = {}, timeout = 30) ⇒ Object
execute shell command.
-
#start_server(timeout = 30) ⇒ Object
start the server process.
-
#stop_server(timeout = 30) ⇒ Object
stop the server process.
-
#uninstall(package, target = {}, timeout = 30) ⇒ Object
uninstall an apk file to a device.
-
#wait_for_device(target = {}, timeout = 30) ⇒ Object
wait for a device to complete startup.
Methods included from Instrumentation
Instance Attribute Details
#last_stderr ⇒ Object (readonly)
Returns the value of attribute last_stderr.
14 15 16 |
# File 'lib/ADB.rb', line 14 def last_stderr @last_stderr end |
#last_stdout ⇒ Object (readonly)
Returns the value of attribute last_stdout.
14 15 16 |
# File 'lib/ADB.rb', line 14 def last_stdout @last_stdout end |
Instance Method Details
#connect(hostname = 'localhost', port = '5555', timeout = 30) ⇒ Object
connect to a running device via TCP/IP
seconds.
45 46 47 48 |
# File 'lib/ADB.rb', line 45 def connect(hostname='localhost', port='5555', timeout=30) execute_adb_with(timeout, "connect #{hostname}:#{port}") raise ADBError, "Could not connect to device at #{hostname}:#{port}#{}" unless stdout_contains "connected to #{hostname}" end |
#devices(timeout = 30) ⇒ Object
list all connected devices
seconds.
68 69 70 71 72 73 |
# File 'lib/ADB.rb', line 68 def devices(timeout=30) execute_adb_with(timeout, 'devices') device_list = last_stdout.split("\n") device_list.shift device_list.collect { |device| device.split("\t").first } end |
#disconnect(hostname = 'localhost', port = '5555', timeout = 30) ⇒ Object
disconnect from a device
seconds.
58 59 60 |
# File 'lib/ADB.rb', line 58 def disconnect(hostname='localhost', port='5555', timeout=30) execute_adb_with(timeout, "disconnect #{hostname}:#{port}") end |
#format_date_for_adb(date = Date.new) ⇒ Object
format a date for adb shell date command
146 147 148 |
# File 'lib/ADB.rb', line 146 def format_date_for_adb(date=Date.new) date.strftime("%C%y%m%d.%H%M00") end |
#forward(source, destination, target = {}, timeout = 30) ⇒ Object
setup port forwarding
:emulator, and :serial. seconds.
160 161 162 |
# File 'lib/ADB.rb', line 160 def forward(source, destination, target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} forward #{source} #{destination}") end |
#install(installable, options = nil, target = {}, timeout = 30) ⇒ Object
install an apk file to a device
:emulator, and :serial. seconds.
96 97 98 99 |
# File 'lib/ADB.rb', line 96 def install(installable, =nil, target={}, timeout=30) execute_adb_with_exactly(timeout, *"#{which_one(target)} wait-for-device install #{}".split, installable) raise ADBError, "Could not install #{installable}#{}" unless stdout_contains "Success" end |
#list_packages(switches = '', target = {}, timeout = 30) ⇒ Object
execute shell list packages command
:emulator, and :serial. seconds.
137 138 139 |
# File 'lib/ADB.rb', line 137 def list_packages(switches='', target={}, timeout=30) shell("pm list packages #{switches}", target, timeout) end |
#pull(source, destination, target = {}, timeout = 30) ⇒ Object
pull a file
:emulator, and :serial. seconds.
189 190 191 192 |
# File 'lib/ADB.rb', line 189 def pull(source, destination, target={}, timeout=30) args = "#{which_one(target)} pull".split execute_adb_with_exactly(timeout, *args, source, destination) end |
#push(source, destination, target = {}, timeout = 30) ⇒ Object
push a file
:emulator, and :serial. seconds.
174 175 176 177 |
# File 'lib/ADB.rb', line 174 def push(source, destination, target={}, timeout=30) args = "#{which_one(target)} push".split execute_adb_with_exactly(timeout, *args, source, destination) end |
#remount(target = {}, timeout = 30) ⇒ Object
remount /system as read-write
:emulator, and :serial. seconds.
202 203 204 |
# File 'lib/ADB.rb', line 202 def remount(target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} remount") end |
#root(target = {}, timeout = 30) ⇒ Object
restarts the adb daemon with root permissions
:emulator, and :serial. seconds.
214 215 216 |
# File 'lib/ADB.rb', line 214 def root(target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} root") end |
#shell(command, target = {}, timeout = 30) ⇒ Object
execute shell command
:emulator, and :serial. seconds.
124 125 126 |
# File 'lib/ADB.rb', line 124 def shell(command, target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} wait-for-device shell #{command}") end |
#start_server(timeout = 30) ⇒ Object
start the server process
seconds.
22 23 24 25 |
# File 'lib/ADB.rb', line 22 def start_server(timeout=30) execute_adb_with(timeout, 'start-server') raise ADBError, "Server didn't start#{}" unless stdout_contains "daemon started successfully" end |
#stop_server(timeout = 30) ⇒ Object
stop the server process
seconds.
33 34 35 |
# File 'lib/ADB.rb', line 33 def stop_server(timeout=30) execute_adb_with(timeout, 'kill-server') end |
#uninstall(package, target = {}, timeout = 30) ⇒ Object
uninstall an apk file to a device
:emulator, and :serial. seconds.
110 111 112 113 |
# File 'lib/ADB.rb', line 110 def uninstall(package, target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} uninstall #{package}") raise ADBError, "Could not uninstall #{package}#{}" unless stdout_contains "Success" end |
#wait_for_device(target = {}, timeout = 30) ⇒ Object
wait for a device to complete startup
:emulator, and :serial. seconds.
83 84 85 |
# File 'lib/ADB.rb', line 83 def wait_for_device(target={}, timeout=30) execute_adb_with(timeout, "#{which_one(target)} wait-for-device") end |