Class: AdbSdkLib::Adb
- Inherits:
-
Object
- Object
- AdbSdkLib::Adb
- Defined in:
- lib/adb-sdklib.rb
Class Method Summary collapse
-
.terminate ⇒ self
Terminate ADB connection.
Instance Method Summary collapse
-
#devices ⇒ DeviceList
Get devices attached with ADB.
-
#initialize(adb_location = nil, force_new_bridge = false) ⇒ Adb
constructor
Initialize Rjb and connect to ADB.
Constructor Details
#initialize(adb_location = nil, force_new_bridge = false) ⇒ Adb
Initialize Rjb and connect to ADB.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |
Class Method Details
.terminate ⇒ self
Terminate ADB connection. This method will be called automatically when exiting ruby.
79 80 81 82 83 84 85 |
# File 'lib/adb-sdklib.rb', line 79 def self.terminate unless @@adb.nil? @@adb.terminate @@adb = nil end self end |
Instance Method Details
#devices ⇒ DeviceList
Get devices attached with ADB.
89 90 91 92 93 94 95 96 97 |
# 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 |