droid_adbs 0.1.7 → 0.1.8

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: ac7f6e3a9711e3e9ec664e93509a280403f82d9c
4
- data.tar.gz: 699b44b24c108e2e2d6adbf14d07c97ce9149895
3
+ metadata.gz: cc1795d0ee56ebdaef3ea8102f5a2e259a7dbf64
4
+ data.tar.gz: e4387cfdd2c98f1b7610a98610a23e02a5aafc00
5
5
  SHA512:
6
- metadata.gz: ca83e3c8988a3774cfe799525e5e996c7ac4b080faef2dc7b063a2505c3027805a1fcff040f9fc6f8cf19fb87400a4e48486079c68d5e6c7766a625d49e450f8
7
- data.tar.gz: 35caa18e2a057e5a1aeff0197cd8e8a1643ffe7cd124d35ccebdbfbb8dbe02d34e744bd095e0a0705c1f488bf2bc7bf08379445fbc235c8a28c8313d1e169baa
6
+ metadata.gz: 882da2e19245b75b6316f39e9dce5d4e842598ae8218dfbe0e301a3ce758a94999cb6295869e592356c445d43e97b5a22864e9eb3042a0d051447b664ad2481a
7
+ data.tar.gz: cf42637973fe07c88482c89dc250fd373183372715d81a7b5266110af17433b503c7adce25b1aa62f73edf5f526cd2f13b025be04a7d44e908147a65851d1de2
@@ -28,7 +28,7 @@ module DroidAdbs
28
28
 
29
29
  # @return [String] Get results of adb devices command
30
30
  def devices
31
- `#{adb} devices`
31
+ `#{adb} devices`.strip
32
32
  end
33
33
 
34
34
  # @return [Array] array of serial number to specify adb command
@@ -39,7 +39,7 @@ module DroidAdbs
39
39
  # @param [String] app Application path
40
40
  # @return [String] message from adb command
41
41
  def install(app)
42
- result = `#{adb_serial} install -r #{app}`
42
+ result = `#{adb_serial} install -r #{app}`.strip
43
43
  raise RuntimeError, result if result.include?("Error:")
44
44
  raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
45
45
  raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
@@ -49,7 +49,7 @@ module DroidAdbs
49
49
  # @param [String] app Application path
50
50
  # @return [String] message from adb command
51
51
  def install_with_grant(app)
52
- result = `#{adb_serial} install -gr #{app}`
52
+ result = `#{adb_serial} install -gr #{app}`.strip
53
53
  raise RuntimeError, result if result.include?("Error:")
54
54
  raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
55
55
  raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
@@ -59,7 +59,7 @@ module DroidAdbs
59
59
  # @param [String] app Application path
60
60
  # @return [String] message from adb command
61
61
  def install_with(app, option = "")
62
- result = `#{adb_serial} install #{option} #{app}`
62
+ result = `#{adb_serial} install #{option} #{app}`.strip
63
63
  raise RuntimeError, result if result.include?("Error:")
64
64
  raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
65
65
  raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
@@ -70,14 +70,14 @@ module DroidAdbs
70
70
  # @param [String] package A package name you would like to uninstall
71
71
  # @return [String] message from adb command
72
72
  def uninstall(package)
73
- `#{adb_serial} uninstall #{package}`
73
+ `#{adb_serial} uninstall #{package}`.strip
74
74
  end
75
75
 
76
76
  # @param [String] package A package name you would like to uninstall similar ones
77
- # @return [String] message from adb command
77
+ # @return [Array] messages from adb command
78
78
  def uninstall_similar(package)
79
79
  installed_packages = installed_similar(package)
80
- installed_packages.each { |pack| `#{adb_serial} uninstall #{pack}` }
80
+ installed_packages.map { |pack| `#{adb_serial} uninstall #{pack}`.strip }
81
81
  end
82
82
 
83
83
  # @param [String] package A package name you would like to delete data in device local
@@ -85,34 +85,36 @@ module DroidAdbs
85
85
  def delete_data(package)
86
86
  result = `#{shell} pm clear #{package}`.strip
87
87
  puts "failed to delete data" unless result == "Success"
88
+ result
88
89
  end
