device_api-android 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e869674eefcdfc233369a21f2d14d11d27df450
4
- data.tar.gz: 6da4897b07d21f066230bd3bd9ada5f3240a6764
3
+ metadata.gz: 7dfe569584ed7b09ceb48bb274a0c974798f10f6
4
+ data.tar.gz: 8269d27b46ae49ff8bf354f06dfa8abb8bc713ce
5
5
  SHA512:
6
- metadata.gz: e543135408a47beef36b487b98d481235120f441df30af60aae043a5775ae1d131fc9cd9ca802f91977a3e258956c8d4f1677d78b930a42bc965c56dfd8d9bbe
7
- data.tar.gz: f62b5e92503750c0bdd704295761b7189aa1e2e4193e41f1c7611201f689d32581621463b2234f662fc5fe95fc480a715a5bf0e4a0edefcba9b570917d356f91
6
+ metadata.gz: 95d0ded27c12b01421de3d766a7373ef79d18effc903ae420a5091e81af378fed9a7ef845998db7d25496826c7d8f5d9e4d2a7b22fb85ee4481185c90eb9d3de
7
+ data.tar.gz: 4ae9c1c9b96d4df37ad18cbb41ef01344e47204baf03c92cbeab6231f5b9aa60356d7eb53c34e8e21cfedd8dabff876dfe3fd91d9b9c8f3993298643e51617cd
@@ -10,6 +10,7 @@ require 'device_api/android/plugins/disk'
10
10
 
11
11
  # Load additional device types
12
12
  require 'device_api/android/device/kindle'
13
+ require 'device_api/android/device/samsung'
13
14
 
14
15
  module DeviceAPI
15
16
  module Android
@@ -17,7 +18,7 @@ module DeviceAPI
17
18
  def self.devices
18
19
  ADB.devices.map do |d|
19
20
  if d.keys.first && !d.keys.first.include?('?')
20
- DeviceAPI::Android::Device.create( self.get_device_type(d.keys.first), { serial: d.keys.first, state: d.values.first } )
21
+ DeviceAPI::Android::Device.create( self.get_device_type(d), { serial: d.keys.first, state: d.values.first } )
21
22
  end
22
23
  end
23
24
  end
@@ -28,15 +29,18 @@ module DeviceAPI
28
29
  raise DeviceAPI::BadSerialString.new("serial was '#{serial.nil? ? 'nil' : serial}'")
29
30
  end
30
31
  state = ADB.get_state(serial)
31
- DeviceAPI::Android::Device.create( self.get_device_type(serial), { serial: serial, state: state })
32
+ DeviceAPI::Android::Device.create( self.get_device_type({ "#{serial}": state}), { serial: serial, state: state })
32
33
  end
33
34
 
34
35
  # Return the device type used in determining which Device Object to create
35
- def self.get_device_type(serial)
36
- return :default if Device.new(serial: serial).manufacturer.nil?
37
- case Device.new(serial: serial).manufacturer.downcase
36
+ def self.get_device_type(options)
37
+ return :default if options.values.first == 'unauthorized'
38
+ return :default if Device.new(serial: options.keys.first, state: options.values.first).manufacturer.nil?
39
+ case Device.new(serial: options.keys.first).manufacturer.downcase
38
40
  when 'amazon'
39
41
  type = :kindle
42
+ when 'samsung'
43
+ type = :samsung
40
44
  else
41
45
  type = :default
42
46
  end
@@ -42,7 +42,7 @@ module DeviceAPI
42
42
 
43
43
  raise ADBCommandError.new(result.stderr) if result.exit != 0
44
44
 
45
- lines = result.stdout.encode('UTF-8', invalid: :replace).split("\n")
45
+ lines = result.stdout.encode('UTF-16', 'UTF-8', invalid: :replace, replace: '').encode('UTF-8', 'UTF-16').split("\n")
46
46
 
47
47
  process_dumpsys('\[(.*)\]:\s+\[(.*)\]', lines)
48
48
  end
@@ -263,12 +263,40 @@ module DeviceAPI
263
263
  # @param serial serial number of device
264
264
  # @param command -option activity
265
265
  # @example
266
- # DeviceAPI::ADB.am(serial, "-a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings")
266
+ # DeviceAPI::ADB.am(serial, "start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings")
267
267
  def self.am(serial, command)
268
- result = execute("adb -s #{serial} shell am start #{command}")
268
+ result = execute("adb -s #{serial} shell am #{command}")
269
269
  raise ADBCommandError.new(result.stderr) if result.exit != 0
270
270
  return result.stdout
271
271
  end
272
+
273
+ # Package manager commands
274
+ # @param serial serial of device
275
+ # @param command command to issue to the package manager
276
+ # @example DeviceAPI::ADB.pm(serial, 'list packages')
277
+ def self.pm(serial, command)
278
+ result = execute("adb -s #{serial} shell pm #{command}")
279
+ raise ADBCommandError.new(result.stderr) if result.exit != 0
280
+ return result.stdout
281
+ end
282
+
283
+ # Blocks a package, used on Android versions less than KitKat
284
+ # Returns boolean
285
+ # @param serial serial of device
286
+ # @param package to block
287
+ def self.block_package(serial, package)
288
+ result = pm(serial, "block #{package}")
289
+ result.include?('true')
290
+ end
291
+
292
+ # Blocks a package on KitKat and above
293
+ # Returns boolean
294
+ # @param serial serial of device
295
+ # @param package to hide
296
+ def self.hide_package(serial, package)
297
+ result = pm(serial, "hide #{package}")
298
+ result.include?('true')
299
+ end
272
300
  end
273
301
 
274
302
  # ADB Error class
@@ -86,6 +86,14 @@ module DeviceAPI
86
86
  !get_battery_info.select { |keys| keys.include?('powered')}.select { |_,v| v == 'true' }.empty?
87
87
  end
88
88
 
89
+ def block_package(package)
90
+ if version < "5.0.0"
91
+ ADB.block_package(serial, package)
92
+ else
93
+ ADB.hide_package(serial, package)
94
+ end
95
+ end
96
+
89
97
  # Return the device orientation
90
98
  # @return (String) current device orientation
91
99
  def orientation
@@ -141,6 +149,11 @@ module DeviceAPI
141
149
  result
142
150
  end
143
151
 
152
+ def list_installed_packages
153
+ packages = ADB.pm(serial, 'list packages')
154
+ packages.split("\r\n")
155
+ end
156
+
144
157
  # Return the app version number for a specified apk
145
158
  # @param [String] apk string containing path to the apk
146
159
  # @return [String, Exception] app version number if it can be found, otherwise an error is raised
@@ -220,8 +233,8 @@ module DeviceAPI
220
233
  # @param [String] command to start the intent
221
234
  # Return the stdout of executed intent
222
235
  # @return [String] stdout
223
- def start_intent(command)
224
- ADB.am(serial,command)
236
+ def intent(command)
237
+ ADB.am(serial, command)
225
238
  end
226
239
 
227
240
  #Reboots the device
@@ -0,0 +1,18 @@
1
+ module DeviceAPI
2
+ module Android
3
+ # Samsung specific device class
4
+ class Samsung < Device
5
+ def initialize(options = {})
6
+
7
+ super
8
+ packages = list_installed_packages
9
+ multi_window = 'com.sec.android.app.FlashBarService'
10
+ if packages.include?("package:#{multi_window}")
11
+ # Stop the multi window function from running and block it
12
+ intent("force-stop #{multi_window}")
13
+ block_package("#{multi_window}")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: device_api-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Buckhurst
8
8
  - Jitesh Gosai
9
+ - Asim Khan
9
10
  - Jon Wilson
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2015-10-14 00:00:00.000000000 Z
14
+ date: 2015-10-19 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: device_api
@@ -58,6 +59,7 @@ files:
58
59
  - lib/device_api/android/adb.rb
59
60
  - lib/device_api/android/device.rb
60
61
  - lib/device_api/android/device/kindle.rb
62
+ - lib/device_api/android/device/samsung.rb
61
63
  - lib/device_api/android/plugins/battery.rb
62
64
  - lib/device_api/android/plugins/disk.rb
63
65
  - lib/device_api/android/plugins/memory.rb