ADB 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/ADB/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Jeffrey S. Morgan"]
6
- gem.email = ["jeff.morgan@leandog.com"]
5
+ gem.authors = ["Jeffrey S. Morgan", "Joel Byler"]
6
+ gem.email = ["jeff.morgan@leandog.com", "joelbyler@gmail.com"]
7
7
  gem.description = %q{Simple wrapper over Android Debug Bridge command-line tool}
8
8
  gem.summary = %q{Simple wrapper over Android Debug Bridge command-line tool}
9
9
  gem.homepage = "http://github.com/cheezy/ADB"
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === Release 0.3 / 2012-8-22
2
+ * Enhancements
3
+ * Added remount method (mounts /system as root)
4
+ * Added push method to push files to a device
5
+ * Added pull method to pull files from a device
6
+ * Added root method
7
+
1
8
  === Release 0.2 / 2012-8-18
2
9
  * Enhancements
3
10
  * Added forward method
@@ -33,3 +33,24 @@ Feature: Using the ADB module
33
33
  Given the adb server is started
34
34
  And I am connected to the local device
35
35
  Then I should be able to forward "tcp:7777" to "tcp:5555"
36
+
37
+ Scenario: Remount the system partition for read-write access
38
+ Given the adb server is started
39
+ And I am connected to the local device
40
+ Then I can remount the system partition
41
+
42
+ Scenario: Restart adb in root mode
43
+ Given the adb server is started
44
+ And I am connected to the local device
45
+ Then I can attain root privileges
46
+
47
+ Scenario: Push a file
48
+ Given the adb server is started
49
+ And I am connected to the local device
50
+ Then I should be able to push a file to the local device
51
+
52
+ Scenario: Pull a file
53
+ Given the adb server is started
54
+ Then I should be able to pull a file from the local device
55
+
56
+
@@ -7,6 +7,8 @@ Then /^the adb server should be running$/ do
7
7
  end
8
8
 
9
9
  Then /^I should be able to connect to a local device$/ do
10
+ sn = devices[0]
11
+ wait_for_device({:serial => sn}, 60)
10
12
  connect('localhost')
11
13
  last_stdout.should include "connected to localhost"
12
14
  disconnect('localhost')
@@ -39,7 +41,7 @@ When /^I change the devices date and time to (.*?)$/ do |date_arg|
39
41
  shell("date -s #{format_date_for_adb(date)}", {:serial => sn}, 60)
40
42
  end
41
43
 
42
- Then /^the device time should be Aug (.*?)$/ do |date_str|
44
+ Then /^the device time should be (.*?)$/ do |date_str|
43
45
  last_stdout.should include date_str
44
46
  end
45
47
 
@@ -47,3 +49,49 @@ Then /^I should be able to forward "(.*?)" to "(.*?)"$/ do |source, target|
47
49
  sn = devices[0]
48
50
  forward(source, target, {:serial => sn})
49
51
  end
52
+
53
+ Then /^I can remount the system partition$/ do
54
+ sn = devices[0]
55
+ wait_for_device({:serial => sn}, 60)
56
+ remount({:serial => sn})
57
+ last_stdout.should include 'remount succeeded'
58
+ end
59
+
60
+ Then /^I can attain root privileges$/ do
61
+ sn = devices[0]
62
+ wait_for_device({:serial => sn}, 60)
63
+ root({:serial => sn})
64
+ #TODO: how to assert?
65
+ #last_stdout.should include 'remount succeeded'
66
+ end
67
+
68
+ Then /^I should be able to push a file to the local device$/ do
69
+ # confirm that the file doesn't already exist
70
+ sn = devices[0]
71
+ wait_for_device({:serial => sn}, 60)
72
+ remount({:serial => sn})
73
+ shell('ls /system/cuke_test_file.txt', {:serial => sn})
74
+ last_stdout.should include 'No such file or directory'
75
+
76
+ # create the temp file
77
+ File.open('cuke_test_file.txt', 'w'){ |f| f.write('Temporary file for adb testing. If found, please delete.') }
78
+
79
+ # push the file
80
+ push('cuke_test_file.txt', '/system/cuke_test_file.txt', {:serial => sn})
81
+ last_stderr.should_not include 'failed to copy'
82
+
83
+ end
84
+
85
+ Then /^I should be able to pull a file from the local device$/ do
86
+ # confirm that the file exists on the device and not locally
87
+ sn = devices[0]
88
+ wait_for_device({:serial => sn}, 60)
89
+ remount({:serial => sn})
90
+ shell("touch /system/cuke_test_file.txt", {:serial => sn})
91
+
92
+ # pull the file
93
+ pull('/system/cuke_test_file.txt', 'cuke_test_file.txt', {:serial => sn})
94
+
95
+ # confirm that the file was created
96
+ File.exists?('cuke_test_file.txt').should == true
97
+ end
@@ -6,7 +6,7 @@ require 'ADB'
6
6
 
7
7
  World(ADB)
