adb-sdklib 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.yardopts +5 -0
- data/README.md +23 -9
- data/adb-sdklib.gemspec +1 -1
- data/lib/adb-sdklib.rb +74 -17
- data/lib/adb_sdklib/common.rb +70 -5
- data/lib/adb_sdklib/device.rb +186 -29
- data/lib/adb_sdklib/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGI1NWY1ZTRjNDdlNDFkOWU0YzNhODI4OWZlNjZhY2M5Mjg0ZTFiYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmQ4ZTg4NTI5MWVhYWQwOWRkMWY3NGVkOTgyYWIyNDMwZDhkMDI0Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWYzOTZjNDM2NDNmYzI0MmZiY2M1NTliYjY2OTkxZDkzMjYwOTk3NzUzNmI5
|
10
|
+
ZWI5ZjZiYzY4M2MwZTZmZjE4NzM5ZGMyYTA2YjM0MTZmODQyZTY3YjJhYTgy
|
11
|
+
YzEyNDg1OWIwMmU3YWE5MWUwOTRlOWJiZGNhZWMxNTA1N2YzMTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjlmZDA0YzVlMGI2NTdiMDAwMDA4ZjA5Y2U4NWQ5ZTRmYWYxOWMzZDUwODU1
|
14
|
+
ZWM0OGJjMzFmZTE1M2RmMjMxYzRjZmFlM2U4OTlkMmU1N2Q4NDcwZDMxNTYy
|
15
|
+
ODE2OWFlOGM2MjNhZTA3NWQ2NDhjNTMzNWI0NjZlZTg0ZGI4ZTg=
|
data/.yardopts
ADDED
data/README.md
CHANGED
@@ -14,19 +14,19 @@ $ gem install adb-sdklib
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
-
### Adb
|
17
|
+
### *Adb* object
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
require 'adb-sdklib'
|
21
21
|
adb = AdbSdkLib::Adb.new
|
22
22
|
# If 'adb' command-line tool isn't in your $PATH, set adb location to constructor shown as below
|
23
|
-
# adb = AdbSdkLib::Adb.new(
|
23
|
+
# adb = AdbSdkLib::Adb.new('/path/to/adb')
|
24
24
|
|
25
25
|
# Get device objects
|
26
26
|
devices = adb.devices
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
*Adb* object is wrapper of *com.android.ddmlib.AndroidDebugBridge*.
|
30
30
|
Source code of *com.android.ddmlib.AndroidDebugBridge*:
|
31
31
|
<https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/AndroidDebugBridge.java>
|
32
32
|
|
@@ -34,12 +34,14 @@ Some methods of *AndroidDebugBridge* are wrapped for Ruby.
|
|
34
34
|
For remaining methods, *Adb#method_missing* is defined to call
|
35
35
|
wrapping java object's same name method using specified parameters.
|
36
36
|
|
37
|
-
### Device
|
37
|
+
### *Device* object
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
adb = AdbSdkLib::Adb.new
|
41
41
|
device = adb.devices.first
|
42
|
-
# device = adb.devices['xxxxxx'] # get by serial number
|
42
|
+
# device = adb.devices['xxxxxx'] # get by the device's serial number.
|
43
|
+
|
44
|
+
# Display attributes
|
43
45
|
puts <<"EOS"
|
44
46
|
serial : #{device.serial}
|
45
47
|
state : #{device.state}
|
@@ -48,16 +50,28 @@ build ver : #{device.build_version}
|
|
48
50
|
api level : #{device.api_level}
|
49
51
|
device model : #{device.device_model}
|
50
52
|
manufacturer : #{device.manufacturer}
|
51
|
-
build desc : #{device.property('ro.build.description')}
|
52
|
-
battery level : #{device.battery_level}
|
53
53
|
EOS
|
54
|
+
|
55
|
+
# Push a file to the device
|
56
|
+
device.push('local.txt', '/data/local/tmp/')
|
57
|
+
|
58
|
+
# Pull a file from the device
|
59
|
+
device.pull('/system/build.prop', '/path/to/dir/')
|
60
|
+
|
61
|
+
# Execute shell
|
62
|
+
puts device.shell('ps') # display results
|
63
|
+
|
64
|
+
device.shell('ls /data/local/tmp/') { |line| # each line
|
65
|
+
puts line
|
66
|
+
}
|
67
|
+
|
54
68
|
```
|
55
69
|
|
56
|
-
|
70
|
+
*Device* object is wrapper of *com.android.ddmlib.Device*.
|
57
71
|
Source code of *com.android.ddmlib.Device*:
|
58
72
|
<https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/Device.java>
|
59
73
|
|
60
|
-
Some methods of *ddmlib.Device* are wrapped for Ruby.
|
74
|
+
Some methods of *ddmlib.Device* are wrapped for Ruby.
|
61
75
|
For remaining methods, *Device#method_missing* is defined to call
|
62
76
|
wrapping java object's same name method using specified parameters.
|
63
77
|
|
data/adb-sdklib.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'adb_sdklib/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "adb-sdklib"
|
8
8
|
spec.version = AdbSdkLib::VERSION
|
9
|
-
spec.authors = ["
|
9
|
+
spec.authors = ["yoyo0906"]
|
10
10
|
spec.email = ["yoyo0906@gmail.com"]
|
11
11
|
spec.summary = "Android Debug Bridge (ADB) wrapper" +
|
12
12
|
" using Android SDK Tools Library with Rjb."
|
data/lib/adb-sdklib.rb
CHANGED
@@ -4,50 +4,107 @@ require 'adb_sdklib/common'
|
|
4
4
|
require 'adb_sdklib/device'
|
5
5
|
|
6
6
|
module AdbSdkLib
|
7
|
+
# List of devices.
|
8
|
+
# It can be used as Enumerable like Set, and as Hash which key
|
9
|
+
# is the serial number of the device.
|
10
|
+
class DeviceList < Hash
|
11
|
+
# @param [Enumerable] devices Device object of Java
|
12
|
+
def initialize(devices = [])
|
13
|
+
devices.each { |d| self[d.serial_number] = d }
|
14
|
+
end
|
15
|
+
# Calls block once for each device in self, passing that device as a parameter.
|
16
|
+
# If no block is given, an enumerator is returned instead.
|
17
|
+
# @return [Enumerator] if not block given
|
18
|
+
# @return [self] if block given
|
19
|
+
# @yield [device] called with each device
|
20
|
+
# @yieldparam [Device] device a device instance
|
21
|
+
def each
|
22
|
+
return self.values.each unless block_given?
|
23
|
+
self.values.each {|device| yield device }
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
7
28
|
class Adb
|
8
29
|
include Common
|
9
30
|
|
10
|
-
|
31
|
+
# @private
|
32
|
+
@@java_initialized = false
|
11
33
|
|
34
|
+
# @private
|
35
|
+
# AndroidDebugBridge class object
|
36
|
+
@@adb = nil
|
37
|
+
|
38
|
+
# Initialize Rjb and connect to ADB.
|
39
|
+
# @param [String] adb_location Location of ADB command line tool
|
40
|
+
# @param [Boolean] force_new_bridge if set true, start force new ADB server
|
41
|
+
# @raise [AdbError] If could not found ADB command line tool
|
12
42
|
def initialize(adb_location = nil, force_new_bridge = false)
|
13
43
|
if adb_location.nil?
|
14
44
|
@adbpath = `which adb`.chomp!
|
45
|
+
raise AdbError, "Not found 'adb' command in $PATH" unless @adbpath
|
15
46
|
else
|
16
47
|
@adbpath = adb_location
|
48
|
+
raise AdbError, "Not found 'adb' command" unless @adbpath
|
17
49
|
end
|
18
|
-
raise AdbError, "Not found 'adb' command in $PATH" unless @adbpath
|
19
|
-
|
20
|
-
# load AndroidDebugBridge
|
21
|
-
libpath = File.expand_path('../tools/lib/', File.dirname(@adbpath))
|
22
50
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
51
|
+
# load jar files
|
52
|
+
unless @@java_initialized
|
53
|
+
load_sdk_tools_jar(['ddmlib.jar'])
|
54
|
+
# Hide logs to be output to the console.
|
55
|
+
ddm = Rjb::import('com.android.ddmlib.DdmPreferences')
|
56
|
+
ddm.setLogLevel('assert')
|
57
|
+
@@java_initialized = true
|
27
58
|
at_exit { Adb.terminate }
|
28
59
|
end
|
60
|
+
if @@adb.nil?
|
61
|
+
@@adb = Rjb::import('com.android.ddmlib.AndroidDebugBridge')
|
62
|
+
@@adb.initIfNeeded(false)
|
63
|
+
end
|
29
64
|
|
30
|
-
@adb = @@
|
65
|
+
@adb = @@adb.createBridge(@adbpath, force_new_bridge)
|
31
66
|
10.times { |i|
|
32
67
|
break if @adb.connected?
|
33
68
|
sleep(0.25)
|
34
69
|
}
|
35
70
|
raise AdbError, 'Connect adb error (timeout)' unless @adb.connected?
|
71
|
+
|
72
|
+
@devices = DeviceList.new
|
36
73
|
end
|
37
74
|
|
75
|
+
# Terminate ADB connection.
|
76
|
+
# This method will be called automatically when exiting ruby.
|
77
|
+
# @return [self] self
|
38
78
|
def self.terminate
|
39
|
-
unless @@
|
40
|
-
@@
|
41
|
-
@@
|
79
|
+
unless @@adb.nil?
|
80
|
+
@@adb.terminate
|
81
|
+
@@adb = nil
|
42
82
|
end
|
83
|
+
self
|
43
84
|
end
|
44
85
|
|
86
|
+
# Get devices attached with ADB.
|
87
|
+
# @return [DeviceList] List of devices
|
45
88
|
def devices
|
46
|
-
devices = @adb.devices.map { |d|
|
47
|
-
|
48
|
-
|
89
|
+
devices = @adb.devices.map { |d|
|
90
|
+
serial = d.serial_number
|
91
|
+
(@devices.has_key?(serial) && same_jobject?(@devices[serial].jobject, d)) \
|
92
|
+
? @devices[serial] : Device.new(d)
|
93
|
+
}
|
94
|
+
@devices = DeviceList.new(devices)
|
95
|
+
return @devices
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
# @private
|
101
|
+
def load_sdk_tools_jar(libs)
|
102
|
+
libpath = File.expand_path('../tools/lib/', File.dirname(@adbpath))
|
103
|
+
libs.each do |lib|
|
104
|
+
lib = "#{libpath}/#{lib}"
|
105
|
+
raise AdbError, "Not found #{lib}" unless File.exist?(lib)
|
106
|
+
Rjb::add_jar(lib)
|
49
107
|
end
|
50
|
-
return devices
|
51
108
|
end
|
52
109
|
end
|
53
110
|
end
|
data/lib/adb_sdklib/common.rb
CHANGED
@@ -2,14 +2,79 @@
|
|
2
2
|
require 'rjb'
|
3
3
|
|
4
4
|
module AdbSdkLib
|
5
|
+
# ADB error
|
5
6
|
class AdbError < StandardError; end
|
7
|
+
|
8
|
+
# Error on java
|
9
|
+
class SdkLibError < StandardError
|
10
|
+
# @return [String] error message
|
11
|
+
attr_reader :error_message
|
12
|
+
# @return [String] exception class name on Java
|
13
|
+
attr_reader :exception_name
|
14
|
+
# @return [String] class name
|
15
|
+
attr_reader :class_name
|
16
|
+
# @return [String] method name
|
17
|
+
attr_reader :method_name
|
18
|
+
|
19
|
+
# @param [String] message error message
|
20
|
+
# @param [String] exception_name exception class name on Java
|
21
|
+
# @param [String] class_name class name
|
22
|
+
# @param [String] method_name method name
|
23
|
+
def initialize(message, exception_name, class_name, method_name)
|
24
|
+
super("#{message} (#{exception_name}) - [#{class_name}##{method_name}()]")
|
25
|
+
@error_message = message
|
26
|
+
@exception_name = exception_name
|
27
|
+
@class_name = class_name
|
28
|
+
@method_name = method_name
|
29
|
+
end
|
30
|
+
end
|
6
31
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
32
|
+
# @private
|
33
|
+
class CommandCapture
|
34
|
+
def initialize(line_receiver = nil)
|
35
|
+
@output = ''
|
36
|
+
@line_receiver = line_receiver
|
37
|
+
end
|
38
|
+
|
39
|
+
# Override
|
40
|
+
def addOutput(data, offset, length)
|
41
|
+
out = data[offset..(offset + length - 1)] # -1 for ¥x00
|
42
|
+
@output << out.force_encoding('UTF-8')
|
43
|
+
unless @line_receiver.nil?
|
44
|
+
lines = @output.split("\n")
|
45
|
+
@output = (@output[-1] != "\n") ? lines.pop : ''
|
46
|
+
lines.each { |line|
|
47
|
+
@line_receiver.call(line.chomp)
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Override
|
53
|
+
def flush
|
54
|
+
if !@line_receiver.nil? && !@output.empty?
|
55
|
+
@line_receiver.call(@output)
|
56
|
+
@output = ''
|
57
|
+
end
|
11
58
|
end
|
12
59
|
|
60
|
+
# Override
|
61
|
+
def isCancelled; false end
|
62
|
+
|
63
|
+
def to_s; @output end
|
64
|
+
end
|
65
|
+
|
66
|
+
# @private
|
67
|
+
module Common
|
68
|
+
# @private
|
69
|
+
System = Rjb::import('java.lang.System')
|
70
|
+
|
71
|
+
# Inspects whether two objects are the same of Java instance.
|
72
|
+
def same_jobject?(obj1, obj2)
|
73
|
+
System.identityHashCode(obj1) \
|
74
|
+
== System.identityHashCode(obj2)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Converts Java Map object to Ruby Hash object.
|
13
78
|
def convert_map_to_hash(object, &block)
|
14
79
|
hash = Hash.new
|
15
80
|
i = object.entrySet.iterator
|
@@ -27,7 +92,7 @@ module AdbSdkLib
|
|
27
92
|
hash
|
28
93
|
end
|
29
94
|
|
30
|
-
module_function(:
|
95
|
+
module_function(:same_jobject?, :convert_map_to_hash)
|
31
96
|
end
|
32
97
|
end
|
33
98
|
|
data/lib/adb_sdklib/device.rb
CHANGED
@@ -1,61 +1,218 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'adb_sdklib/common'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
module AdbSdkLib
|
6
|
+
|
7
|
+
# One of android device attached to host through ADB.
|
8
|
+
#
|
9
|
+
# This is a wrapper of com.android.ddmlib.Device object in Java.
|
5
10
|
class Device
|
6
11
|
include Common
|
7
12
|
|
13
|
+
# @param [Rjb::Rjb_JavaProxy] device Rjb proxy object of com.android.ddmlib.Device
|
8
14
|
def initialize(device)
|
9
15
|
unless device.instance_of?(Rjb::Rjb_JavaProxy) &&
|
10
|
-
device.
|
16
|
+
device._classname == 'com.android.ddmlib.Device'
|
11
17
|
raise TypeError, "Parameter is not com.android.ddmlib.Device class"
|
12
18
|
end
|
19
|
+
class << device
|
20
|
+
def call_java_method(method_name, *args)
|
21
|
+
rjb_method_missing(method_name, *args)
|
22
|
+
rescue => e
|
23
|
+
raise SdkLibError.new(e.message, e.class.to_s, self._classname, method_name)
|
24
|
+
end
|
25
|
+
alias_method :rjb_method_missing, :method_missing
|
26
|
+
alias_method :method_missing, :call_java_method
|
27
|
+
end
|
13
28
|
@device = device
|
14
29
|
end
|
15
30
|
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def
|
23
|
-
|
24
|
-
|
31
|
+
# @!attribute [r] jobject
|
32
|
+
# @return [Rjb::Rjb_JavaProxy] Wrapper of com.android.ddmlib.Device object.
|
33
|
+
def jobject; @device end
|
34
|
+
|
35
|
+
# @!attribute [r] serial
|
36
|
+
# @return [String] the serial number of the device.
|
37
|
+
def serial; @device.getSerialNumber end
|
38
|
+
|
39
|
+
# @!attribute [r] state
|
40
|
+
# @return [Symbol] the state of the device.
|
41
|
+
# (:BOOTLOADER, :OFFLINE, :ONLINE, :RECOVERY)
|
42
|
+
def state; @device.getState.toString.to_sym end
|
43
|
+
|
44
|
+
# @!attribute [r] online?
|
45
|
+
# @return [Boolean] true if the device is ready.
|
46
|
+
def online?; @device.isOnline end
|
47
|
+
|
48
|
+
# @!attribute [r] emulator?
|
49
|
+
# @return [Boolean] true if the device is an emulator.
|
50
|
+
def emulator?; @device.isEmulator end
|
51
|
+
|
52
|
+
# @!attribute [r] offline?
|
53
|
+
# @return [Boolean] true if the device is offline.
|
54
|
+
def offline?; @device.isOffline end
|
55
|
+
|
56
|
+
# @!attribute [r] bootloader?
|
57
|
+
# @return [Boolean] true if the device is in bootloader mode.
|
58
|
+
def bootloader?; @device.isBootloader end
|
59
|
+
|
60
|
+
# Reboot the device
|
61
|
+
# @param [String, nil] into the bootloader name to reboot into,
|
62
|
+
# or nil to just reboot the device
|
63
|
+
# @return [self]
|
64
|
+
def reboot(into=nil) @device.reboot(into); self end
|
65
|
+
|
66
|
+
# Returns the property count.
|
67
|
+
# @return [Integer] the number of property for this device.
|
68
|
+
def property_count; @device.getPropertyCount end
|
69
|
+
|
70
|
+
# Returns a property value.
|
71
|
+
# @param [String] name the name of the value to return.
|
72
|
+
# @return [String, nil] the value or nil if the property does not exist.
|
73
|
+
def property(name); @device.getProperty(name) end
|
74
|
+
|
75
|
+
# Returns the device properties. It contains the whole output of 'getprop'
|
76
|
+
# @return [Hash<String, String>] the device properties
|
25
77
|
def properties
|
26
|
-
convert_map_to_hash(@device.
|
78
|
+
convert_map_to_hash(@device.getProperties) do |hash, key, value|
|
27
79
|
hash[key.toString] = value.toString
|
28
|
-
|
80
|
+
end
|
29
81
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def
|
36
|
-
|
37
|
-
|
82
|
+
|
83
|
+
# the build version of the android on the device.
|
84
|
+
# (same as output of 'getprop ro.build.version.release')
|
85
|
+
# @!attribute [r] build_version
|
86
|
+
# @return [String] the build version of the android.
|
87
|
+
def build_version; property(@device.PROP_BUILD_VERSION) end
|
88
|
+
|
89
|
+
# the API level of the android on the device.
|
90
|
+
# (same as output of 'getprop ro.build.version.sdk')
|
91
|
+
# @!attribute [r] api_level
|
92
|
+
# @return [String] the API level.
|
93
|
+
def api_level; property(@device.PROP_BUILD_API_LEVEL) end
|
94
|
+
|
95
|
+
# the build code name of the android on the device.
|
96
|
+
# @!attribute [r] build_codename
|
97
|
+
# (same as output of 'getprop ro.build.version.codename')
|
98
|
+
# @return [String] the build code name.
|
99
|
+
def build_codename; property(@device.PROP_BUILD_CODENAME) end
|
100
|
+
|
101
|
+
# the product model of the device.
|
102
|
+
# (same as output of 'getprop ro.product.model')
|
103
|
+
# @!attribute [r] device_model
|
104
|
+
# @return [String] the device model.
|
105
|
+
def device_model; property(@device.PROP_DEVICE_MODEL) end
|
106
|
+
|
107
|
+
# the product manufacturer of the device.
|
108
|
+
# (same as output of 'getprop ro.product.manufacturer')
|
109
|
+
# @!attribute [r] device_manufacturer
|
110
|
+
# @return [String] the product manufacturer.
|
111
|
+
def device_manufacturer; property(@device.PROP_DEVICE_MANUFACTURER) end
|
112
|
+
|
113
|
+
# the device debuggable.
|
114
|
+
# (same as output of 'getprop ro.debuggable')
|
115
|
+
# @!attribute [r] debuggable
|
116
|
+
# @return [String] the device debuggable.
|
117
|
+
def debuggable; property(@device.PROP_DEBUGGABLE) end
|
118
|
+
|
119
|
+
# Returns the battery level.
|
120
|
+
# @param [Integer] freshness_ms freshness time (milliseconds).
|
121
|
+
# @return [Integer] the battery level.
|
122
|
+
def battery_level(freshness_ms = nil)
|
38
123
|
if freshness_ms.nil?
|
39
|
-
@device.
|
124
|
+
@device.getBatteryLevel.intValue
|
40
125
|
else
|
41
|
-
@device.
|
126
|
+
@device.getBatteryLevel(freshness_ms).intValue
|
42
127
|
end
|
43
128
|
end
|
44
129
|
|
45
|
-
|
46
|
-
|
130
|
+
# Executes a shell command on the device, and receives the result.
|
131
|
+
# @!method shell(command)
|
132
|
+
# @return [String, self]
|
133
|
+
# @overload shell(command)
|
134
|
+
# @param [String] command the command to execute
|
135
|
+
# @return [String] all results of the command.
|
136
|
+
# @overload shell(command)
|
137
|
+
# @param [String] command the command to execute
|
138
|
+
# @return [self] self
|
139
|
+
# @yield [line]
|
140
|
+
# @yieldparam [String] line each line of results of the command.
|
141
|
+
def shell(command, &block)
|
142
|
+
capture = CommandCapture.new(block_given? ? block : nil)
|
143
|
+
receiver = Rjb::bind(capture, 'com.android.ddmlib.IShellOutputReceiver')
|
144
|
+
@device.executeShellCommand(command.to_s, receiver)
|
145
|
+
block_given? ? self : capture.to_s
|
146
|
+
end
|
147
|
+
|
148
|
+
# Pushes a file to the device.
|
149
|
+
#
|
150
|
+
# If *remotefile* path ends with '/', complements by the basename of
|
151
|
+
# *localfile*.
|
152
|
+
# @example
|
153
|
+
# device = AdbSdkLib::Adb.new.devices.first
|
154
|
+
# device.push('path/to/local.txt', '/data/local/tmp/remote.txt')
|
155
|
+
# device.push('path/to/file.txt', '/data/local/tmp/') # uses file.txt
|
156
|
+
# @param [String] localfile the name of the local file to send
|
157
|
+
# @param [String] remotefile the name of the remote file or directory
|
158
|
+
# on the device
|
159
|
+
# @return [self] self
|
160
|
+
# @raise [ArgumentError] If *localfile* is not found
|
161
|
+
def push(localfile, remotefile)
|
162
|
+
raise ArgumentError, "Not found #{localfile}" unless File.exist?(localfile)
|
163
|
+
if remotefile.end_with?('/')
|
164
|
+
remotefile = "#{remotefile}#{File.basename(localfile)}"
|
165
|
+
end
|
166
|
+
@device.pushFile(localfile, remotefile)
|
167
|
+
self
|
47
168
|
end
|
48
169
|
|
49
|
-
|
50
|
-
|
170
|
+
# Pulls a file from the device.
|
171
|
+
#
|
172
|
+
# If *localfile* path ends with '/', complements by the basename of
|
173
|
+
# *remotefile*.
|
174
|
+
# @example
|
175
|
+
# device = AdbSdkLib::Adb.new.devices.first
|
176
|
+
# device.pull('/data/local/tmp/remote.txt', 'path/to/local.txt')
|
177
|
+
# device.pull('/data/local/tmp/file.txt', 'path/to/dir/') # uses file.txt
|
178
|
+
# @param [String] remotefile the name of the remote file on the device to get
|
179
|
+
# @param [String] localfile the name of the local file or directory
|
180
|
+
# @return [self] self
|
181
|
+
def pull(remotefile, localfile)
|
182
|
+
if localfile.end_with?('/') || File.directory?(localfile)
|
183
|
+
localdir = localfile.chomp('/')
|
184
|
+
localfilename = nil
|
185
|
+
else
|
186
|
+
localdir = File.dirname(localfile)
|
187
|
+
localfilename = File.basename(localfile)
|
188
|
+
end
|
189
|
+
unless File.exist?(localdir)
|
190
|
+
FileUtils.mkdir_p(localdir)
|
191
|
+
end
|
192
|
+
|
193
|
+
localfilename = File.basename(remotefile) if localfilename.nil?
|
194
|
+
@device.pullFile(remotefile, "#{localdir}/#{localfilename}")
|
195
|
+
self
|
51
196
|
end
|
52
197
|
|
53
|
-
|
54
|
-
|
198
|
+
# Calls wrapping java object's same name method with arguments.
|
199
|
+
# @param [String] method_name method name to call
|
200
|
+
# @param [Array] args arguments
|
201
|
+
# @return [Object] result of the method call
|
202
|
+
def method_missing(method_name, *args)
|
203
|
+
return @device.__send__(method_name, *args)
|
55
204
|
end
|
56
205
|
|
206
|
+
# Converts self to string.
|
207
|
+
# @return [String] convert to string
|
208
|
+
def to_s; "Android:#{self.serial}" end
|
209
|
+
|
210
|
+
# Returns the human-readable formatted information.
|
211
|
+
# @return [String] the human-readable formatted information
|
212
|
+
def inspect; "#<AdbSdkLib::Device:#{self.serial}>" end
|
213
|
+
|
57
214
|
private
|
215
|
+
# @private
|
58
216
|
def to_ary; nil end
|
59
217
|
end
|
60
218
|
end
|
61
|
-
|
data/lib/adb_sdklib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adb-sdklib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- yoyo0906
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rjb
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- .gitignore
|
64
|
+
- .yardopts
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|