Class: ADB

Inherits:
Object
  • Object
show all
Defined in:
lib/android-adb-extension/adb.rb

Overview

Class to handle Android Debug Bridge shell commands

Class Method Summary collapse

Class Method Details

.airplane_modeObject



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

Returns:

  • (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_nameObject



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_modeObject



67
68
69
# File 'lib/android-adb-extension/adb.rb', line 67

def disable_airplane_mode
  change_airplane_mode(0)
end

.enable_airplane_modeObject



63
64
65
# File 'lib/android-adb-extension/adb.rb', line 63

def enable_airplane_mode
  change_airplane_mode(1)
end

.helpObject 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

Returns:

  • (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

.lockObject



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

.majorObject



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

.orientationObject



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

Returns:

  • (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

.releaseObject



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

.sdkObject



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_backgroundObject



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

.serialObject



17
18
19
# File 'lib/android-adb-extension/adb.rb', line 17

def serial
  `#{adb_shell_command} getprop ro.serialno`.strip
end

.set_landscapeObject



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_portraitObject



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

.unlockObject



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