ADB 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  *.swp
19
+ .idea
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.3-p194@ADB --create
1
+ rvm 1.9.3-p392@ADB --create
@@ -1,37 +1,34 @@
1
1
  language: java
2
2
  before_install:
3
- # download the latest android sdk and unzip
4
- - wget http://dl.google.com/android/android-sdk_r18-linux.tgz
5
- - tar -zxf android-sdk_r18-linux.tgz
6
-
7
- # This is a bit of a hack to get the android-15 arm abi installed
8
- - wget http://dl.google.com/android/repository/sysimg_armv7a-15_r02.zip
9
- - mkdir ~/builds/joelbyler/ADB/android-sdk-linux/system-images
10
- - mkdir ~/builds/joelbyler/ADB/android-sdk-linux/system-images/android-15
11
- - unzip sysimg_armv7a-15_r02.zip -d ~/builds/joelbyler/ADB/android-sdk-linux/system-images/android-15
12
-
13
- # setup your ANDROID_HOME and PATH environment variables
14
- # use ~/builds/[Github username]/[project]/android-sdk-linux
15
- - export ANDROID_HOME=~/builds/joelbyler/ADB/android-sdk-linux
16
- - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
17
-
18
- # only update the sdk for the tools and platform-tools (1,2) and whatever api level
19
- # you are building for android (run "android list sdk" to get the full list. 9 = 2.3.3 or API level 10
20
- #- android list sdk --all
21
- - android update sdk -u -f --filter 1,2
22
- - android update sdk -u -f --filter android-15
23
-
24
- # Create an emulator for testing against
25
- - echo no | android create avd -n Android_4.0.3 -t 1 --force
26
- - echo "hw.ramSize=2048" >> ~/.android/avd/Android_4.0.3.i
27
3
 
28
- # Need to figure out how to get the emulator to start up properly
29
- #- emulator -avd Android_4.0.3 -port 5554 -no-window -no-audio -no-boot-anim &
30
- #- adb wait-for-device
4
+ # Install base Android SDK
5
+ - sudo apt-get update -qq
6
+ - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch; fi
7
+ - wget http://dl.google.com/android/android-sdk_r21.0.1-linux.tgz
8
+ - tar xzf android-sdk_r21.0.1-linux.tgz
9
+ - export ANDROID_HOME=$PWD/android-sdk-linux
10
+ - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
11
+
12
+ # This is a bit of a hack to get the android-15 arm abi installed
13
+ - wget http://dl.google.com/android/repository/sysimg_armv7a-15_r02.zip
14
+ - mkdir -p ${ANDROID_HOME}/system-images/android-15
15
+ - unzip sysimg_armv7a-15_r02.zip -d ${ANDROID_HOME}/system-images/android-15
16
+
17
+ # Update SDK
18
+ - android update sdk -u -f --filter 1,2
19
+ - android update sdk -u -f --filter android-15
20
+
21
+ # Create an emulator for testing against
22
+ - echo no | android create avd -n Android_4.0.3 -t 1 --force
23
+ - echo "hw.ramSize=2048" >> ~/.android/avd/Android_4.0.3.i
24
+
25
+ # Need to figure out how to get the emulator to start up properly
26
+ - emulator -avd Android_4.0.3 -port 5554 -no-window -no-audio -no-boot-anim &
27
+ - sh wait_for_emulator.sh
31
28
 
32
29
  language: ruby
33
30
  rvm:
34
31
  - 1.9.3
35
32
 
36
- #after_script:
37
- #- bundle exec rake test
33
+ after_script:
34
+ - bundle exec rake test
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ === Release 0.5.6 / 2013-7-14
2
+ * Enhancements
3
+ * Added a helper method to list packages, list_packages(switches)
4
+
1
5
  === Release 0.5.5 / 2012-9-18
2
6
  * Enhancements
3
7
  * Added last Stdout and Stderr to ADBError messages
@@ -5,7 +9,7 @@
5
9
  === Release 0.5.4 / 2012-9-19
6
10
  * Fixes
7
11
  * Corrected push, pull when multiple arguments used
8
-
12
+
9
13
  === Release 0.5.3 / 2012-9-18
10
14
  * Enhancements
11
15
  * Added travis-ci config file for automated specs
@@ -17,7 +17,7 @@ Feature: Using the ADB module
17
17
  Given the adb server is started
18
18
  And I am connected to the local device
19
19
  Then I should be able to install the sample application
20
-
20
+
21
21
  Scenario: Providing command line options for installation
22
22
  Given the adb server is started
23
23
  And I am connected to the local device
@@ -32,7 +32,7 @@ Feature: Using the ADB module
32
32
  Given the adb server is started
33
33
  And I am connected to the local device
34
34
  When I change the devices date and time to 08/10/2012 11:25