8
8
 
9
- emulator = ChildProcess.build('emulator', '-avd', 'Android_4.0.3')
9
+ emulator = ChildProcess.build('emulator', '-avd', 'Android_4.0.3', '-port', '5554')
10
10
  emulator.start
11
11
 
12
12
  at_exit do
data/lib/ADB.rb CHANGED
@@ -146,6 +146,58 @@ module ADB
146
146
  execute_adb_with(timeout, "#{which_one(target)} forward #{source} #{destination}")
147
147
  end
148
148
 
149
+ #
150
+ # push a file
151
+ #
152
+ # @param the fully quanified source (local) file name
153
+ # @param the fully quanified destination (device) file name
154
+ # @param [Hash] which device to wait for. Valid keys are :device,
155
+ # :emulator, and :serial.
156
+ # @param timeout value for the command to complete. Defaults to 30
157
+ # seconds.
158
+ #
159
+ def push(source, destination, target={}, timeout=30)
160
+ execute_adb_with(timeout, "#{which_one(target)} push #{source} #{destination}")
161
+ end
162
+
163
+ #
164
+ # push a file
165
+ #
166
+ # @param the fully quanified source (device) file name
167
+ # @param the fully quanified destination (local) file name
168
+ # @param [Hash] which device to wait for. Valid keys are :device,
169
+ # :emulator, and :serial.
170
+ # @param timeout value for the command to complete. Defaults to 30
171
+ # seconds.
172
+ #
173
+ def pull(source, destination, target={}, timeout=30)
174
+ execute_adb_with(timeout, "#{which_one(target)} pull #{source} #{destination}")
175
+ end
176
+
177
+ #
178
+ # remount /system as read-write
179
+ #
180
+ # @param [Hash] which device to wait for. Valid keys are :device,
181
+ # :emulator, and :serial.
182
+ # @param timeout value for the command to complete. Defaults to 30
183
+ # seconds.
184
+ #
185
+ def remount(target={}, timeout=30)
186
+ execute_adb_with(timeout, "#{which_one(target)} remount")
187
+ end
188
+
189
+ #
190
+ # restarts the adb daemon with root permissions
191
+ #
192
+ # @param [Hash] which device to wait for. Valid keys are :device,
193
+ # :emulator, and :serial.
194
+ # @param timeout value for the command to complete. Defaults to 30
195
+ # seconds.
196
+ #
197
+ def root(target={}, timeout=30)
198
+ execute_adb_with(timeout, "#{which_one(target)} root")
199
+ end
200
+
149
201
  private
150
202
 
151
203
  def execute_adb_with(timeout, arguments)
@@ -1,3 +1,3 @@
1
1
  module ADB
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -45,7 +45,27 @@ describe ADB do
45
45
  should_call_adb_with('forward', 'src', 'dest')
46
46
  ADB.forward('src', 'dest')
47
47
  end
48
+
49
+ it "should push a file" do
50
+ should_call_adb_with('push', '/usr/foo.txt', '/sdcard/bar.txt')
51
+ ADB.push('/usr/foo.txt', '/sdcard/bar.txt')
52
+ end
53
+
54
+ it "should pull a file" do
55
+ should_call_adb_with('pull', '/usr/foo.txt', '/sdcard/bar.txt')
56
+ ADB.pull('/usr/foo.txt', '/sdcard/bar.txt')
57
+ end
48
58
 
59
+ it "should be able to remount the /system drive" do
60
+ should_call_adb_with('remount')
61
+ ADB.remount
62
+ end
63
+
64
+ it "should be able to provide root access" do
65
+ should_call_adb_with('root')
66
+ ADB.root
67
+ end
68
+
49
69
  context "when connecting to a device" do
50
70
  before(:each) do
51
71
  ADB.should_receive(:last_stdout).and_return("connected to localhost")
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ADB
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeffrey S. Morgan
9
+ - Joel Byler
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-08-18 00:00:00.000000000 Z
13
+ date: 2012-08-22 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: childprocess
@@ -62,6 +63,7 @@ dependencies:
62
63
  description: Simple wrapper over Android Debug Bridge command-line tool
63
64
  email:
64
65
  - jeff.morgan@leandog.com
66
+ - joelbyler@gmail.com
65
67
  executables: []
66
68
  extensions: []
67
69
  extra_rdoc_files: []
@@ -98,18 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
100
  - - ! '>='
99
101
  - !ruby/object:Gem::Version
100
102
  version: '0'
101
- segments:
102
- - 0
103
- hash: -1607274235838869715
104
103
  required_rubygems_version: !ruby/object:Gem::Requirement
105
104
  none: false
106
105
  requirements:
107
106
  - - ! '>='
108
107
  - !ruby/object:Gem::Version
109
108
  version: '0'
110
- segments:
111
- - 0
112
- hash: -1607274235838869715
113
109
  requirements: []
114
110
  rubyforge_project:
115
111
  rubygems_version: 1.8.24