89
90
 
90
91
  # @param [String] package A package name you would like to check installed or not
91
92
  # @return [Bool] If the package installed, return true. Else return false
92
93
  def installed?(package)
93
- result = `#{shell} pm list packages -e #{package}`.strip
94
- return true if result == "package:#{package}"
94
+ packages = `#{shell} pm list packages -e #{package}`.strip
95
+ result = packages.each_line.find { |p| p == "package:#{package}" }
96
+ return true if result
95
97
  false
96
98
  end
97
99
 
98
100
  # @param [String] package A package name you would like to collect similar package
99
101
  # @return [Array] all package names
100
102
  def installed_similar(package)
101
- result = `#{shell} pm list packages -e #{package}`.strip
102
- result.each_line.map { |pack| pack.strip.sub("package:", "") }
103
+ packages = `#{shell} pm list packages -e #{package}`.strip
104
+ packages.each_line.map { |pack| pack.strip.sub("package:", "") }
103
105
  end
104
106
 
105
107
  # @param [String] activity An activity name you would like to launch
106
108
  # @return [String] message from adb command
107
109
  def start(activity)
108
- `#{shell} am start -n #{activity}`
110
+ `#{shell} am start -n #{activity}`.strip
109
111
  end
110
112
 
111
113
  # @param [String] account_type accountType of Android OS
112
114
  # @return [String] message from adb command
113
115
  def launch_login_activity(account_type)
114
116
  if ::DroidAdbs::Devices.device_build_version_sdk.to_i >= 21
115
- `#{shell} am start -a android.settings.ADD_ACCOUNT_SETTINGS --esa authorities #{account_type}`
117
+ `#{shell} am start -a android.settings.ADD_ACCOUNT_SETTINGS --esa authorities #{account_type}`.strip
116
118
  else
117
119
  puts "Can't launch LoginActivity.java because version of sdk in the target device is lower than 21."
118
120
  end
@@ -121,14 +123,14 @@ module DroidAdbs
121
123
  # @param [String] package A package name you would like to stop
122
124
  # @return [String] message from adb command
123
125
  def force_stop(package)
124
- `#{shell} am force-stop #{package}`
126
+ `#{shell} am force-stop #{package}`.strip
125
127
  end
126
128
 
127
129
  # @param [String] broadcats_item Target item for broadcast
128
130
  # @param [String] broadcast_extra putExtra to send broadcast.
129
131
  # @return [String] message from adb command
130
132
  def send_broadcast(broadcats_item, broadcast_extra = "")
131
- `#{shell} am broadcast -a #{broadcats_item} #{broadcast_extra}`
133
+ `#{shell} am broadcast -a #{broadcats_item} #{broadcast_extra}`.strip
132
134
  end
133
135
 
134
136
  ## resources
@@ -140,38 +142,38 @@ module DroidAdbs
140
142
  ### Activity
141
143
  # @return [String] message from adb command regarding current activities
142
144
  def current_activity
143
- `#{shell} dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"`
145
+ `#{shell} dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"`.strip
144
146
  end
145
147
 
146
148
  # @param referrer [String] To broadcast
147
149
  # @return [String] message from adb command
148
150
  def install_referrer_broadcast(referrer)
149
- `#{shell} broadcast window -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{referrer}`
151
+ `#{shell} broadcast window -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{referrer}`.strip
150
152
  end
151
153
 
152
154
  # send referrer for TVs
153
155
  # @param [String] ref to broadcast
154
156
  # @return [String] message from adb command
155
157
  def broad_install_referrer(ref)
156
- `#{shell} am broadcast -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{ref}`
158
+ `#{shell} am broadcast -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{ref}`.strip
157
159
  end
158
160
 
159
161
  # Emulator should be unlocked after launch emulator with -wipe-data option
160
162
  # Should unlock screen if current focus is like `mCurrentFocus=Window{2e85df18 u0 StatusBar}` .
161
163
  # @return [String] message from adb command
162
164
  def unlock_without_pin
163
- `#{shell} input keyevent 82`
165
+ `#{shell} input keyevent 82`.strip
164
166
  end
165
167
 
166
168
  # @param [String] text Pin code to unlock
167
169
  # @return [String] message from adb command
