ios.py: Bugfix to prevent iOS tasks from failing with "Error: ImageMountFailed".
ios.py: Bugfix to prevent iOS tasks from failing with "Error: ImageMountFailed".

This CL fixes a bug in the logic that checks whether there's an image mounted on the attached iOS device.

Currently this is determined by checking whether strings "ImagePresent: true" or "ImageSignature:" are present in the output of command "ideviceimagemounter --list". However, these strings do not match the command's actual output:

  # No image mounted.
  $ ideviceimagemounter --list
  Status: Complete

  # Image mounted (fake signature for illustrative purposes).
  $ ideviceimagemounter --list
  ImageSignature[1]:
   0: Rm9yIGlsbHVzdHJhdGl2ZSBwdXJwb3NlcyBvbmx5LiBUaGlzIGlzIG5vdCBhIHJlYWwgc2lnbmF0dXJlLg==
  Status: Complete

As is, the recipe fails to detect that an image is already mounted on the attached iOS device. The recipe then tries to mount one, which makes the "ideviceimagemounter" command fail with "Error: ImageAlreadyMounted". The following example shows how to reproduce this error:

  # Initially no image is mounted.
  $ ideviceimagemounter --list
  Status: Complete

  # Mount an image.
  $ ideviceimagemounter DeveloperDiskImage.dmg DeveloperDiskImage.dmg.signature
  Uploading DeveloperDiskImage.dmg
  done.
  Mounting...
  Done.
  Status: Complete

  # Verify that the image is mounted.
  $ ideviceimagemounter --list
  ImageSignature[1]:
   0: Rm9yIGlsbHVzdHJhdGl2ZSBwdXJwb3NlcyBvbmx5LiBUaGlzIGlzIG5vdCBhIHJlYWwgc2lnbmF0dXJlLg==
  Status: Complete

  # Try to mount an image when one is already mounted.
  $ ideviceimagemounter DeveloperDiskImage.dmg DeveloperDiskImage.dmg.signature
  Uploading DeveloperDiskImage.dmg
  done.
  Mounting...
  Error: ImageMountFailed

Checking for presence of string "ImageSignature" in the ideviceimagemounter command's output seems to solve the problem.

In the process I also discovered that self._run() requires keyword argument stdout=self.m.raw_io.output() in order to return the command's output. As is, the returned stdout is always blank.

Note to reviewer:
- Patchsets 1 to 11 iterate on a potential fix.
- Patchset 12 reproduces the bug. See the failing tryjob.
- Patchset 13 tries the fix. See the successful tryjob.
- Patchsets 14+ clean up the CL.

Change-Id: I3ca1cdbf4bfa450c3e87d6d87b5f615f28c4aaba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281058
Reviewed-by: Weston Tracey <e7e27cb74e46abd7b999223aa4f27901ab7e58c6@google.com>
Commit-Queue: Leandro Lovisolo <f558143c2568be8d55575d13f30a1fc5cb8009d5@google.com>

google/skia,aosp-mirror/platform_external_skia,google/skia,google/skia,aosp-mirror/platform_external_skia,aosp-mirror/platform_external_skia,google/skia,google/skia,google/skia,aosp-mirror/platform_external_skia,google/skia,aosp-mirror/platform_external_skia,google/skia,google/skia,aosp-mirror/platform_external_skia,google/skia,aosp-mirror/platform_external_skia,aosp-mirror/platform_external_skia,aosp-mirror/platform_external_skia,aosp-mirror/platform_external_skia