droid_adbs 0.1.8 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc1795d0ee56ebdaef3ea8102f5a2e259a7dbf64
4
- data.tar.gz: e4387cfdd2c98f1b7610a98610a23e02a5aafc00
3
+ metadata.gz: de9ff6761785392fee2f3046625447d66726ae35
4
+ data.tar.gz: 27ef3ca245cbeb9fa4877f87a369576b3edb6640
5
5
  SHA512:
6
- metadata.gz: 882da2e19245b75b6316f39e9dce5d4e842598ae8218dfbe0e301a3ce758a94999cb6295869e592356c445d43e97b5a22864e9eb3042a0d051447b664ad2481a
7
- data.tar.gz: cf42637973fe07c88482c89dc250fd373183372715d81a7b5266110af17433b503c7adce25b1aa62f73edf5f526cd2f13b025be04a7d44e908147a65851d1de2
6
+ metadata.gz: ff1d9f0edf9bfc1fb9de16ba6874309158da776536d48e949b50fc5d2adc22b306a8f748c9845607a79a74003ece0aebacefa4aaf92b529883e6ece854fbb49b
7
+ data.tar.gz: f356565df2957019e52a6c9f577d35fa693f4cd4a97ccda96b8845a4b8209b5b3692b43402a55436153c5e7d4e4eb87d3b35877756d18f98f7deb6e6ca9e0a16
@@ -0,0 +1,88 @@
1
+ module DroidAdbs
2
+ module Logcat
3
+ class << self
4
+ # @return [String] Empty string if the command is succeeded
5
+ def clear
6
+ result = `#{::DroidAdbs.shell} logcat -c`
7
+ puts result unless result.empty?
8
+ result
9
+ end
10
+
11
+ # @param [Symbol] log_level Log level. Default is warning(:w).
12
+ # @return [String] Message from adb command
13
+ def get(log_level: :w)
14
+ level = validate_log_level log_level
15
+ `#{::DroidAdbs.shell} logcat -d *:#{level}`.strip
16
+ end
17
+
18
+ # @param [String] file_path File path to save logcat.
19
+ # @param [Symbol] log_level Log level. Default is warning(:w).
20
+ # @return [String] Message from adb command
21
+ def save_logs_in(file_path:, log_level: :w)
22
+ level = validate_log_level log_level
23
+ `#{::DroidAdbs.shell} logcat -d *:#{level} -f #{file_path}`.strip
24
+ end
25
+
26
+ # @return [String] Message from adb command
27
+ def get_sigsegv
28
+ `#{::DroidAdbs.shell} logcat -d *:W | grep "SIGSEGV"`.strip
29
+ end
30
+
31
+ # @param [String] logcat
32
+ # @return [String|nil] Return a fatal exception
33
+ def filter_fatal_exception(logcat)
34
+ do_filter_fatal_exceptions(logcat).first
35
+ end
36
+
37
+ # @param [String] logcat
38
+ # @return [Array] Return a fatal exception
39
+ def filter_fatal_exceptions(logcat)
40
+ do_filter_fatal_exceptions(logcat)
41
+ end
42
+
43
+ private
44
+
45
+ def do_filter_fatal_exceptions(logcat)
46
+ has_exception, end_exception, split_line = false, false, []
47
+ tmp_memo = {last_exception: "", exceptions: []}
48
+
49
+ logcat.each_line.reduce(tmp_memo) { |memo, line|
50
+ if !has_exception
51
+ has_exception = has_fatal_exception?(line)
52
+ if has_exception
53
+ memo[:last_exception].concat(line)
54
+ split_line = line.split(/\s/)
55
+ end
56
+ elsif !end_exception
57
+ compare_lines(line.split(/\s/), split_line) ? memo[:last_exception].concat(line) : end_exception = true
58
+ end
59
+
60
+ # store last exception and clear local variables.
61
+ if end_exception
62
+ memo[:exceptions].push memo[:last_exception] if !memo[:last_exception].nil? && !memo[:last_exception].empty?
63
+ has_exception, end_exception, memo[:last_exception], split_line = false, false, "", []
64
+ end
65
+
66
+ memo
67
+ }[:exceptions]
68
+ end
69
+
70
+ def validate_log_level(log_level)
71
+ unless %I(v V d D i I w W e E f F s S).include? log_level
72
+ raise ArgumentError, "log_level requires one of #{%I(v V d D i I w W e E f F s S)}"
73
+ end
74
+
75
+ log_level.to_s.upcase
76
+ end
77
+
78
+ def has_fatal_exception?(line)
79
+ result = /.+ FATAL EXCEPTION:.+/.match(line)
80
+ result.nil? ? false : true
81
+ end
82
+
83
+ def compare_lines(line1, line2)
84
+ line1[0..3] == line2[0..3]
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module DroidAdbs
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/droid_adbs.rb CHANGED
@@ -4,7 +4,8 @@ require "droid_adbs/commons/devices"
4
4
  require "droid_adbs/commons/backup"
5
5
  require "droid_adbs/commons/ime"
6
6
  require "droid_adbs/commons/wm"
7
- require "droid_adbs/commons/grant"
7
+ require "droid_adbs/commons/grant"
8
+ require "droid_adbs/commons/logcat"
8
9
  require "droid_adbs/aapt"
9
10
 
10
11
  module DroidAdbs
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: droid_adbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-08 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - lib/droid_adbs/commons/devices.rb
75
75
  - lib/droid_adbs/commons/grant.rb
76
76
  - lib/droid_adbs/commons/ime.rb
77
+ - lib/droid_adbs/commons/logcat.rb
77
78
  - lib/droid_adbs/commons/settings.rb
78
79
  - lib/droid_adbs/commons/wm.rb
79
80
  - lib/droid_adbs/version.rb