Class: EmuCtl::Ctl

Inherits:
Object
  • Object
show all
Defined in:
lib/emu_ctl/ctl.rb

Constant Summary collapse

@@EMU_TIMEOUT =
180

Class Method Summary collapse

Class Method Details

.create(target, skin) ⇒ Object



48
49
50
51
52
53
# 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) ⇒ Object



55
56
57
# File 'lib/emu_ctl/ctl.rb', line 55

def self.delete(emu)
  system "android delete avd -n #{emu.name}"
end

.kill_pids(pids) ⇒ Object



67
68
69
70
# 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

.listObject



33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
44
45
46
# 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_pidsObject



59
60
61
62
63
64
65
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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