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

Instance Method Summary collapse

Methods included from Instrumentation

#instrument

Instance Attribute Details

#last_stderrObject (readonly)

Returns the value of attribute last_stderr.



14
15
16
# File 'lib/ADB.rb', line 14

def last_stderr
  @last_stderr
end

#last_stdoutObject (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.

Parameters:

  • hostname (defaults to: 'localhost')

    defaults to ‘localhost’

  • port (defaults to: '5555')

    defaults to ‘5555’

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30

Raises:



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}#{stdout_stderr_message}" unless stdout_contains "connected to #{hostname}"
end

#devices(timeout = 30) ⇒ Object

list all connected devices

seconds.

Parameters:

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • hostname (defaults to: 'localhost')

    defaults to ‘localhost’

  • port (defaults to: '5555')

    defaults to ‘5555’

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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

Parameters:

  • date (defaults to: Date.new)

    to format. Defaults current date



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.

Parameters:

  • the

    source protocol:port

  • the

    destination protocol:port

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • the

    path and filename to the apk you wish to install

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30

Raises:



96
97
98
99
# File 'lib/ADB.rb', line 96

def install(installable, options=nil, target={}, timeout=30)
  execute_adb_with_exactly(timeout, *"#{which_one(target)} wait-for-device install #{options}".split, installable)
  raise ADBError, "Could not install #{installable}#{stdout_stderr_message}" unless stdout_contains "Success"
end

#list_packages(switches = '', target = {}, timeout = 30) ⇒ Object

execute shell list packages command

:emulator, and :serial. seconds.

Parameters:

  • optional (String)

    switches, see adb shell list documentation

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • the

    fully quanified source (device) file name

  • the

    fully quanified destination (local) file name

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • the

    fully quanified source (local) file name

  • the

    fully quanified destination (device) file name

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • command (String)

    to be passed to the shell command

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30

Raises:



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#{stdout_stderr_message}" unless stdout_contains "daemon started successfully"
end

#stop_server(timeout = 30) ⇒ Object

stop the server process

seconds.

Parameters:

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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.

Parameters:

  • the

    package name of the apk ou wish to uninstall

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30

Raises:



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}#{stdout_stderr_message}" unless stdout_contains "Success"
end

#wait_for_device(target = {}, timeout = 30) ⇒ Object

wait for a device to complete startup

:emulator, and :serial. seconds.

Parameters:

  • which (Hash)

    device to wait for. Valid keys are :device,

  • timeout (defaults to: 30)

    value for the command to complete. Defaults to 30



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