droid_adbs 0.1.5 → 0.1.6

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: 12aa081c392cadc2fbeeece257869e5669ba60a1
4
- data.tar.gz: 67c95c2d910f880ee36876792d1d93e6890662a3
3
+ metadata.gz: 568bd488d848be1f37d46702e9b2f5c151c826ab
4
+ data.tar.gz: 1aba89a26ec167fae9a811d70349ae8c0c0df0a9
5
5
  SHA512:
6
- metadata.gz: ae7e8d24a6cf754f6987ad6ddd88b4d06e4b2cc3ef99fca9da8f4a8d07f74214dc7d376f41d8253681e84043769bd98894c6037d1d7c6af349a88a25166371e2
7
- data.tar.gz: 7aba1f9a8429ac56917632099a53a5e0541f17b02a681e7a385450d8395e535a7a1b21c3da064a9627b090326faa1f4082c867e64c63db80516b9e4a0c474c87
6
+ metadata.gz: 2a33f99f5a6e38732f4176a56f1574197385891b8167dcb9a6eb2ca5bca9fc9ade201d78f499b6847c692d1e496803c0cf86ad4d111b50ef23c147862e09589c
7
+ data.tar.gz: ea5ab0b50f306212c196ff7bc3fca9c5ac63cf1f4fbedfdc48a5810c77458e63024561e4d500c4fa7e2f6738178283294b00820c8d27f28b80727da290ee8d9b
data/README.md CHANGED
@@ -19,7 +19,15 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- TODO
22
+ Example:
23
+
24
+ ```
25
+ ::DroidAdbs.device_serial = "device cerial you would like to connect" # set device_serial
26
+ ::DroidAdbs devices # means `adb devices`
27
+ ::DroidAdbs.install(app_path) # install `app_path` to the device
28
+ ```
29
+
30
+ Please read yard documents if you would like to know more.
23
31
 
24
32
  ## Development
25
33
 
@@ -30,6 +38,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
30
38
  ## Rubygems
31
39
  - https://rubygems.org/gems/droid_adbs
32
40
 
41
+ ## Documents
42
+ You can get document by `yard` command.
43
+
33
44
  ## Contributing
34
45
 
35
46
  Bug reports and pull requests are welcome on GitHub at https://github.com/KazuCocoa/droid_adbs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -1,8 +1,12 @@
1
1
  module DroidAdbs
2
2
  module Aapt
3
3
  class << self
4
+ # @param [String] package_path
5
+ # @param [String] out_path
6
+ # @raise RuntimeError because get_manifesto can't find aapt command
7
+ # @return [fixnum]
4
8
  def get_manifesto(package_path, out_path)
5
- raise "should set path to aapt, android-sdks/build-tools/xxxx" if `which aapt`.empty?
9
+ raise RuntimeError, "should set path to aapt, android-sdks/build-tools/xxxx" if `which aapt`.empty?
6
10
  dumped_data = `aapt dump xmltree #{package_path} AndroidManifest.xml`
7
11
  File.write out_path, dumped_data
8
12
  end
@@ -6,31 +6,43 @@ module DroidAdbs
6
6
 
7
7
  # https://developer.android.com/intl/ja/training/backup/autosyncapi.html#testing
8
8
 
9
+ # @raise RuntimeError because backup available over SDK 23
10
+ # @return [String] message from adb command
9
11
  def enable_backup_logs
10
- fail "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
12
+ raise RuntimeError, "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
11
13
  `#{::DroidAdbs.shell} setprop log.tag.BackupXmlParserLogging VERBOSE`
12
14
  end
13
15
 
16
+ # @param [String] package A package name you would like to backup
17
+ # @raise RuntimeError because backup available over SDK 23
18
+ # @return [String] message from adb command
14
19
  def full_backup(package)
15
- fail "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
20
+ raise RuntimeError, "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
16
21
  `#{::DroidAdbs.shell} bmgr run`
17
22
  `#{::DroidAdbs.shell} bmgr fullbackup #{package}`
18
23
  end
19
24
 
25
+ # @param [String] package A package name you would like to backup
26
+ # @return [String] message from adb command
20
27
  def restore(package)
21
28
  fail "Backup support over SDK 23(Android 6.0, M)" unless available_backup?
22
29
  `#{::DroidAdbs.shell} bmgr restore #{package}`
23
30
  end
24
31
 
32
+ # @return [String] message from adb command
25
33
  def transports
26
34
  `#{::DroidAdbs.shell} bmgr list transports`
