Fix vm-tests attempt 2

Pass in ANDROID_DATA env variable, so dalvikvm will use the dalvik-cache
folder in /data/local/tmp/dalvik-cache.

Also remove all files when test completes.

Bug 5493719

Change-Id: Ifa63f25f4c5b374a7a44fce79075401a51de2987
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
index 31a1602..e972640 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
@@ -46,6 +46,7 @@
                     getDevice().getSerialNumber()));
         }
         super.run(listener);
+        cleanupDeviceFiles(getDevice());
     }
 
     /**
@@ -58,10 +59,7 @@
      */
     private boolean installVmPrereqs(ITestDevice device, CtsBuildHelper ctsBuild)
             throws DeviceNotAvailableException {
-        if (device.doesFileExist(VM_TEST_TEMP_DIR)) {
-            CLog.d("Removing device's temp dir %s from previous runs.", VM_TEST_TEMP_DIR);
-            device.executeShellCommand(String.format("rm -r %s", VM_TEST_TEMP_DIR));
-        }
+        cleanupDeviceFiles(device);
         // Creates temp directory recursively. We also need to create the dalvik-cache directory
         // which is used by the dalvikvm to optimize things. Without the dalvik-cache, there will be
         // a sigsev thrown by the vm.
@@ -97,6 +95,19 @@
     }
 
     /**
+     * Removes temporary file directory from device
+     *
+     * @param device
+     * @throws DeviceNotAvailableException
+     */
+    private void cleanupDeviceFiles(ITestDevice device) throws DeviceNotAvailableException {
+        if (device.doesFileExist(VM_TEST_TEMP_DIR)) {
+            CLog.d("Removing device's temp dir %s from previous runs.", VM_TEST_TEMP_DIR);
+            device.executeShellCommand(String.format("rm -r %s", VM_TEST_TEMP_DIR));
+        }
+    }
+
+    /**
      * Creates the file directory recursively in the device.
      *
      * @param device the {@link ITestDevice}
diff --git a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
index d31daa1..eebbb00 100644
--- a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
+++ b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
@@ -217,8 +217,9 @@
     }
 
     private String getShellExecJavaLine(String classpath, String mainclass) {
-      String cmd = String.format("dalvikvm -Xint:portable -Xmx512M -Xss32K -Djava.io.tmpdir=%s" +
-                                 " -classpath %s %s", TARGET_JAR_ROOT_PATH, classpath, mainclass);
+      String cmd = String.format("ANDROID_DATA=%s dalvikvm -Xint:portable -Xmx512M -Xss32K " +
+              ""-Djava.io.tmpdir=%s" -classpath %s %s", TARGET_JAR_ROOT_PATH, TARGET_JAR_ROOT_PATH,
+              classpath, mainclass);
       return "String res = getDevice().executeShellCommand(\""+ cmd + "\");\n" +
              "// A sucessful adb shell command returns an empty string.\n" +
              "assertEquals(\"" + cmd + "\", \"\", res);";