Class: AndroidAdb::Adb
- Inherits:
-
Object
- Object
- AndroidAdb::Adb
- Defined in:
- lib/android-adb/Adb.rb
Instance Attribute Summary collapse
-
#adb_path ⇒ Object
Returns the value of attribute adb_path.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#last_command ⇒ Object
Returns the value of attribute last_command.
-
#show_stderr ⇒ Object
Returns the value of attribute show_stderr.
Instance Method Summary collapse
-
#get_devices ⇒ Array<Device>
Returns a list of all connected devices.
-
#get_packages(adb_opts = {}) ⇒ Hash
Returns a list of all installed packages on the device.
-
#initialize(opts = {}) ⇒ Adb
constructor
Contructs an Adb object for issuing commands to the connected device or emulator.
-
#install(package, opts = {}, adb_opts = {}) ⇒ Object
Installs a package from the APK file
package
onto the device/emulator. -
#run_adb(args, adb_opts = {}) {|stdout| ... } ⇒ Object
Run the adb command with the give
args
. -
#run_adb_shell(args, adb_args = {}) {|stdout| ... } ⇒ Object
Run the device shell command given by
args
.
Constructor Details
#initialize(opts = {}) ⇒ Adb
Contructs an Adb object for issuing commands to the connected device or emulator.
If the adb path is not specified in the opts
hash it is determined in the following order:
-
Try and use the unix which command to locate the adb binary.
-
Use the ANDROID_HOME environment variable.
-
Default to adb (no path specified).
24 25 26 27 28 |
# File 'lib/android-adb/Adb.rb', line 24 def initialize(opts = {}) @show_stderr = opts[:show_stderr] || false @dry_run = opts[:dry_run] || false @adb_path = opts[:adb_path] || Adb.find_adb end |
Instance Attribute Details
#adb_path ⇒ Object
Returns the value of attribute adb_path.
11 12 13 |
# File 'lib/android-adb/Adb.rb', line 11 def adb_path @adb_path end |
#dry_run ⇒ Object
Returns the value of attribute dry_run.
11 12 13 |
# File 'lib/android-adb/Adb.rb', line 11 def dry_run @dry_run end |
#last_command ⇒ Object
Returns the value of attribute last_command.
11 12 13 |
# File 'lib/android-adb/Adb.rb', line 11 def last_command @last_command end |
#show_stderr ⇒ Object
Returns the value of attribute show_stderr.
11 12 13 |
# File 'lib/android-adb/Adb.rb', line 11 def show_stderr @show_stderr end |
Instance Method Details
#get_devices ⇒ Array<Device>
Returns a list of all connected devices. The collection is returned as a hash containing the device name :name
and the serial :serial
.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/android-adb/Adb.rb', line 33 def get_devices devices = [] run_adb("devices") do |pout| pout.each do |line| line = line.strip if (!line.empty? && line !~ /^List of devices/) parts = line.split device = AndroidAdb::Device.new(parts[0], parts[1]) devices << device end end end return devices end |
#get_packages(adb_opts = {}) ⇒ Hash
Returns a list of all installed packages on the device.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/android-adb/Adb.rb', line 51 def get_packages(adb_opts = {}) packages = [] run_adb_shell("pm list packages -f", adb_opts) do |pout| pout.each do |line| parts = line.split(":") if (parts.length > 1) info = parts[1].strip.split("=") package = AndroidAdb::Package.new(info[1], info[0]); packages << package; end end end return packages end |
#install(package, opts = {}, adb_opts = {}) ⇒ Object
Installs a package from the APK file package
onto the device/emulator.
73 74 75 76 77 78 79 |
# File 'lib/android-adb/Adb.rb', line 73 def install(package, opts = {}, adb_opts = {}) opt_arg = "" opt_arg += " -l" if opts[:forwardlock] opt_arg += " -r" if opts[:reinstall] opt_arg += " -s" if opts[:sdcard] run_adb("install#{opt_arg} #{package}", adb_opts) end |
#run_adb(args, adb_opts = {}) {|stdout| ... } ⇒ Object
Run the adb command with the give args
.
88 89 90 91 92 93 94 95 96 |
# File 'lib/android-adb/Adb.rb', line 88 def run_adb(args, adb_opts = {}, &block) # :yields: stdout adb_arg = "" adb_arg += " -s #{adb_opts[:serial]}" if !adb_opts[:serial].nil? && !adb_opts[:serial].empty? adb_arg += " -e #{adb_opts[:emulator]}" if adb_opts[:emulator] adb_arg += " -d #{adb_opts[:device]}" if adb_opts[:emulator] path = "#{@adb_path}#{adb_arg} #{args}" last_command = path run(path, &block) end |
#run_adb_shell(args, adb_args = {}) {|stdout| ... } ⇒ Object
Run the device shell command given by args
.
102 103 104 105 |
# File 'lib/android-adb/Adb.rb', line 102 def run_adb_shell(args, adb_args = {}, &block) # :yields: stdout args = "shell #{args}" run_adb(args, adb_args, &block) end |