27
35
  end
28
36
 
37
+ # @param [String] transport
38
+ # @param [String] package A package name you would like to backup
39
+ # @return [String] message from adb command and puts message
29
40
  def clear_backup(transport, package)
30
41
  `#{::DroidAdbs.shell} bmgr wipe #{transport} #{package}`
31
42
  puts "You can also clear the backup data and associated metadata wither by turning backup off and on in Settings > Backup."
32
43
  end
33
44
 
45
+ # @return [Boolean] Return true if API Level against target device is over 23
34
46
  def available_backup?
35
47
  ::DroidAdbs::Devices.device_build_version_sdk.to_i >= 23
36
48
  end
@@ -5,32 +5,37 @@ module DroidAdbs
5
5
  class << self
6
6
  ### device infos
7
7
  # @return [String] message from adb command
8
- # e.g: docomo/SO-04E_1274-2936/SO-04E:4.2.2/10.3.1.B.0.256/_753rg:user/release-keys
8
+ # @example result of message
9
+ # docomo/SO-04E_1274-2936/SO-04E:4.2.2/10.3.1.B.0.256/_753rg:user/release-keys
9
10
  def device_fingerprint
10
11
  `#{::DroidAdbs.shell} getprop ro.build.fingerprint`.chomp
11
12
  end
12
13
 
13
14
  ### device infos
14
15
  # @return [String] message from adb command
15
- # e.g: SO-04E
16
+ # @example result of message
17
+ # SO-04E
16
18
  def device_model
17
19
  `#{::DroidAdbs.shell} getprop ro.product.model`.chomp
18
20
  end
19
21
 
20
22
  # @return [String] message from adb command
21
- # e.g: 4.2.2
23
+ # @example result of message
24
+ # 4.2.2
22
25
  def device_build_version_release
23
26
  `#{::DroidAdbs.shell} getprop ro.build.version.release`.chomp
24
27
  end
25
28
 
26
29
  # @return [String] message from adb command
27
- # e.g: 17
30
+ # @example result of message
31
+ # 17
28
32
  def device_build_version_sdk
29
33
  `#{::DroidAdbs.shell} getprop ro.build.version.sdk`.chomp
30
34
  end
31
35
 
32
36
  # @return [String] message from adb command
33
- # e.g: "en"
37
+ # @example result of message
38
+ # "en"
34
39
  def current_language
35
40
  language = `#{::DroidAdbs.shell} getprop persist.sys.language`.chomp
36
41
  return language unless language.empty?
@@ -39,7 +44,8 @@ module DroidAdbs
39
44
  end
40
45
 
41
46
  # @return [String] message from adb command
42
- # e.g.: "ja-JP"
47
+ # @example result of message
48
+ # "ja-JP"
43
49
  def current_locale
44
50
  locale = `#{::DroidAdbs.shell} getprop persist.sys.locale`.chomp
45
51
  return locale unless locale.empty?
@@ -0,0 +1,22 @@
1
+ require_relative "../../droid_adbs"
2
+
3
+ module DroidAdbs
4
+ module Grant
5
+ class << self
6
+ # @param [String] package A name of package you would like to allow permission
7
+ # @param [Object] permission Permission you would like to allow
8
+ # @return [String] message from adb command
9
+ def grant(package:, permission:)
10
+ result = `#{::DroidAdbs.shell} pm grant #{package} #{permission}`.chomp
11
+
12
+ unless result.empty?
13
+ exception = "java.lang.IllegalArgumentException:"
14
+ error_message = result.each_line.find { |line| line.include? exception }.chomp
15
+ raise RuntimeError, message unless error_message.empty?
16
+ end
17
+
18
+ result
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,29 +3,37 @@ require_relative "../../droid_adbs"
3
3
  module DroidAdbs
4
4
  module IME
5
5
  class << self
6
- # @return [String] message from adb command
6
+ # @return [String] message from adb command as pure string.
7
7
  def get_ime_with_string
8
8
  `#{::DroidAdbs.shell} ime list`.chomp
9
9
  end
10
10
 
11
- # @return [Array] Array of IME ID list such as ["com.agilebits.onepassword/.filling.FillingInputMethodService",
12
- # com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService"]
11
+ # @return [Array] Array of IME ID list
12
+ # @example
13
+ # [
14
+ # "com.agilebits.onepassword/.filling.FillingInputMethodService",
15
+ # "com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService"
16
+ # ]
13
17
  def get_ime_list
