Add retry logic for adoptable storage tests

- After a call is made to "sm forget all" there is a short window where
  the adoptable disks are not available.  If we check for disk
  availability within this window the test would fail. We add retry
  logic to reduce these failures.

Bug: 32305664
Test: cts-tradefed run cts -m CtsAppSecurityHostTestCases -t
      android.appsecurity.cts.AdoptableHostTest
Change-Id: I0eb4d0914055df28e8fe998c2154caaf61915de1
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
index 1032c62..b77eef2 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
@@ -293,8 +293,18 @@
     }
 
     private String getAdoptionDisk() throws Exception {
-        final String disks = getDevice().executeShellCommand("sm list-disks adoptable");
-        if (disks == null || disks.length() == 0) {
+        // In the case where we run multiple test we cleanup the state of the device. This
+        // results in the execution of sm forget all which causes the MountService to "reset"
+        // all its knowledge about available drives. This can cause the adoptable drive to
+        // become temporarily unavailable.
+        int attempt = 0;
+        String disks = getDevice().executeShellCommand("sm list-disks adoptable");
+        while ((disks == null || disks.isEmpty()) && attempt++ < 15) {
+            Thread.sleep(1000);
+            disks = getDevice().executeShellCommand("sm list-disks adoptable");
+        }
+
+        if (disks == null || disks.isEmpty()) {
             throw new AssertionError("Devices that claim to support adoptable storage must have "
                     + "adoptable media inserted during CTS to verify correct behavior");
         }