Class: Fastlane::Helper::EmulatorCommander

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/mango/helper/emulator_commander.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_name) ⇒ EmulatorCommander

Returns a new instance of EmulatorCommander.



8
9
10
11
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 8

def initialize(container_name)
  @container_name = container_name
  @docker_commander = DockerCommander.new(container_name)
end

Instance Attribute Details

#container_nameObject

Returns the value of attribute container_name.



6
7
8
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 6

def container_name
  @container_name
end

Instance Method Details

#check_connectionObject

Restarts adb on the separate port and checks if created emulator is connected



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 36

def check_connection
  UI.success('Checking if emulator is connected to ADB.')

  if emulator_is_healthy?
    UI.success('Emulator connected successfully')
    true
  else
    UI.important("Something went wrong. Newly created device couldn't connect to the adb")
    false
  end
end

#disable_animationsObject

Disables animation for faster and stable testing



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 14

def disable_animations
  @docker_commander.exec(command: 'adb shell settings put global window_animation_scale 0.0')
  @docker_commander.exec(command: 'adb shell settings put global transition_animation_scale 0.0')
  @docker_commander.exec(command: 'adb shell settings put global animator_duration_scale 0.0')
rescue FastlaneCore::Interface::FastlaneShellError => e
  # Under weird circumstances it can happen that adb is running but shell on the emu is not completely up
  # it recovers after some time, so wait and retry
  retry_counter = retry_counter.to_i + 1
  if retry_counter <= 5
    sleep 10 * retry_counter
    retry
  else
    raise e
  end
end

#emulator_is_healthy?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 48

def emulator_is_healthy?
  list_devices = @docker_commander.exec(command: 'adb devices')
  list_devices.include? "\tdevice"
rescue FastlaneCore::Interface::FastlaneShellError => e
  # Under weird circumstances it can happen that adb is running but adb is not completely up
  # it recovers after some time, so wait and retry
  retry_counter = retry_counter.to_i + 1
  if retry_counter <= 5
    sleep 10 * retry_counter
    retry
  else
    raise e
  end
end

#increase_logcat_storageObject

Increases logcat storage



31
32
33
# File 'lib/fastlane/plugin/mango/helper/emulator_commander.rb', line 31

def increase_logcat_storage
  @docker_commander.exec(command: 'adb logcat -G 16m')
end