168
170
  def unlock_with_pin(text)
169
- `#{shell} input text #{text} && #{shell} input keyevent 66`
171
+ `#{shell} input text #{text} && #{shell} input keyevent 66`.strip
170
172
  end
171
173
 
172
174
  # @return [String] message from adb command
173
175
  def screen_on_or_off
174
- `#{shell} input keyevent 26`
176
+ `#{shell} input keyevent 26`.strip
175
177
  end
176
178
 
177
179
  private
@@ -8,7 +8,7 @@ module DroidAdbs
8
8
  # @return [String] message from adb command
9
9
  def enable_backup_logs
10
10
  raise RuntimeError, "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
11
- `#{::DroidAdbs.shell} setprop log.tag.BackupXmlParserLogging VERBOSE`
11
+ `#{::DroidAdbs.shell} setprop log.tag.BackupXmlParserLogging VERBOSE`.strip
12
12
  end
13
13
 
14
14
  # @param [String] package A package name you would like to backup
@@ -17,27 +17,28 @@ module DroidAdbs
17
17
  def full_backup(package)
18
18
  raise RuntimeError, "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
19
19
  `#{::DroidAdbs.shell} bmgr run`
20
- `#{::DroidAdbs.shell} bmgr fullbackup #{package}`
20
+ `#{::DroidAdbs.shell} bmgr fullbackup #{package}`.strip
21
21
  end
22
22
 
23
23
  # @param [String] package A package name you would like to backup
24
24
  # @return [String] message from adb command
25
25
  def restore(package)
26
26
  fail "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
27
- `#{::DroidAdbs.shell} bmgr restore #{package}`
27
+ `#{::DroidAdbs.shell} bmgr restore #{package}`.strip
28
28
  end
29
29
 
30
30
  # @return [String] message from adb command
31
31
  def transports
32
- `#{::DroidAdbs.shell} bmgr list transports`
32
+ `#{::DroidAdbs.shell} bmgr list transports`.strip
33
33
  end
34
34
 
35
35
  # @param [String] transport
36
36
  # @param [String] package A package name you would like to backup
37
37
  # @return [String] message from adb command and puts message
38
38
  def clear_backup(transport, package)
39
- `#{::DroidAdbs.shell} bmgr wipe #{transport} #{package}`
39
+ result = `#{::DroidAdbs.shell} bmgr wipe #{transport} #{package}`.strip
40
40
  puts "You can also clear the backup data and associated metadata wither by turning backup off and on in Settings > Backup."
41
+ result
41
42
  end
42
43
 
43
44
  # @return [Boolean] Return true if API Level against target device is over 23
@@ -6,7 +6,7 @@ module DroidAdbs
6
6
  # @example result of message
7
7
  # docomo/SO-04E_1274-2936/SO-04E:4.2.2/10.3.1.B.0.256/_753rg:user/release-keys
8
8
  def device_fingerprint
9
- `#{::DroidAdbs.shell} getprop ro.build.fingerprint`.chomp
9
+ `#{::DroidAdbs.shell} getprop ro.build.fingerprint`.strip
10
10
  end
11
11
 
12
12
  ### device infos
@@ -14,41 +14,41 @@ module DroidAdbs
14
14
  # @example result of message
15
15
  # SO-04E
16
16
  def device_model
17
- `#{::DroidAdbs.shell} getprop ro.product.model`.chomp
17
+ `#{::DroidAdbs.shell} getprop ro.product.model`.strip
18
18
  end
19
19
 
20
20
  # @return [String] message from adb command
21
21
  # @example result of message
22
22
  # 4.2.2
23
23
  def device_build_version_release
24
- `#{::DroidAdbs.shell} getprop ro.build.version.release`.chomp
24
+ `#{::DroidAdbs.shell} getprop ro.build.version.release`.strip
25
25
  end
26
26
 
27
27
  # @return [String] message from adb command
28
28
  # @example result of message
29
29
  # 17
30
30
  def device_build_version_sdk
31
- `#{::DroidAdbs.shell} getprop ro.build.version.sdk`.chomp
31
+ `#{::DroidAdbs.shell} getprop ro.build.version.sdk`.strip
32
32
  end
