Class: Flick::Android
- Inherits:
-
Object
- Object
- Flick::Android
- Defined in:
- lib/flick/android.rb
Instance Attribute Summary collapse
-
#dir_name ⇒ Object
Returns the value of attribute dir_name.
-
#flick_dir ⇒ Object
Returns the value of attribute flick_dir.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#name ⇒ Object
Returns the value of attribute name.
-
#outdir ⇒ Object
Returns the value of attribute outdir.
-
#specs ⇒ Object
Returns the value of attribute specs.
-
#udid ⇒ Object
Returns the value of attribute udid.
-
#unique ⇒ Object
Returns the value of attribute unique.
Instance Method Summary collapse
- #check_for_devices ⇒ Object
- #clear_files ⇒ Object
- #create_flick_dirs ⇒ Object
- #devices ⇒ Object
- #devices_connected? ⇒ Boolean
- #get_device_udid(opts_hash) ⇒ Object
- #info ⇒ Object
-
#initialize(options) ⇒ Android
constructor
A new instance of Android.
- #log(name) ⇒ Object
- #os_version ⇒ Object
- #pull_file(file, dir) ⇒ Object
- #pull_files ⇒ Object
- #recordable? ⇒ Boolean
- #screenrecord(name) ⇒ Object
- #screenshot(name) ⇒ Object
- #screenshots_exist? ⇒ Boolean
- #unique_files ⇒ Object
Constructor Details
#initialize(options) ⇒ Android
Returns a new instance of Android.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/flick/android.rb', line 5 def initialize Flick::Checker.system_dependency "adb" self.flick_dir = "#{Dir.home}/.flick" self.dir_name = "sdcard/flick" self.udid = .fetch(:udid, get_device_udid()) self.name = .fetch(:name, self.udid) self.outdir = .fetch(:outdir, Dir.pwd) self.unique = .fetch(:unique, true).to_b self.limit = .fetch(:limit, 180) self.specs = .fetch(:specs, false) create_flick_dirs end |
Instance Attribute Details
#dir_name ⇒ Object
Returns the value of attribute dir_name.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def dir_name @dir_name end |
#flick_dir ⇒ Object
Returns the value of attribute flick_dir.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def flick_dir @flick_dir end |
#limit ⇒ Object
Returns the value of attribute limit.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def limit @limit end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def name @name end |
#outdir ⇒ Object
Returns the value of attribute outdir.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def outdir @outdir end |
#specs ⇒ Object
Returns the value of attribute specs.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def specs @specs end |
#udid ⇒ Object
Returns the value of attribute udid.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def udid @udid end |
#unique ⇒ Object
Returns the value of attribute unique.
3 4 5 |
# File 'lib/flick/android.rb', line 3 def unique @unique end |
Instance Method Details
#check_for_devices ⇒ Object
36 37 38 39 40 41 |
# File 'lib/flick/android.rb', line 36 def check_for_devices unless devices_connected? puts "\nNo Devices Connected or Authorized!!!\nMake sure at least one device (emulator/simulator) is started!\n".red abort end end |
#clear_files ⇒ Object
23 24 25 26 |
# File 'lib/flick/android.rb', line 23 def clear_files %x(adb -s #{udid} shell rm '#{dir_name}/*' >> /dev/null 2>&1) Flick::System.clean_system_dir flick_dir, udid end |
#create_flick_dirs ⇒ Object
18 19 20 21 |
# File 'lib/flick/android.rb', line 18 def create_flick_dirs Flick::System.setup_system_dir flick_dir %x(adb -s #{udid} shell 'mkdir #{dir_name}' >> /dev/null 2>&1) end |
#devices ⇒ Object
28 29 30 |
# File 'lib/flick/android.rb', line 28 def devices (`adb devices`).scan(/\n(.*)\t/).flatten end |
#devices_connected? ⇒ Boolean
32 33 34 |
# File 'lib/flick/android.rb', line 32 def devices_connected? !devices.empty? end |
#get_device_udid(opts_hash) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/flick/android.rb', line 43 def get_device_udid opts_hash devices_connected? return unless opts_hash[:udid].nil? if devices.size == 1 devices[0] else puts "\nMultiple android devices '#{devices}' found.\nSpecify a single UDID. e.g. -u #{devices.sample}\n".red abort unless specs end end |
#info ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/flick/android.rb', line 54 def info specs = { os: "ro.build.version.release", manufacturer: "ro.product.manufacturer", model: "ro.product.model", sdk: "ro.build.version.sdk" } hash = { udid: udid } specs.each do |key, spec| value = `adb -s #{udid} shell getprop "#{spec}"`.strip hash.merge!({key=> "#{value}"}) end hash end |
#log(name) ⇒ Object
72 73 74 |
# File 'lib/flick/android.rb', line 72 def log name %x(adb -s #{udid} logcat -v long > #{outdir}/#{name}.log) end |
#os_version ⇒ Object
64 65 66 |
# File 'lib/flick/android.rb', line 64 def os_version `adb -s #{udid} shell getprop "ro.build.version.release"`.strip.to_f end |
#pull_file(file, dir) ⇒ Object
84 85 86 |
# File 'lib/flick/android.rb', line 84 def pull_file file, dir %x(adb -s #{udid} pull #{file} #{dir} >> /dev/null 2>&1) end |
#pull_files ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/flick/android.rb', line 100 def pull_files if unique files = unique_files else files = (`adb -s #{udid} shell "ls #{dir_name}/#{udid}*"`).split("\r\n") end return if files.empty? Parallel.map(files, in_threads: 10) { |file| pull_file file, flick_dir } end |
#recordable? ⇒ Boolean
76 77 78 |
# File 'lib/flick/android.rb', line 76 def recordable? (`adb -s #{udid} shell 'ls /system/bin/screenrecord'`).strip == "/system/bin/screenrecord" end |
#screenrecord(name) ⇒ Object
80 81 82 |
# File 'lib/flick/android.rb', line 80 def screenrecord name %x(adb -s #{udid} shell screenrecord --time-limit #{limit} --size 720x1280 #{dir_name}/#{name}.mp4) end |
#screenshot(name) ⇒ Object
68 69 70 |
# File 'lib/flick/android.rb', line 68 def screenshot name %x(adb -s #{udid} shell screencap #{dir_name}/#{name}.png) end |
#screenshots_exist? ⇒ Boolean
110 111 112 |
# File 'lib/flick/android.rb', line 110 def screenshots_exist? (`adb -s #{udid} shell "ls #{dir_name}/#{udid}-*.png | wc -l"`).to_i > 0 end |
#unique_files ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/flick/android.rb', line 88 def unique_files if os_version < 6.0 command = "md5" else command = "md5sum" end files = `adb -s #{udid} shell "#{command} #{dir_name}/#{udid}*"` hash = files.split("\r\n").map { |file| { md5: file.match(/(.*) /)[1].strip, file: file.match(/ (.*)/)[1].strip } } hash.uniq! { |e| e[:md5] } hash.map { |file| file[:file] } end |