module Adb

Constants

Device

Public Instance Methods

android_5_or_greater?() click to toggle source
# File lib/adb_driver/adb.rb, line 21
def android_5_or_greater?
  android_version[0].to_i >= 5
end
android_6?() click to toggle source
# File lib/adb_driver/adb.rb, line 29
def android_6?
  android_version.start_with?('6')
end
android_6_or_greater?() click to toggle source
# File lib/adb_driver/adb.rb, line 25
def android_6_or_greater?
  android_version[0].to_i >= 6
end
android_7?() click to toggle source
# File lib/adb_driver/adb.rb, line 33
def android_7?
  android_version.start_with?('7')
end
app_version(package_name) click to toggle source
# File lib/adb_driver/adb.rb, line 11
def app_version(package_name)
  output = execute_command("shell dumpsys package #{package_name}")
  version_line = output.lines.grep(/versionName/).first.strip
  version_line[/=(.*)/, 1]
end
asus?() click to toggle source
# File lib/adb_driver/adb.rb, line 55
def asus?
  brand == 'asus'
end
brand() click to toggle source
# File lib/adb_driver/adb.rb, line 67
def brand
  execute_command('shell getprop ro.product.brand').strip
end
connected_device_udid() click to toggle source
# File lib/adb_driver/adb.rb, line 90
def connected_device_udid
  case
  when devices.none?                            then fail('No devices detected')
  when devices.one?                             then devices.first.udid
  when devices.count > 1 && emulators.none?     then fail('Several devices detected. Set ANDROID_SERIAL to pick one')
  when devices.count > 1 && emulators.one?      then emulators.first.udid
  when devices.count > 1 && emulators.count > 1 then fail('Several emulators detected. Close all but one')
  end
end
density() click to toggle source
# File lib/adb_driver/adb.rb, line 63
def density
  @density ||= execute_command('shell getprop ro.sf.lcd_density').to_i
end
emulator?() click to toggle source
# File lib/adb_driver/adb.rb, line 43
def emulator?
  !real_device?
end
execute_command(command, timeout_in_seconds = 10) click to toggle source
# File lib/adb_driver/adb.rb, line 7
def execute_command(command, timeout_in_seconds = 10)
  timeout(timeout_in_seconds) { `adb #{command}` }
end
htc?() click to toggle source
# File lib/adb_driver/adb.rb, line 51
def htc?
  brand == 'htc'
end
lenovo?() click to toggle source
# File lib/adb_driver/adb.rb, line 59
def lenovo?
  brand == 'Lenovo'
end
model() click to toggle source
# File lib/adb_driver/adb.rb, line 71
def model
  execute_command('shell getprop ro.product.model').strip
end
package_exists?(package_name) click to toggle source
# File lib/adb_driver/adb.rb, line 17
def package_exists?(package_name)
  execute_command('shell pm list packages').lines.grep(/#{package_name}\s*$/).one?
end
portrait?() click to toggle source
# File lib/adb_driver/adb.rb, line 85
def portrait?
  @orientation_enum ||= `adb shell dumpsys input`.lines.find { |l| l =~ /SurfaceOrientation/ }.strip[-1].to_i
  @orientation_enum.even?
end
real_device?() click to toggle source
# File lib/adb_driver/adb.rb, line 37
def real_device?
  output = execute_command('devices -l')
  output = output.lines.grep(/#{ENV['ANDROID_SERIAL']}/).first
  output.include?('usb')
end
remove_package(name) click to toggle source
# File lib/adb_driver/adb.rb, line 75
def remove_package(name)
  return unless package_exists?(name)
  `adb uninstall #{name}`
  fail "#{name} package wasn't removed" if package_exists?(name)
end
restart_adb() click to toggle source
# File lib/adb_driver/adb.rb, line 81
def restart_adb
  `adb kill-server; adb start-server`
end
samsung?() click to toggle source
# File lib/adb_driver/adb.rb, line 47
def samsung?
  brand == 'samsung'
end

Private Instance Methods

android_version() click to toggle source
# File lib/adb_driver/adb.rb, line 102
def android_version
  execute_command('shell getprop ro.build.version.release').lines.last.strip
end
devices() click to toggle source
# File lib/adb_driver/adb.rb, line 106
def devices
  @device_list ||= begin
                     execute_command('devices -l').lines.grep(/model/).inject([]) do |dl, device_string|
                       dl << Device.new(device_string[/^\S+/])
                     end
                   end
end
emulators() click to toggle source
# File lib/adb_driver/adb.rb, line 114
def emulators
  @emulators_list ||= begin
                     execute_command('devices -l').lines.grep(/model/).grep_v(/usb/).inject([]) do |dl, device_string|
                       dl << Device.new(device_string[/^\S+/])
                     end
                   end
end