33
33
 
34
34
  # @return [String] message from adb command
35
35
  # @example result of message
36
36
  # "en"
37
37
  def current_language
38
- language = `#{::DroidAdbs.shell} getprop persist.sys.language`.chomp
38
+ language = `#{::DroidAdbs.shell} getprop persist.sys.language`.strip
39
39
  return language unless language.empty?
40
40
 
41
- `#{::DroidAdbs.shell} getprop ro.product.locale.language`.chomp
41
+ `#{::DroidAdbs.shell} getprop ro.product.locale.language`.strip
42
42
  end
43
43
 
44
44
  # @return [String] message from adb command
45
45
  # @example result of message
46
46
  # "ja-JP"
47
47
  def current_locale
48
- locale = `#{::DroidAdbs.shell} getprop persist.sys.locale`.chomp
48
+ locale = `#{::DroidAdbs.shell} getprop persist.sys.locale`.strip
49
49
  return locale unless locale.empty?
50
50
 
51
- `#{::DroidAdbs.shell} getprop ro.product.locale`.chomp
51
+ `#{::DroidAdbs.shell} getprop ro.product.locale`.strip
52
52
  end
53
53
  end
54
54
  end
@@ -5,7 +5,7 @@ module DroidAdbs
5
5
  # @param [Object] permission Permission you would like to allow
6
6
  # @return [String] message from adb command
7
7
  def grant(package:, permission:)
8
- result = `#{::DroidAdbs.shell} pm grant #{package} #{permission}`.chomp
8
+ result = `#{::DroidAdbs.shell} pm grant #{package} #{permission}`.strip
9
9
 
10
10
  unless result.empty?
11
11
  exception = "java.lang.IllegalArgumentException:"
@@ -3,7 +3,7 @@ module DroidAdbs
3
3
  class << self
4
4
  # @return [String] message from adb command as pure string.
5
5
  def get_ime_with_string
6
- `#{::DroidAdbs.shell} ime list`.chomp
6
+ `#{::DroidAdbs.shell} ime list`.strip
7
7
  end
8
8
 
9
9
  # @return [Array] Array of IME ID list
@@ -22,7 +22,7 @@ module DroidAdbs
22
22
  # If it succeeded to set IME, then it returns "Input method com.google.android.inputmethod.japanese/.MozcService selected"
23
23
  # If it failed to set IME because of no ID, then it returns "Error: Unknown id: ime_id"
24
24
  def set_ime(ime_id)
25
- `#{::DroidAdbs.shell} ime set #{ime_id}`.chomp
25
+ `#{::DroidAdbs.shell} ime set #{ime_id}`.strip
26
26
  end
27
27
 
28
28
  # @param [String] ime_lists
@@ -3,63 +3,67 @@ module DroidAdbs
3
3
  class << self
4
4
  # @return [String] message from adb command
5
5
  def disable_always_finish_activities
6
- `#{::DroidAdbs.shell} settings put global always_finish_activities 0`
6
+ `#{::DroidAdbs.shell} settings put global always_finish_activities 0`.strip
7
7
  end
8
8
 
9
9
  # @return [String] message from adb command
10
10
  def enable_always_finish_activities
11
- `#{::DroidAdbs.shell} settings put global always_finish_activities 1`
11
+ `#{::DroidAdbs.shell} settings put global always_finish_activities 1`.strip
12
12
  end
13
13
 
14
14
  ### Network mode
15
15
  # @return [String] message from adb command
16
16
  def turn_airplain_mode_on
17
- `#{::DroidAdbs.shell} settings put global airplane_mode_on 1`
18
- `#{::DroidAdbs.shell} am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true`
17
+ result1 = `#{::DroidAdbs.shell} settings put global airplane_mode_on 1`
18
+ result2 = `#{::DroidAdbs.shell} am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true`.strip
19
+ result1.concat result2
19
20
  end
20
21
 
21
22
  # @return [String] message from adb command
22
23
  def turn_airplain_mode_off
23
- `#{::DroidAdbs.shell} settings put global airplane_mode_on 0`
24
- `#{::DroidAdbs.shell} am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false`
24
+ result1 = `#{::DroidAdbs.shell} settings put global airplane_mode_on 0`
25
+ result2 = `#{::DroidAdbs.shell} am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false`.strip
26
+ result1.concat result2
25
27
  end
