adb-sdklib 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/adb-sdklib.gemspec +28 -0
- data/lib/adb-sdklib.rb +53 -0
- data/lib/adb_sdklib/common.rb +33 -0
- data/lib/adb_sdklib/device.rb +61 -0
- data/lib/adb_sdklib/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTE3YzhiZDg1MzU4MzkxZGM1N2I5Y2IxYjIwYTgxNWQ1OWY0ZWU5NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NmM3MzE5NmZhZjQxNmI0NjkyNjRkZWY4NGFkNzQwMmViMTA3NzJiOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTY3ODE0OTI4MzI3Mzc4YTMwNzQ3ZmY4ZTQxMTZjNjQ0YzkxNTZlNzJmNzkz
|
10
|
+
NzZmM2QwYzU4NWMzN2U2MjY3MzU0ZGQwMDZhZjcyZWExMGQzNWY2YTM5MjU1
|
11
|
+
ZmIwZWQyZGQyNjA4YWRhNTMyOTMxZWUwYWRjZjdjOWU4MDNjNjY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzFjYzhjYzUxNDRlNzdmOWNmNDZhODU1NzM5ZWQzN2Q5NTkzNTA0ZThjMzli
|
14
|
+
MzA1ZDU4ZTA3NGE0ZDA1MWVmMTRjNGNiOWM3MDg0NDY0ZGZmODAyYmQ1MzRj
|
15
|
+
NmU0YTc0NGZkYjQ2ODdkZjc0NzUxNWY5M2E5MDRhYjRhOGI0MDQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 yoyo0906
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# adb-sdklib
|
2
|
+
|
3
|
+
Android Debug Bridge (ADB) wrapper using Android SDK Tools Library with Rjb
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
```bash
|
7
|
+
# Install Rjb
|
8
|
+
$ export JAVA_HOME=<your java home path>
|
9
|
+
$ gem install rjb
|
10
|
+
|
11
|
+
# Install adb-sdklib
|
12
|
+
$ gem install adb-sdklib
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Adb Object
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'adb-sdklib'
|
21
|
+
adb = AdbSdkLib::Adb.new
|
22
|
+
# If 'adb' command-line tool isn't in your $PATH, set adb location to constructor shown as below
|
23
|
+
# adb = AdbSdkLib::Adb.new(<adb location>)
|
24
|
+
|
25
|
+
# Get device objects
|
26
|
+
devices = adb.devices
|
27
|
+
```
|
28
|
+
|
29
|
+
**Adb** object is wrapper of *com.android.ddmlib.AndroidDebugBridge*.
|
30
|
+
Source code of *com.android.ddmlib.AndroidDebugBridge*:
|
31
|
+
<https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/AndroidDebugBridge.java>
|
32
|
+
|
33
|
+
Some methods of *AndroidDebugBridge* are wrapped for Ruby.
|
34
|
+
For remaining methods, *Adb#method_missing* is defined to call
|
35
|
+
wrapping java object's same name method using specified parameters.
|
36
|
+
|
37
|
+
### Device Object
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
adb = AdbSdkLib::Adb.new
|
41
|
+
device = adb.devices.first
|
42
|
+
# device = adb.devices['xxxxxx'] # get by serial number of the device.
|
43
|
+
puts <<"EOS"
|
44
|
+
serial : #{device.serial}
|
45
|
+
state : #{device.state}
|
46
|
+
emulator : #{device.emulator?}
|
47
|
+
build ver : #{device.build_version}
|
48
|
+
api level : #{device.api_level}
|
49
|
+
device model : #{device.device_model}
|
50
|
+
manufacturer : #{device.manufacturer}
|
51
|
+
build desc : #{device.property('ro.build.description')}
|
52
|
+
battery level : #{device.battery_level}
|
53
|
+
EOS
|
54
|
+
```
|
55
|
+
|
56
|
+
**Device** object is wrapper of *com.android.ddmlib.Device*.
|
57
|
+
Source code of *com.android.ddmlib.Device*:
|
58
|
+
<https://android.googlesource.com/platform/tools/base/+/master/ddmlib/src/main/java/com/android/ddmlib/Device.java>
|
59
|
+
|
60
|
+
Some methods of *ddmlib.Device* are wrapped for Ruby.
|
61
|
+
For remaining methods, *Device#method_missing* is defined to call
|
62
|
+
wrapping java object's same name method using specified parameters.
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( http://github.com/yoyo0906/ruby-adb-sdklib/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
- MIT License
|
75
|
+
- Copyright (c) 2014 yoyo0906
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/adb-sdklib.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'adb_sdklib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "adb-sdklib"
|
8
|
+
spec.version = AdbSdkLib::VERSION
|
9
|
+
spec.authors = ["yoyo"]
|
10
|
+
spec.email = ["yoyo0906@gmail.com"]
|
11
|
+
spec.summary = "Android Debug Bridge (ADB) wrapper" +
|
12
|
+
" using Android SDK Tools Library with Rjb."
|
13
|
+
spec.description = "Ruby library for basic access to Android devices through" +
|
14
|
+
" ADB using ddmlib.jar which is included Android SDK Tools" +
|
15
|
+
" via Rjb (Ruby Java Bridge)."
|
16
|
+
spec.homepage = "http://github.com/yoyo0906/ruby-adb-sdklib"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'rjb'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
end
|
data/lib/adb-sdklib.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "adb_sdklib/version"
|
3
|
+
require 'adb_sdklib/common'
|
4
|
+
require 'adb_sdklib/device'
|
5
|
+
|
6
|
+
module AdbSdkLib
|
7
|
+
class Adb
|
8
|
+
include Common
|
9
|
+
|
10
|
+
@@AndroidDebugBridge = nil
|
11
|
+
|
12
|
+
def initialize(adb_location = nil, force_new_bridge = false)
|
13
|
+
if adb_location.nil?
|
14
|
+
@adbpath = `which adb`.chomp!
|
15
|
+
else
|
16
|
+
@adbpath = adb_location
|
17
|
+
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
|
+
|
23
|
+
if @@AndroidDebugBridge.nil?
|
24
|
+
load_jar("#{libpath}/ddmlib.jar")
|
25
|
+
@@AndroidDebugBridge = Rjb::import('com.android.ddmlib.AndroidDebugBridge')
|
26
|
+
@@AndroidDebugBridge.initIfNeeded(false)
|
27
|
+
at_exit { Adb.terminate }
|
28
|
+
end
|
29
|
+
|
30
|
+
@adb = @@AndroidDebugBridge.createBridge(@adbpath, force_new_bridge)
|
31
|
+
10.times { |i|
|
32
|
+
break if @adb.connected?
|
33
|
+
sleep(0.25)
|
34
|
+
}
|
35
|
+
raise AdbError, 'Connect adb error (timeout)' unless @adb.connected?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.terminate
|
39
|
+
unless @@AndroidDebugBridge.nil?
|
40
|
+
@@AndroidDebugBridge.terminate
|
41
|
+
@@AndroidDebugBridge = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def devices
|
46
|
+
devices = @adb.devices.map { |d| Device.new(d) }
|
47
|
+
class << devices
|
48
|
+
def [](serial); self.find { |d| d.serial_number == serial } end
|
49
|
+
end
|
50
|
+
return devices
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rjb'
|
3
|
+
|
4
|
+
module AdbSdkLib
|
5
|
+
class AdbError < StandardError; end
|
6
|
+
|
7
|
+
module Common
|
8
|
+
def load_jar(lib)
|
9
|
+
raise AdbError, "Not found #{lib}" unless File.exist?(lib)
|
10
|
+
Rjb::load(lib)
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert_map_to_hash(object, &block)
|
14
|
+
hash = Hash.new
|
15
|
+
i = object.entrySet.iterator
|
16
|
+
if block_given?
|
17
|
+
while i.hasNext
|
18
|
+
entry = i.next
|
19
|
+
yield hash, entry.getKey, entry.getValue
|
20
|
+
end
|
21
|
+
else
|
22
|
+
while i.hasNext
|
23
|
+
entry = i.next
|
24
|
+
hash[entry.getKey] = entry.getValue
|
25
|
+
end
|
26
|
+
end
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
|
30
|
+
module_function(:load_jar, :convert_map_to_hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'adb_sdklib/common'
|
3
|
+
|
4
|
+
module AdbSdkLib
|
5
|
+
class Device
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def initialize(device)
|
9
|
+
unless device.instance_of?(Rjb::Rjb_JavaProxy) &&
|
10
|
+
device.getClass.getCanonicalName == 'com.android.ddmlib.Device'
|
11
|
+
raise TypeError, "Parameter is not com.android.ddmlib.Device class"
|
12
|
+
end
|
13
|
+
@device = device
|
14
|
+
end
|
15
|
+
|
16
|
+
def serial; @device.serial_number end
|
17
|
+
def state; @device.state.toString.to_sym end
|
18
|
+
def online?; @device.online? end
|
19
|
+
def emulator?; @device.emulator? end
|
20
|
+
def offline?; @device.offline? end
|
21
|
+
def bootloader?; @device.bootloader? end
|
22
|
+
def reboot(into=nil) @device.reboot(into) end
|
23
|
+
def property_count; @device.property_count end
|
24
|
+
def property(prop); @device.property(prop) end
|
25
|
+
def properties
|
26
|
+
convert_map_to_hash(@device.properties) { |hash, key, value|
|
27
|
+
hash[key.toString] = value.toString
|
28
|
+
}
|
29
|
+
end
|
30
|
+
def build_version; @device.property(@device.PROP_BUILD_VERSION) end
|
31
|
+
def api_level; @device.property(@device.PROP_BUILD_API_LEVEL) end
|
32
|
+
def build_codename; @device.property(@device.PROP_BUILD_CODENAME) end
|
33
|
+
def device_model; @device.property(@device.PROP_DEVICE_MODEL) end
|
34
|
+
def device_manufacturer; @device.property(@device.PROP_DEVICE_MANUFACTURER) end
|
35
|
+
def debuggable; @device.property(@device.PROP_DEBUGGABLE) end
|
36
|
+
|
37
|
+
def battery_level(freshness_ms=nil)
|
38
|
+
if freshness_ms.nil?
|
39
|
+
@device.battery_level.int_value
|
40
|
+
else
|
41
|
+
@device.battery_level(freshness_ms).int_value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(action, *args)
|
46
|
+
return @device.__send__(action, *args)
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"Android: ID:#{self.serial}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
"#<AdbSdkLib::Device:#{self.serial}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def to_ary; nil end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adb-sdklib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yoyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rjb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ruby library for basic access to Android devices through ADB using ddmlib.jar
|
56
|
+
which is included Android SDK Tools via Rjb (Ruby Java Bridge).
|
57
|
+
email:
|
58
|
+
- yoyo0906@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- adb-sdklib.gemspec
|
69
|
+
- lib/adb-sdklib.rb
|
70
|
+
- lib/adb_sdklib/common.rb
|
71
|
+
- lib/adb_sdklib/device.rb
|
72
|
+
- lib/adb_sdklib/version.rb
|
73
|
+
homepage: http://github.com/yoyo0906/ruby-adb-sdklib
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Android Debug Bridge (ADB) wrapper using Android SDK Tools Library with Rjb.
|
97
|
+
test_files: []
|