35
- Then the device time should be Aug 10 11:25:00 EDT 2012
35
+ Then the device time should be Aug 10 11:25:00
36
36
 
37
37
  Scenario: Forwarding ports
38
38
  Given the adb server is started
@@ -58,4 +58,6 @@ Feature: Using the ADB module
58
58
  Given the adb server is started
59
59
  Then I should be able to pull a file from the local device
60
60
 
61
-
61
+ Scenario: List installed packages
62
+ Given the adb server is started
63
+ Then I can list the installed packages
@@ -1,6 +1,6 @@
1
1
  APK_FILE_NAME = 'features/support/ApiDemos.apk'
2
2
  TEMP_FILE_NAME = 'cuke_test_file.txt'
3
- TEMP_FILE_REMOTE_LOCATION = '/sdcard/'
3
+ TEMP_FILE_REMOTE_LOCATION = '/sdcard'
4
4
 
5
5
  When /^the adb server is started$/ do
6
6
  start_server
@@ -23,6 +23,7 @@ Given /^I am connected to the local device$/ do
23
23
  end
24
24
 
25
25
  Then /^I should see the device "(.*?)"$/ do |device|
26
+ puts devices
26
27
  devices.should include device
27
28
  end
28
29
 
@@ -80,15 +81,20 @@ Then /^I should be able to push a file to the local device$/ do
80
81
  sn = devices[0]
81
82
  wait_for_device({:serial => sn}, 60)
82
83
  remount({:serial => sn})
84
+
85
+ shell("mount -o rw,remount #{TEMP_FILE_REMOTE_LOCATION}", {:serial => sn})
86
+
83
87
  shell("rm #{TEMP_FILE_NAME}", {:serial => sn})
84
88
  shell("ls #{TEMP_FILE_NAME}", {:serial => sn})
89
+
90
+
85
91
  last_stdout.should include 'No such file or directory'
86
92
 
87
93
  # create the temp file
88
94
  File.open(TEMP_FILE_NAME, 'w'){ |f| f.write('Temporary file for adb testing. If found, please delete.') }
89
95
 
90
96
  # push the file
91
- push(TEMP_FILE_NAME, "#{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", {:serial => sn})
97
+ push(TEMP_FILE_NAME, "#{TEMP_FILE_REMOTE_LOCATION}/#{TEMP_FILE_NAME}", {:serial => sn})
92
98
  last_stderr.should_not include 'failed to copy'
93
99
 
94
100
  end
@@ -98,11 +104,16 @@ Then /^I should be able to pull a file from the local device$/ do
98
104
  sn = devices[0]
99
105
  wait_for_device({:serial => sn}, 60)
100
106
  remount({:serial => sn})
101
- shell("touch #{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", {:serial => sn})
107
+ shell("touch #{TEMP_FILE_REMOTE_LOCATION}/#{TEMP_FILE_NAME}", {:serial => sn})
102
108
 
103
109
  # pull the file
104
- pull "#{TEMP_FILE_REMOTE_LOCATION}#{TEMP_FILE_NAME}", #{TEMP_FILE_NAME}", {:serial => sn})
110
+ pull "#{TEMP_FILE_REMOTE_LOCATION}/#{TEMP_FILE_NAME}", "#{TEMP_FILE_NAME}", {:serial => sn}
105
111
 
106
112
  # confirm that the file was created
107
113
  File.exists?(TEMP_FILE_NAME).should == true
108
114
  end
115
+
116
+ Then(/^I can list the installed packages$/) do
117
+ list_packages
118
+ last_stdout.should include 'com.leandog.brazenhead'
119
+ end
@@ -17,5 +17,7 @@ end
17
17
  After do
18
18
  stop_server
19
19
  sleep 1
20
+
21
+ File.delete ('cuke_test_file.txt') unless not File.exists?('cuke_test_file.txt')
20
22
  end
21
23
 
data/lib/ADB.rb CHANGED
@@ -11,7 +11,7 @@ require 'date'
11
11
  module ADB
12
12
  include ADB::Instrumentation
13
13
 
14
- attr_reader :last_stdout, :last_stderr
14
+ attr_reader :last_stdout, :last_stderr
15
15
 
16
16
  #
17
17
  # start the server process
@@ -125,12 +125,25 @@ module ADB
125
125
  execute_adb_with(timeout, "#{which_one(target)} wait-for-device shell #{command}")
126
126
  end
127
127
 
128
+ #
129
+ # execute shell list packages command
130
+ #
131
+ # @param [String] optional switches, see adb shell list documentation
132
+ # @param [Hash] which device to wait for. Valid keys are :device,
133
+ # :emulator, and :serial.
134
+ # @param timeout value for the command to complete. Defaults to 30
135
+ # seconds.
136
+ #
137
+ def list_packages(switches='', target={}, timeout=30)
138
+ shell("pm list packages #{switches}", target, timeout)
139
+ end
140
+
128
141
  #
