| 321 | self.logger.info("Process inside emulator has exited.") |
| 322 | |
| 323 | def fetchOutput(self, args, appIdToRun): |
| 324 | appDataDirInEmulator = "/data/user/0/%s" % (appIdToRun) |
| 325 | |
| 326 | # the application has now exited. If the caller wants us to read output data from |
| 327 | # a file inside the emulator then we do that now. |
| 328 | if args.run_android_fetch_output_from: |
| 329 | fromPath = args.run_android_fetch_output_from |
| 330 | fromPath = fromPath.replace("{DATA_DIR}", appDataDirInEmulator) |
| 331 | |
| 332 | if args.run_output_file: |
| 333 | readTargetFile = open(args.run_output_file, "w") |
| 334 | to_desc = args.run_output_file |
| 335 | else: |
| 336 | readTargetFile = None |
| 337 | to_desc = "stdout" |
| 338 | |
| 339 | self.logger.info("Extracting output data from emulator\nFrom: %s\nTo: %s", fromPath, to_desc ) |
| 340 | |
| 341 | try: |
| 342 | # it would be nice if we could use adb pull. However we will get permission |
| 343 | # denied when we try to access private data. |
| 344 | # Luckily we can use run-as instead |
| 345 | #pull_command = '"%s" pull "%s" "%s"' % ( self.adbPath, fromPath, temp_output_path ) |
| 346 | readCommand = '"%s" shell run-as "%s" cat "%s"' % ( self.adbPath, appIdToRun, fromPath ) |
| 347 | |
| 348 | # if the file does not exist then the pull command will fail. |
| 349 | readExitCode = subprocess.call(readCommand, shell=True, stdout=readTargetFile, env=self.androidEnvironment ) |
| 350 | |
| 351 | if readExitCode!=0: |
| 352 | self.logger.warning("Output file inside emulator does not exist.") |
| 353 | |
| 354 | finally: |
| 355 | if readTargetFile is not None: |
| 356 | readTargetFile.close() |
| 357 | |
| 358 | def closeEmulator(self, deviceName, emulatorProcess): |
| 359 | self.logger.warning("Killing emulator") |