14
18
  string = get_ime_with_string
15
19
  parse_ime_list(string)
16
20
  end
17
21
 
18
22
  # @param [String] ime_id ID provided by IME such as "com.google.android.inputmethod.japanese/.MozcService"
19
- # @return [String] message from adb command
20
- # if it succeeded to set IME, then it returns "Input method com.google.android.inputmethod.japanese/.MozcService selected"
21
- # if it failed to set IME because of no ID, then it returns "Error: Unknown id: ime_id"
23
+ # @return [String] message from adb command.
24
+ # If it succeeded to set IME, then it returns "Input method com.google.android.inputmethod.japanese/.MozcService selected"
25
+ # If it failed to set IME because of no ID, then it returns "Error: Unknown id: ime_id"
22
26
  def set_ime(ime_id)
23
27
  `#{::DroidAdbs.shell} ime set #{ime_id}`.chomp
24
28
  end
25
29
 
26
30
  # @param [String] ime_lists
27
- # @return [Array] Array of IME ID list such as ["com.agilebits.onepassword/.filling.FillingInputMethodService",
28
- # com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService"]
31
+ # @return [Array] Array of IME ID list
32
+ # @example
33
+ # [
34
+ # "com.agilebits.onepassword/.filling.FillingInputMethodService",
35
+ # "com.google.android.googlequicksearchbox/com.google.android.voicesearch.ime.VoiceInputMethodService"
36
+ # ]
29
37
  def parse_ime_list(ime_lists)
30
38
  ime_lists.each_line.map { |line| line.chomp.scan(/\A\S+:\z/).first }.compact.map(&:chop)
31
39
  end
@@ -1,3 +1,3 @@
1
1
  module DroidAdbs
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/droid_adbs.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "droid_adbs/commons/devices"
4
4
  require_relative "droid_adbs/commons/backup"
5
5
  require_relative "droid_adbs/commons/ime"
6
6
  require_relative "droid_adbs/commons/wm"
7
+ require_relative "droid_adbs/commons/grant"
7
8
  require_relative "droid_adbs/aapt"
8
9
 
9
10
  module DroidAdbs
@@ -30,55 +31,58 @@ module DroidAdbs
30
31
  `#{adb} devices`.scan(/^.*\t/).map(&:strip)
31
32
  end
32
33
 
33
- # @param app [String] application path
34
+ # @param [String] app Application path
34
35
  # @return [String] message from adb command
35
36
  def install(app)
36
37
  result = `#{adb_serial} install -r #{app}`
37
- fail "invalid APK" if result.include?("Invalid APK file:")
38
- fail "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
38
+ raise RuntimeError, result if result.include?("Error:")
39
+ raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
40
+ raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
39
41
  result
40
42
  end
41
43
 
42
- # @param app [String] application path
44
+ # @param [String] app Application path
43
45
  # @return [String] message from adb command
44
46
  def install_with_grant(app)
45
47
  result = `#{adb_serial} install -r -g #{app}`
46
- fail "invalid APK" if result.include?("Invalid APK file:")
47
- fail "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
48
+ raise RuntimeError, result if result.include?("Error:")
49
+ raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
50
+ raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
48
51
  result
49
52
  end
50
53
 
51
- # @param app [String] application path
54
+ # @param [String] app Application path
52
55
  # @return [String] message from adb command
53
56
  def install_with(app, option = "")
54
57
  result = `#{adb_serial} install #{option} #{app}`
55
- fail "invalid APK" if result.include?("Invalid APK file:")
56
- fail "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
58
+ raise RuntimeError, result if result.include?("Error:")
59
+ raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:")
60
+ raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE")
57
61
  result
58
62
  end
59
63
 
60
64
 
61
- # @param package [String] package name you would like to uninstall
65
+ # @param [String] package A package name you would like to uninstall
62
66
  # @return [String] message from adb command
63
67
  def uninstall(package)
64
68
  `#{adb_serial} uninstall #{package}`
65
69
  end
66
70
 
67
- # @param package [String] package name you would like to uninstall similar ones
71
+ # @param [String] package A package name you would like to uninstall similar ones
68
72
  # @return [String] message from adb command
69
73
  def uninstall_similar(package)
70
74
  installed_packages = installed_similar(package)
71
75
  installed_packages.each { |pack| `#{adb_serial} uninstall #{pack}` }
72
76
  end
73
77
 
