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/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
Constant Summary collapse
- VERSION =
"0.3.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.
15 16 17 |
# File 'lib/droid_adbs.rb', line 15 def device_serial @device_serial end |
Class Method Details
.adb_serial ⇒ String
Returns adb command with serial.
34 35 36 |
# File 'lib/droid_adbs.rb', line 34 def adb_serial "#{adb} #{device_serial_option}" end |
.broad_install_referrer(ref) ⇒ String
send referrer for TVs
176 177 178 |
# File 'lib/droid_adbs.rb', line 176 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.
26 27 28 29 30 31 |
# File 'lib/droid_adbs.rb', line 26 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
163 164 165 |
# File 'lib/droid_adbs.rb', line 163 def current_activity `#{shell} dumpsys window windows | grep -E "mCurrentFocus|mFocusedApp"`.strip end |
.delete_data(package) ⇒ String
Returns message from adb command.
104 105 106 107 108 |
# File 'lib/droid_adbs.rb', line 104 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.
199 200 201 |
# File 'lib/droid_adbs.rb', line 199 def device_screen `#{shell} input keyevent KEYCODE_HOME`.strip end |
.device_serials ⇒ Array
Returns array of serial number to specify adb command.
54 55 56 |
# File 'lib/droid_adbs.rb', line 54 def device_serials `#{adb} devices`.scan(/^.*\t/).map(&:strip) end |
.devices ⇒ String
Returns Get results of adb devices command.
49 50 51 |
# File 'lib/droid_adbs.rb', line 49 def devices `#{adb} devices`.strip end |
.dump_all_cpuinfos ⇒ String
resources
157 158 159 |
# File 'lib/droid_adbs.rb', line 157 def dump_all_cpuinfos `#{shell} dumpsys cpuinfo`.scan(/^.*$/).map(&:strip) end |
.force_stop(package) ⇒ String
Returns message from adb command.
144 145 146 |
# File 'lib/droid_adbs.rb', line 144 def force_stop(package) `#{shell} am force-stop #{package}`.strip end |
.install(app) ⇒ String
Returns message from adb command.
60 61 62 63 64 65 66 |
# File 'lib/droid_adbs.rb', line 60 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.
169 170 171 |
# File 'lib/droid_adbs.rb', line 169 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.
80 81 82 83 84 85 86 |
# File 'lib/droid_adbs.rb', line 80 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.
70 71 72 73 74 75 76 |
# File 'lib/droid_adbs.rb', line 70 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.
112 113 114 115 116 117 |
# File 'lib/droid_adbs.rb', line 112 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.
121 122 123 124 |
# File 'lib/droid_adbs.rb', line 121 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.
134 135 136 137 138 139 140 |
# File 'lib/droid_adbs.rb', line 134 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.
44 45 46 |
# File 'lib/droid_adbs.rb', line 44 def push "#{adb_serial} push" end |
.screen_on_or_off ⇒ String
Returns message from adb command.
194 195 196 |
# File 'lib/droid_adbs.rb', line 194 def screen_on_or_off `#{shell} input keyevent 26`.strip end |
.send_broadcast(broadcats_item, broadcast_extra = "") ⇒ String
Returns message from adb command.
151 152 153 |
# File 'lib/droid_adbs.rb', line 151 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.
19 20 21 |
# File 'lib/droid_adbs.rb', line 19 def set_tcpip(ip) `#{adb_serial} tcpip #{ip}`.strip end |
.shell ⇒ String
Returns adb shell command.
39 40 41 |
# File 'lib/droid_adbs.rb', line 39 def shell "#{adb_serial} shell" end |
.start(activity) ⇒ String
Returns message from adb command.
128 129 130 |
# File 'lib/droid_adbs.rb', line 128 def start(activity) `#{shell} am start -n #{activity}`.strip end |
.uninstall(package) ⇒ String
Returns message from adb command.
91 92 93 |
# File 'lib/droid_adbs.rb', line 91 def uninstall(package) `#{adb_serial} uninstall #{package}`.strip end |
.uninstall_similar(package) ⇒ Array
Returns messages from adb command.
97 98 99 100 |
# File 'lib/droid_adbs.rb', line 97 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.
189 190 191 |
# File 'lib/droid_adbs.rb', line 189 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` .
183 184 185 |
# File 'lib/droid_adbs.rb', line 183 def unlock_without_pin `#{shell} input keyevent 82`.strip end |