class AdbSdkLib::Adb
Public Class Methods
new(adb_location = nil, force_new_bridge = false)
click to toggle source
Initialize Rjb and connect to ADB. @param [String] adb_location Location of ADB command line tool @param [Boolean] force_new_bridge if set true, start force new ADB server @raise [AdbError] If could not found ADB command line tool
# File lib/adb-sdklib.rb, line 43 def initialize(adb_location = nil, force_new_bridge = false) if adb_location.nil? @adbpath = `which adb`.chomp! raise AdbError, "Not found 'adb' command in $PATH" unless @adbpath else @adbpath = adb_location raise AdbError, "Not found 'adb' command" unless @adbpath end # load jar files unless @@java_initialized load_sdk_tools_jar(['ddmlib.jar']) # Hide logs to be output to the console. ddm = Rjb::import('com.android.ddmlib.DdmPreferences') ddm.setLogLevel('assert') @@java_initialized = true at_exit { Adb.terminate } end if @@adb.nil? @@adb = Rjb::import('com.android.ddmlib.AndroidDebugBridge') @@adb.initIfNeeded(false) end @adb = @@adb.createBridge(@adbpath, force_new_bridge) 10.times { |i| break if @adb.connected? sleep(0.25) } raise AdbError, 'Connect adb error (timeout)' unless @adb.connected? @devices = DeviceList.new end
terminate()
click to toggle source
Terminate ADB connection. This method will be called automatically when exiting ruby. @return [self] self
# File lib/adb-sdklib.rb, line 79 def self.terminate unless @@adb.nil? @@adb.terminate @@adb = nil end self end
Public Instance Methods
devices()
click to toggle source
Get devices attached with ADB. @return [DeviceList] List of devices
# File lib/adb-sdklib.rb, line 89 def devices devices = @adb.devices.map { |d| serial = d.serial_number (@devices.has_key?(serial) && same_jobject?(@devices[serial].jobject, d)) \ ? @devices[serial] : Device.new(d) } @devices = DeviceList.new(devices) return @devices end
Private Instance Methods
load_sdk_tools_jar(libs)
click to toggle source
@private
# File lib/adb-sdklib.rb, line 102 def load_sdk_tools_jar(libs) libpath = File.expand_path('../tools/lib/', File.dirname(@adbpath)) libs.each do |lib| lib = "#{libpath}/#{lib}" raise AdbError, "Not found #{lib}" unless File.exist?(lib) Rjb::add_jar(lib) end end