26
28
 
27
29
  # @return [String] message from adb command
28
30
  def turn_wifi_on
29
- `#{::DroidAdbs.shell} settings put global wifi_on 1`
30
- `#{::DroidAdbs.shell} am broadcast -a android.intent.action.WIFI_ON --ez state false`
31
+ result1 = `#{::DroidAdbs.shell} settings put global wifi_on 1`
32
+ result2 = `#{::DroidAdbs.shell} am broadcast -a android.intent.action.WIFI_ON --ez state false`.strip
33
+ result1.concat result2
31
34
  end
32
35
 
33
36
  # @return [String] message from adb command
34
37
  def turn_wifi_off
35
- `#{::DroidAdbs.shell} settings put global wifi_on 0`
36
- `#{::DroidAdbs.shell} am broadcast -a android.intent.action.WIFI_ON --ez state false`
38
+ result1 = `#{::DroidAdbs.shell} settings put global wifi_on 0`
39
+ result2 = `#{::DroidAdbs.shell} am broadcast -a android.intent.action.WIFI_ON --ez state false`.strip
40
+ result1.concat result2
37
41
  end
38
42
 
39
43
  # @return [String] message from adb command
40
44
  def turn_cpu_monitoring_on
41
- `#{::DroidAdbs.shell} settings put global show_processes 1`
45
+ `#{::DroidAdbs.shell} settings put global show_processes 1`.strip
42
46
  end
43
47
 
44
48
  # @return [String] message from adb command
45
49
  def turn_cpu_monitoring_off
46
- `#{::DroidAdbs.shell} settings put global show_processes 0`
50
+ `#{::DroidAdbs.shell} settings put global show_processes 0`.strip
47
51
  end
48
52
 
49
53
  # @return [String] message from adb command
50
54
  def turn_auto_time_on
51
- `#{::DroidAdbs.shell} settings put global auto_time 1`
55
+ `#{::DroidAdbs.shell} settings put global auto_time 1`.strip
52
56
  end
53
57
 
54
58
  # @return [String] message from adb command
55
59
  def turn_auto_time_off
56
- `#{::DroidAdbs.shell} settings put global auto_time 0`
60
+ `#{::DroidAdbs.shell} settings put global auto_time 0`.strip
57
61
  end
58
62
 
59
63
  # @return [String] message from adb command
60
64
  def set_date_to(yyyymmdd, hhmmss)
61
65
  turn_auto_time_off
62
- `#{::DroidAdbs.shell} date -s #{yyyymmdd}.#{hhmmss}`
66
+ `#{::DroidAdbs.shell} date -s #{yyyymmdd}.#{hhmmss}`.strip
63
67
  end
64
68
 
65
69
  # animation settings
@@ -3,14 +3,14 @@ module DroidAdbs
3
3
  class << self
4
4
  # @return [Integer] density. If this method fail to get density, then return 0.
5
5
  def get_density
6
- result = `#{::DroidAdbs.shell} wm density`.chomp
6
+ result = `#{::DroidAdbs.shell} wm density`.strip
7
7
  return 0 unless result.match(/\APhysical density:.*/)
8
8
  result.split(/\s/).last.to_i
9
9
  end
10
10
 
11
11
  # @return [String] message from adb commands
12
12
  def reset_density
13
- `#{::DroidAdbs.shell} wm density reset`.chomp
13
+ `#{::DroidAdbs.shell} wm density reset`.strip
14
14
  end
15
15
 
16
16
  # Don't forget to call `reset_density` after change density via adb
@@ -28,7 +28,7 @@ module DroidAdbs
28
28
  else # include :normal
29
29
  base_density
30
30
  end
31
- `#{::DroidAdbs.shell} wm density #{density}`.chomp
31
+ `#{::DroidAdbs.shell} wm density #{density}`.strip
32
32
  end
33
33
 
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module DroidAdbs
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,4 +102,3 @@ signing_key:
102
102
  specification_version: 4
103
103
  summary: adb command wrapper
104
104
  test_files: []
105
- has_rdoc: