Module: DroidAdbs
- Defined in:
- lib/droid_adbs.rb,
lib/droid_adbs/aapt.rb,
lib/droid_adbs/version.rb,
lib/droid_adbs/commons/wm.rb,
lib/droid_adbs/apkanalyzer.rb,
lib/droid_adbs/commons/ime.rb,
lib/droid_adbs/commons/doze.rb,
lib/droid_adbs/commons/grant.rb,
lib/droid_adbs/commons/backup.rb,
lib/droid_adbs/commons/logcat.rb,
lib/droid_adbs/commons/record.rb,
lib/droid_adbs/commons/devices.rb,
lib/droid_adbs/commons/dumpsys.rb,
lib/droid_adbs/commons/settings.rb
Defined Under Namespace
Modules: Aapt, BackupUtils, Devices, Doze, Dumpsys, Grant, IME, Logcat, ScreenRecord, Settings, WM Classes: Apkanalyzer
Constant Summary collapse
- VERSION =
'0.4.1'
Class Attribute Summary collapse
-
.device_serial ⇒ Object
Returns the value of attribute device_serial.
Class Method Summary collapse
-
.adb_serial ⇒ String
Adb command with serial.
-
.broad_install_referrer(ref) ⇒ String
send referrer for TVs.
-
.connect(host = 'localhost', port = 5555) ⇒ String
Adb command with serial.
-
.current_activity ⇒ String
Activity.
-
.delete_data(package) ⇒ String
Message from adb command.
-
.device_screen ⇒ String
Message from adb command.
-
.device_serials ⇒ Array
Array of serial number to specify adb command.
-
.devices ⇒ String
Get results of adb devices command.
-
.dump_all_cpuinfos ⇒ String
resources.
-
.force_stop(package) ⇒ String
Message from adb command.
-
.install(app) ⇒ String
Message from adb command.
-
.install_referrer_broadcast(referrer) ⇒ String
Message from adb command.
-
.install_with(app, option = "") ⇒ String
Message from adb command.
-
.install_with_grant(app) ⇒ String
Message from adb command.
-
.installed?(package) ⇒ Bool
If the package installed, return true.
-
.installed_similar(package) ⇒ Array
All package names.
-
.launch_login_activity(account_type) ⇒ String
Message from adb command.
-
.push ⇒ String
Adb push command.
-
.screen_on_or_off ⇒ String
Message from adb command.
-
.send_broadcast(broadcats_item, broadcast_extra = "") ⇒ String
Message from adb command.
-
.set_tcpip(ip) ⇒ String
Adb command with serial.
-
.shell ⇒ String
Adb shell command.
-
.start(activity) ⇒ String
Message from adb command.
-
.uninstall(package) ⇒ String
Message from adb command.
-
.uninstall_similar(package) ⇒ Array
Messages from adb command.
-
.unlock_with_pin(text) ⇒ String
Message from adb command.
-
.unlock_without_pin ⇒ String
Emulator should be unlocked after launch emulator with -wipe-data option Should unlock screen if current focus is like ‘mCurrentFocus=Windowu0 StatusBar` .
Class Attribute Details
.device_serial ⇒ Object
Returns the value of attribute device_serial.
16 17 18 |
# File 'lib/droid_adbs.rb', line 16 def device_serial @device_serial end |
Class Method Details
.adb_serial ⇒ String
Returns adb command with serial.
35 36 37 |
# File 'lib/droid_adbs.rb', line 35 def adb_serial "#{adb} #{device_serial_option}" end |
.broad_install_referrer(ref) ⇒ String
send referrer for TVs
177 178 179 |
# File 'lib/droid_adbs.rb', line 177 def broad_install_referrer(ref) `#{shell} am broadcast -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{ref}`.strip end |
.connect(host = 'localhost', port = 5555) ⇒ String
Returns adb command with serial.
27 28 29 30 31 32 |
# File 'lib/droid_adbs.rb', line 27 def connect(host = 'localhost', port = 5555) connect_to = %(#{host}:#{port}) self.device_serial = connect_to `#{adb_serial} connect #{connect_to}`.strip end |
.current_activity ⇒ String
Activity
164 165 166 |
# File 'lib/droid_adbs.rb', line 164 def current_activity `#{shell} dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"`.strip end |
.delete_data(package) ⇒ String
Returns message from adb command.
105 106 107 108 109 |
# File 'lib/droid_adbs.rb', line 105 def delete_data(package) result = `#{shell} pm clear #{package}`.strip puts "failed to delete data:[original log] #{result}" unless result == "Success" result end |
.device_screen ⇒ String
Returns message from adb command.
200 201 202 |
# File 'lib/droid_adbs.rb', line 200 def device_screen `#{shell} input keyevent KEYCODE_HOME`.strip end |
.device_serials ⇒ Array
Returns array of serial number to specify adb command.
55 56 57 |
# File 'lib/droid_adbs.rb', line 55 def device_serials `#{adb} devices`.scan(/^.*\t/).map(&:strip) end |
.devices ⇒ String
Returns Get results of adb devices command.
50 51 52 |
# File 'lib/droid_adbs.rb', line 50 def devices `#{adb} devices`.strip end |
.dump_all_cpuinfos ⇒ String
resources
158 159 160 |
# File 'lib/droid_adbs.rb', line 158 def dump_all_cpuinfos `#{shell} dumpsys cpuinfo`.scan(/^.*$/).map(&:strip) end |
.force_stop(package) ⇒ String
Returns message from adb command.
145 146 147 |
# File 'lib/droid_adbs.rb', line 145 def force_stop(package) `#{shell} am force-stop #{package}`.strip end |
.install(app) ⇒ String
Returns message from adb command.
61 62 63 64 65 66 67 |
# File 'lib/droid_adbs.rb', line 61 def install(app) result = `#{adb_serial} install -r #{app}`.strip raise RuntimeError, result if result.include?("Error:") raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:") raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE") result end |
.install_referrer_broadcast(referrer) ⇒ String
Returns message from adb command.
170 171 172 |
# File 'lib/droid_adbs.rb', line 170 def install_referrer_broadcast(referrer) `#{shell} broadcast window -a com.android.vending.INSTALL_REFERRER --include-stopped-packages --es referrer #{referrer}`.strip end |
.install_with(app, option = "") ⇒ String
Returns message from adb command.
81 82 83 84 85 86 87 |
# File 'lib/droid_adbs.rb', line 81 def install_with(app, option = "") result = `#{adb_serial} install #{option} #{app}`.strip raise RuntimeError, result if result.include?("Error:") raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:") raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE") result end |
.install_with_grant(app) ⇒ String
Returns message from adb command.
71 72 73 74 75 76 77 |
# File 'lib/droid_adbs.rb', line 71 def install_with_grant(app) result = `#{adb_serial} install -gr #{app}`.strip raise RuntimeError, result if result.include?("Error:") raise RuntimeError, "invalid APK" if result.include?("Invalid APK file:") raise RuntimeError, "failed to update apk because INSTALL_FAILED_VERSION_DOWNGRADE" if result.include?("INSTALL_FAILED_VERSION_DOWNGRADE") result end |
.installed?(package) ⇒ Bool
Returns If the package installed, return true. Else return false.
113 114 115 116 117 118 |
# File 'lib/droid_adbs.rb', line 113 def installed?(package) packages = `#{shell} pm list packages -e #{package}`.strip result = packages.each_line.find { |p| p == "package:#{package}" } return true if result false end |
.installed_similar(package) ⇒ Array
Returns all package names.
122 123 124 125 |
# File 'lib/droid_adbs.rb', line 122 def installed_similar(package) packages = `#{shell} pm list packages -e #{package}`.strip packages.each_line.map { |pack| pack.strip.sub("package:", "") } end |
.launch_login_activity(account_type) ⇒ String
Returns message from adb command.
135 136 137 138 139 140 141 |
# File 'lib/droid_adbs.rb', line 135 def launch_login_activity(account_type) if ::DroidAdbs::Devices.device_build_version_sdk.to_i >= 21 `#{shell} am start -a android.settings.ADD_ACCOUNT_SETTINGS --esa authorities #{account_type}`.strip else puts "Can't launch LoginActivity.java because version of sdk in the target device is lower than 21." end end |
.push ⇒ String
Returns adb push command.
45 46 47 |
# File 'lib/droid_adbs.rb', line 45 def push "#{adb_serial} push" end |
.screen_on_or_off ⇒ String
Returns message from adb command.
195 196 197 |
# File 'lib/droid_adbs.rb', line 195 def screen_on_or_off `#{shell} input keyevent 26`.strip end |
.send_broadcast(broadcats_item, broadcast_extra = "") ⇒ String
Returns message from adb command.
152 153 154 |
# File 'lib/droid_adbs.rb', line 152 def send_broadcast(broadcats_item, broadcast_extra = "") `#{shell} am broadcast -a #{broadcats_item} #{broadcast_extra}`.strip end |
.set_tcpip(ip) ⇒ String
Returns adb command with serial.
20 21 22 |
# File 'lib/droid_adbs.rb', line 20 def set_tcpip(ip) `#{adb_serial} tcpip #{ip}`.strip end |
.shell ⇒ String
Returns adb shell command.
40 41 42 |
# File 'lib/droid_adbs.rb', line 40 def shell "#{adb_serial} shell" end |
.start(activity) ⇒ String
Returns message from adb command.
129 130 131 |
# File 'lib/droid_adbs.rb', line 129 def start(activity) `#{shell} am start -n #{activity}`.strip end |
.uninstall(package) ⇒ String
Returns message from adb command.
92 93 94 |
# File 'lib/droid_adbs.rb', line 92 def uninstall(package) `#{adb_serial} uninstall #{package}`.strip end |
.uninstall_similar(package) ⇒ Array
Returns messages from adb command.
98 99 100 101 |
# File 'lib/droid_adbs.rb', line 98 def uninstall_similar(package) installed_packages = installed_similar(package) installed_packages.map { |pack| `#{adb_serial} uninstall #{pack}`.strip } end |
.unlock_with_pin(text) ⇒ String
Returns message from adb command.
190 191 192 |
# File 'lib/droid_adbs.rb', line 190 def unlock_with_pin(text) `#{shell} input text #{text} && #{shell} input keyevent 66`.strip end |
.unlock_without_pin ⇒ String
Emulator should be unlocked after launch emulator with -wipe-data option Should unlock screen if current focus is like ‘mCurrentFocus=Windowu0 StatusBar` .
184 185 186 |
# File 'lib/droid_adbs.rb', line 184 def unlock_without_pin `#{shell} input keyevent 82`.strip end |