Class: Seven::ASB::Operations::Device
- Inherits:
-
Object
- Object
- Seven::ASB::Operations::Device
- Defined in:
- lib/automate-standard-baseline/operations.rb
Instance Method Summary collapse
- #adb_command ⇒ Object
- #device_args ⇒ Object
- #device_reset_data ⇒ Object
-
#initialize(cucumber_world, serial, index) ⇒ Device
constructor
A new instance of Device.
- #install_and_start_oc_client(oc_apk_path) ⇒ Object
- #make_default_device ⇒ Object
- #reinstall_oc_client(oc_apk_path) ⇒ Object
- #reinstall_oc_client_by_url(url, saved_path = nil) ⇒ Object
- #start_oc_client ⇒ Object
- #stop_oc_client(package_name) ⇒ Object
- #uninstall_oc_client(package_name) ⇒ Object
Constructor Details
#initialize(cucumber_world, serial, index) ⇒ Device
Returns a new instance of Device.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/automate-standard-baseline/operations.rb', line 85 def initialize(cucumber_world, serial, index) @cucumber_world = cucumber_world @serial = serial @index = index log "ADB_DEVICE_INDEX; #{ENV['ADB_DEVICE_INDEX']}" if @index @index = Integer(@index) * 100 else @index = 0 end log "device_index; #{@index}" @apps = Hash.new end |
Instance Method Details
#adb_command ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/automate-standard-baseline/operations.rb', line 220 def adb_command if is_windows? %Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe" #{device_args}) else %Q("#{ENV["ANDROID_HOME"]}/platform-tools/adb" #{device_args}) end end |
#device_args ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/automate-standard-baseline/operations.rb', line 228 def device_args if @serial "-s #{@serial}" else "" end end |
#device_reset_data ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/automate-standard-baseline/operations.rb', line 194 def device_reset_data() # install the oc client apk log "Reset Data Usage/Mobile data (off/on)" cmd = "#{adb_command} shell svc data disable && #{adb_command} shell svc data enable" log cmd result = exec_command(cmd, @@default_time_out) raise "Can not reset data" unless result.is_success log "Reset data usage done." end |
#install_and_start_oc_client(oc_apk_path) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/automate-standard-baseline/operations.rb', line 180 def install_and_start_oc_client(oc_apk_path) # install the oc client apk log "Install oc client" cmd = "#{adb_command} install -r #{oc_apk_path}" log cmd result = exec_command(cmd, @@default_time_out) raise "Can not install oc client" unless result.is_success start_oc_client() #oc_info = dump_oc_info(oc_apk_path, "logs/device-#{ENV['ADB_DEVICE_ARG']}-oc-info.yml") #log "oc_info: #{oc_info}" log "Install and start oc client finished." end |
#make_default_device ⇒ Object
81 82 83 |
# File 'lib/automate-standard-baseline/operations.rb', line 81 def make_default_device @cucumber_world.default_device = self end |
#reinstall_oc_client(oc_apk_path) ⇒ Object
205 206 207 208 209 |
# File 'lib/automate-standard-baseline/operations.rb', line 205 def reinstall_oc_client(oc_apk_path) oc_pkg_name = package_name(oc_apk_path) uninstall_oc_client(oc_pkg_name) install_and_start_oc_client(oc_apk_path) end |
#reinstall_oc_client_by_url(url, saved_path = nil) ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/automate-standard-baseline/operations.rb', line 211 def reinstall_oc_client_by_url(url, saved_path = nil) if saved_path saved_path = File.(saved_path) end saved_path = download_file(url, saved_path) reinstall_oc_client(saved_path) end |
#start_oc_client ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/automate-standard-baseline/operations.rb', line 125 def start_oc_client() log "Starting oc client...." cmd = "#{adb_command} shell am startservice -a com.seven.asimov.ocengine.OCENGINESERVICE" log cmd result = exec_command(cmd, @@default_time_out) raise "Can not start oc by am startservice" unless result.is_success # check if oc is running retriable :tries => 5, :interval => 30 do cmd = "#{adb_command} shell su -c ps" log cmd result = exec_command(cmd, @@default_time_out) for oc_process in OC_GA_PROCESSES raise "OC client is not running" unless result.output.include?(oc_process) end end # check iptables is modified retriable :tries => 3, :interval => 30 do cmd = "#{adb_command} shell su -c iptables -t nat -nvL" log cmd result = exec_command(cmd, @@default_time_out) log "veirfy redirect port #{@@v_port}" raise "iptables is not modified" unless result.output.include?("redir ports #{@@v_port}") end puts "oc client is started." end |
#stop_oc_client(package_name) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/automate-standard-baseline/operations.rb', line 153 def stop_oc_client(package_name) log "Stopping oc client...." cmd = "#{adb_command} shell am force-stop #{package_name}" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success raise "Can not stop oc by am force-stop" unless result.is_success # kill oc client processes for oc_process in OC_GA_PROCESSES cmd = "#{adb_command} shell su -c cat /data/misc/openchannel/pids/#{oc_process}" log cmd result = exec_command(cmd, @@default_time_out).output.strip log result cmd = "#{adb_command} shell su -c kill -9 #{result}" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success end # flush iptables cmd = "#{adb_command} shell su -c iptables -t nat -F" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success end |
#uninstall_oc_client(package_name) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/automate-standard-baseline/operations.rb', line 101 def uninstall_oc_client(package_name) # uninstall the oc client apk log "Uninstall oc client" cmd = "#{adb_command} uninstall #{package_name}" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success stop_oc_client(package_name) # remove /data/misc/openchannel cmd = "#{adb_command} shell su -c rm -r /data/misc/openchannel" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success cmd = "#{adb_command} shell su -c rm -r /sdcard/OpenChannel" log cmd result = exec_command(cmd, @@default_time_out) log result.is_success log "Uninstall oc client finished" end |