129
142
  # format a date for adb shell date command
130
143
  #
131
144
  # @param date to format. Defaults current date
132
145
  #
133
- def format_date_for_adb(date=Date.new)
146
+ def format_date_for_adb(date=Date.new)
134
147
  date.strftime("%C%y%m%d.%H%M00")
135
148
  end
136
149
 
@@ -207,7 +220,7 @@ module ADB
207
220
  def stdout_stderr_message
208
221
  if not last_stdout.empty?
209
222
  if not last_stderr.empty?
210
- return " Cause: #{last_stdout}, and Error: #{last_stderr}"
223
+ return " Cause: #{last_stdout}, and Error: #{last_stderr}"
211
224
  else
212
225
  return " Cause: #{last_stdout}"
213
226
  end
@@ -1,3 +1,3 @@
1
1
  module ADB
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
@@ -11,7 +11,7 @@ describe ADB do
11
11
  should_call_adb_with('kill-server')
12
12
  ADB.stop_server
13
13
  end
14
-
14
+
15
15
  it "should stop process if it takes too long" do
16
16
  ADB.should_receive(:last_stdout).and_return("device")
17
17
  process = double('process')
@@ -34,6 +34,15 @@ describe ADB do
34
34
  should_call_adb_with('wait-for-device', 'shell', 'date')
35
35
  ADB.shell('date')
36
36
  end
37
+
38
+ it "can list installed packages" do
39
+ should_call_adb_with('wait-for-device', 'shell', 'pm', 'list', 'packages')
40
+ ADB.list_packages
41
+ end
42
+ it "can list installed packages with packages" do
43
+ should_call_adb_with('wait-for-device', 'shell', 'pm', 'list', 'packages', '-f')
44
+ ADB.list_packages '-f'
45
+ end
37
46
  end
38
47
 
39
48
  it "should be able to build an date formatted for adb shell date command" do
@@ -67,7 +76,7 @@ describe ADB do
67
76
  should_call_adb_with('pull', '/usr/local file with spaces.txt', '/sdcard/remote file with spaces.txt')
68
77
  ADB.pull('/usr/local file with spaces.txt', '/sdcard/remote file with spaces.txt')
69
78
  end
70
-
79
+
71
80
  it "should be able to remount the /system drive" do
72
81
  should_call_adb_with('remount')
73
82
  ADB.remount
@@ -171,7 +180,7 @@ describe ADB do
171
180
  end
172
181
 
173
182
  it "should raise an error when the install fails" do
174
- ADB.should_receive(:last_stdout).and_return("some error")
183
+ ADB.should_receive(:last_stdout).any_number_of_times.and_return("some error")
175
184
  should_call_adb_with('wait-for-device', 'install', 'Test.apk')
176
185
  expect { ADB.install('Test.apk') }.to raise_error(ADBError)
177
186
  end
@@ -234,9 +243,9 @@ describe ADB do
234
243
  end
235
244
 
236
245
  end
237
-
238
-
246
+
247
+
239
248
  def should_call_adb_with(*args)
240
- ChildProcess.should_receive(:build).with('adb', *args).and_return(process_mock)
249
+ ChildProcess.should_receive(:build).with('adb', *args).and_return(process_mock)
241
250
  end
242
- end
251
+ end
@@ -0,0 +1,8 @@
1
+ until [ "`adb devices | grep "emulator-[0-9][0-9]*[[:space:]]*device"`" ]
2
+ do
3
+ echo "waiting for emulator..."
4
+ sleep 10
5
+ done
6
+ echo "emulator ready. waiting a sec because emulators are fickle beasts..."
7
+ sleep 45
8
+ echo "Ready to roll"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ADB
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-29 00:00:00.000000000 Z
13
+ date: 2013-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: childprocess
@@ -91,6 +91,7 @@ files:
91
91
  - spec/lib/ADB/instrumentation_spec.rb
92
92
  - spec/lib/ADB_spec.rb
93
93
  - spec/spec_helper.rb
94
+ - wait_for_emulator.sh
94
95
  homepage: http://github.com/cheezy/ADB
95
96
  licenses: []
96
97
  post_install_message:
@@ -105,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  segments:
107
108
  - 0
108
- hash: 4475756240764748213
109
+ hash: 3749825286168687281
109
110
  required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  none: false
111
112
  requirements:
@@ -114,10 +115,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  segments:
116
117
  - 0
117
- hash: 4475756240764748213
118
+ hash: 3749825286168687281
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 1.8.24
121
+ rubygems_version: 1.8.25
121
122
  signing_key:
122
123
  specification_version: 3
123
124
  summary: Simple wrapper over Android Debug Bridge command-line tool