74
- # @param package [String] package name you would like to delete data in device local
78
+ # @param [String] package A package name you would like to delete data in device local
75
79
  # @return [String] message from adb command
76
80
  def delete_data(package)
77
81
  result = `#{shell} pm clear #{package}`.strip
78
82
  puts "failed to delete data" unless result == "Success"
79
83
  end
80
84
 
81
- # @param package [String] package name you would like to check installed or not
85
+ # @param [String] package A package name you would like to check installed or not
82
86
  # @return [Bool] If the package installed, return true. Else return false
83
87
  def installed?(package)
84
88
  result = `#{shell} pm list packages -e #{package}`.strip
@@ -86,20 +90,20 @@ module DroidAdbs
86
90
  false
87
91
  end
88
92
 
89
- # @param package [String] package name you would like to collect similar package
93
+ # @param [String] package A package name you would like to collect similar package
90
94
  # @return [Array] all package names
91
95
  def installed_similar(package)
92
96
  result = `#{shell} pm list packages -e #{package}`.strip
93
97
  result.each_line.map { |pack| pack.strip.sub("package:", "") }
94
98
  end
95
99
 
96
- # @param activity [String] activity name you would like to launch
100
+ # @param [String] activity An activity name you would like to launch
97
101
  # @return [String] message from adb command
98
102
  def start(activity)
99
103
  `#{shell} am start -n #{activity}`
100
104
  end
101
105
 
102
- # @param account_type [String] accountType of Android OS
106
+ # @param [String] account_type accountType of Android OS
103
107
  # @return [String] message from adb command
104
108
  def launch_login_activity(account_type)
105
109
  if ::DroidAdbs::Devices.device_build_version_sdk.to_i >= 21
@@ -109,14 +113,14 @@ module DroidAdbs
109
113
  end
110
114
  end
111
115
 
112
- # @param activity [String] activity name you would like to stop
116
+ # @param [String] package A package name you would like to stop
113
117
  # @return [String] message from adb command
114
118
  def force_stop(package)
115
119
  `#{shell} am force-stop #{package}`
116
120
  end
117
121
 
118
- # @param broadcats_item [String] Target item for broadcast
119
- # @param broadcast_extra [String] putExtra to send broadcast.
122
+ # @param [String] broadcats_item Target item for broadcast
123
+ # @param [String] broadcast_extra putExtra to send broadcast.
120
124
  # @return [String] message from adb command
121
125
  def send_broadcast(broadcats_item, broadcast_extra = "")
122
126
  `#{shell} am broadcast -a #{broadcats_item} #{broadcast_extra}`
@@ -134,14 +138,14 @@ module DroidAdbs
134
138
  `#{shell} dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"`
135
139
  end
136
140
 
137
- # @param [String] referrer to broadcast
141
+ # @param referrer [String] To broadcast
138
142
  # @return [String] message from adb command
139
143
  def install_referrer_broadcast(referrer)
140
144
  `#{shell} broadcast window -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{referrer}`
141
145
  end
142
146
 
143
147
  # send referrer for TVs
144
- # @param [String] referrer to broadcast
148
+ # @param [String] ref to broadcast
145
149
  # @return [String] message from adb command
146
150
  def broad_install_referrer(ref)
147
151
  `#{shell} am broadcast -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{ref}`
@@ -154,10 +158,13 @@ module DroidAdbs
154
158
  `#{shell} input keyevent 82`
155
159
  end
156
160
 
161
+ # @param [String] text Pin code to unlock
162
+ # @return [String] message from adb command
157
163
  def unlock_with_pin(text)
158
164
  `#{shell} input text #{text} && #{shell} input keyevent 66`
159
165
  end
160
166
 
167
+ # @return [String] message from adb command
161
168
  def screen_on_or_off
162
169
  `#{shell} input keyevent 26`
163
170
  end
@@ -174,4 +181,4 @@ module DroidAdbs
174
181
  "-s #{device_serial}"
175
182
  end
176
183
  end
177
- end
184
+ end # 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.5
4
+ version: 0.1.6
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-08-13 00:00:00.000000000 Z
11
+ date: 2016-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - lib/droid_adbs/aapt.rb
73
73
  - lib/droid_adbs/commons/backup.rb
74
74
  - lib/droid_adbs/commons/devices.rb
75
+ - lib/droid_adbs/commons/grant.rb
75
76
  - lib/droid_adbs/commons/ime.rb
76
77
  - lib/droid_adbs/commons/settings.rb
77
78
  - lib/droid_adbs/commons/wm.rb