class EmuCtl::Ctl

Public Class Methods

create(target, skin) click to toggle source
# File lib/emu_ctl/ctl.rb, line 48
def self.create(target, skin)
  escaped_id = target.id.gsub(/(\s|:)/,'-')
  cmd = "android create avd -n emu_#{escaped_id}_#{skin} -t \"#{target.id}\" -s #{skin}"
  puts cmd
  system cmd
end
delete(emu) click to toggle source
# File lib/emu_ctl/ctl.rb, line 55
def self.delete(emu)
  system "android delete avd -n #{emu.name}"
end
kill_pids(pids) click to toggle source
# File lib/emu_ctl/ctl.rb, line 67
def self.kill_pids(pids)
  warn 'deprecated: controlling emulators via pids is a bad idea'
  pids.each { |pid| system "kill -9 #{pid}" }
end
list() click to toggle source
# File lib/emu_ctl/ctl.rb, line 33
def self.list
  _, stdout, _ = Open3.popen3('android list avd')
  lines = []
  stdout.each_line { |l| lines.push(l) }
  lines.join.split('---------').map { |desc| Avd.new(desc) }
end
list_targets(filter = true) click to toggle source
# File lib/emu_ctl/ctl.rb, line 40
def self.list_targets(filter = true)
  _, stdout, _ = Open3.popen3('android list targets')
  lines = []
  stdout.each_line { |l| lines.push(l) }
  target_descs = lines.join.split('----------').select { |t| t.include?('id: ') }
  target_descs.map { |desc| Target.new(desc) }.select{|t| t.abi.nil? == false && filter}
end
running_pids() click to toggle source
# File lib/emu_ctl/ctl.rb, line 59
def self.running_pids
  warn 'deprecated: controlling emulators via pids is a bad idea'
  _, stdout, _ = Open3.popen3("pgrep 'emulator'")
  pids = []
  stdout.each_line { |l| pids.push(l.strip) }
  pids
end
start(emu) click to toggle source
# File lib/emu_ctl/ctl.rb, line 5
def self.start(emu)
  raise 'invalid name: nil' if emu.name.nil?
  puts "starting emulator: #{emu}"
  cmd = "emulator -no-boot-anim -avd #{emu.name} -no-snapshot-load -no-snapshot-save -no-audio -no-window -verbose &"
  puts "#{cmd}"
  system "#{cmd}"
  starting_up = true

  start = Time.now

  until ADB.boot_complete?
    sleep 2
    ellapsed = Time.now - start
    print "\r"
    print "Waiting for emulator " + "."*(ellapsed/2).to_i
    STDOUT.flush
    abort "unable to start emulator for #{@@EMU_TIMEOUT/60} minutes" if Time.now - start > @@EMU_TIMEOUT
  end

  puts ''
  puts 'emulator up and running'
  puts ADB.devices

  puts 'unlocking screen'
  ADB.unlock_emulator
  puts 'emulator ready'
end