Class: ADB
- Inherits:
-
Object
- Object
- ADB
- Defined in:
- lib/android-adb-extension/adb.rb
Overview
Class to handle Android Debug Bridge shell commands
Class Method Summary collapse
- .airplane_mode ⇒ Object
- .airplane_mode? ⇒ Boolean
- .bring_to_foreground(package, activity) ⇒ Object
- .device_name ⇒ Object
- .disable_airplane_mode ⇒ Object
- .enable_airplane_mode ⇒ Object
- .help ⇒ Object (also: h)
- .input_text(text) ⇒ Object
- .landscape? ⇒ Boolean
- .lock ⇒ Object
- .major ⇒ Object
- .monkey(package, event_count = 500) ⇒ Object
- .orientation ⇒ Object
- .portrait? ⇒ Boolean
- .release ⇒ Object
- .reset_app(package) ⇒ Object
- .sdk ⇒ Object
- .send_to_background ⇒ Object
- .serial ⇒ Object
- .set_landscape ⇒ Object
- .set_portrait ⇒ Object
- .start_intent(uri) ⇒ Object
- .stop_app(package) ⇒ Object
- .swipe(x1, y1, x2, y2, duration = nil) ⇒ Object
- .take_screenshot(file_name) ⇒ Object
- .uninstall_app(package) ⇒ Object
- .unlock ⇒ Object
Class Method Details
.airplane_mode ⇒ Object
55 56 57 |
# File 'lib/android-adb-extension/adb.rb', line 55 def airplane_mode `#{adb_shell_command} settings get global airplane_mode_on`.strip.to_i end |
.airplane_mode? ⇒ Boolean
59 60 61 |
# File 'lib/android-adb-extension/adb.rb', line 59 def airplane_mode? airplane_mode.to_boolean end |
.bring_to_foreground(package, activity) ⇒ Object
92 93 94 95 |
# File 'lib/android-adb-extension/adb.rb', line 92 def bring_to_foreground(package, activity) res = `#{adb_shell_command} am start -n #{package}/#{activity}` res.empty? ? nil : res end |
.device_name ⇒ Object
21 22 23 |
# File 'lib/android-adb-extension/adb.rb', line 21 def device_name `#{adb_shell_command} getprop ro.product.model`.strip end |
.disable_airplane_mode ⇒ Object
67 68 69 |
# File 'lib/android-adb-extension/adb.rb', line 67 def disable_airplane_mode change_airplane_mode(0) end |
.enable_airplane_mode ⇒ Object
63 64 65 |
# File 'lib/android-adb-extension/adb.rb', line 63 def enable_airplane_mode change_airplane_mode(1) end |
.help ⇒ Object Also known as: h
133 134 135 |
# File 'lib/android-adb-extension/adb.rb', line 133 def help public_methods(false) end |
.input_text(text) ⇒ Object
117 118 119 120 |
# File 'lib/android-adb-extension/adb.rb', line 117 def input_text(text) res = `#{adb_shell_command} input text #{text}` res.empty? ? nil : res end |
.landscape? ⇒ Boolean
36 37 38 39 |
# File 'lib/android-adb-extension/adb.rb', line 36 def landscape? rotation = orientation rotation.eql?(1) || rotation.eql?(3) end |
.lock ⇒ Object
75 76 77 78 79 80 |
# File 'lib/android-adb-extension/adb.rb', line 75 def lock cmd = "#{adb_shell_command} input keyevent 26" `#{cmd}` res = `#{cmd}` res.empty? ? nil : res end |
.major ⇒ Object
13 14 15 |
# File 'lib/android-adb-extension/adb.rb', line 13 def major release.chomp.split('.').first.to_i end |
.monkey(package, event_count = 500) ⇒ Object
71 72 73 |
# File 'lib/android-adb-extension/adb.rb', line 71 def monkey(package, event_count = 500) `#{adb_shell_command} monkey -p #{package} #{event_count}` end |
.orientation ⇒ Object
25 26 27 28 29 |
# File 'lib/android-adb-extension/adb.rb', line 25 def orientation `#{adb_shell_command} dumpsys input | grep 'SurfaceOrientation' | awk '{ print $2 }'`.strip.to_i end |
.portrait? ⇒ Boolean
31 32 33 34 |
# File 'lib/android-adb-extension/adb.rb', line 31 def portrait? rotation = orientation rotation.eql?(0) || rotation.eql?(2) end |
.release ⇒ Object
9 10 11 |
# File 'lib/android-adb-extension/adb.rb', line 9 def release `#{adb_shell_command} getprop ro.build.version.release`.strip end |
.reset_app(package) ⇒ Object
97 98 99 100 |
# File 'lib/android-adb-extension/adb.rb', line 97 def reset_app(package) res = `#{adb_shell_command} pm clear #{package}` res.empty? ? nil : res end |
.sdk ⇒ Object
5 6 7 |
# File 'lib/android-adb-extension/adb.rb', line 5 def sdk `#{adb_shell_command} getprop ro.build.version.sdk`.strip.to_i end |
.send_to_background ⇒ Object
87 88 89 90 |
# File 'lib/android-adb-extension/adb.rb', line 87 def send_to_background res = `#{adb_shell_command} input keyevent 3` res.empty? ? nil : res end |
.serial ⇒ Object
17 18 19 |
# File 'lib/android-adb-extension/adb.rb', line 17 def serial `#{adb_shell_command} getprop ro.serialno`.strip end |
.set_landscape ⇒ Object
48 49 50 51 52 53 |
# File 'lib/android-adb-extension/adb.rb', line 48 def set_landscape change_accelerometer_control(0) res = change_device_orientation(1) change_accelerometer_control(1) res.empty? ? nil : res end |
.set_portrait ⇒ Object
41 42 43 44 45 46 |
# File 'lib/android-adb-extension/adb.rb', line 41 def set_portrait change_accelerometer_control(0) res = change_device_orientation(0) change_accelerometer_control(1) res.empty? ? nil : res end |
.start_intent(uri) ⇒ Object
112 113 114 115 |
# File 'lib/android-adb-extension/adb.rb', line 112 def start_intent(uri) res = `#{adb_shell_command} am start -a android.intent.action.VIEW -d #{uri}` res.empty? ? nil : res end |
.stop_app(package) ⇒ Object
102 103 104 105 |
# File 'lib/android-adb-extension/adb.rb', line 102 def stop_app(package) res = `#{adb_shell_command} am force-stop #{package}` res.empty? ? nil : res end |
.swipe(x1, y1, x2, y2, duration = nil) ⇒ Object
127 128 129 130 131 |
# File 'lib/android-adb-extension/adb.rb', line 127 def swipe(x1, y1, x2, y2, duration = nil) args = duration.nil? ? "#{x1} #{y1} #{x2} #{y2}" : "#{x1} #{y1} #{x2} #{y2} #{duration}" res = `#{adb_shell_command} input swipe #{args}` res.empty? ? nil : res end |
.take_screenshot(file_name) ⇒ Object
122 123 124 125 |
# File 'lib/android-adb-extension/adb.rb', line 122 def take_screenshot(file_name) res = `#{adb_shell_command} screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > #{file_name}.png` res.empty? ? nil : res end |
.uninstall_app(package) ⇒ Object
107 108 109 110 |
# File 'lib/android-adb-extension/adb.rb', line 107 def uninstall_app(package) res = `#{adb_shell_command} pm uninstall #{package}` res.empty? ? nil : res end |
.unlock ⇒ Object
82 83 84 85 |
# File 'lib/android-adb-extension/adb.rb', line 82 def unlock res = `#{adb_shell_command} input keyevent 82` res.empty? ? nil : res end |