Test the image dimensions captured in a screenshot.
bug:14609275
bug:15500275

Change-Id: I62c99835e33fdb5a6a5979685469dfe6d51bb74e
(cherry picked from commit 922c6a30d1715972bf113f2bb9f0315e41a54ab9)
diff --git a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
index b540048..ceb9072 100644
--- a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
+++ b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
@@ -30,12 +30,17 @@
 import com.android.tradefed.util.RunUtil;
 import com.android.tradefed.util.StreamUtil;
 
+import java.awt.image.BufferedImage;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.io.IOException;
 
+import javax.imageio.ImageIO;
+
 /**
  * Functional tests for adb connection
  * <p/>
@@ -328,22 +333,21 @@
     /**
      * Basic test for {@link TestDevice#getScreenshot()}.
      * <p/>
-     * Grab a screenshot, save it to a file, and perform a cursory size check to ensure its valid.
+     * Grab a screenshot and perform a cursory size check to ensure its valid.
      */
     public void testGetScreenshot() throws DeviceNotAvailableException, IOException {
-        CLog.i(LOG_TAG, "testGetScreenshot");
         InputStreamSource source = getDevice().getScreenshot();
         assertNotNull(source);
-        File tmpPngFile = FileUtil.createTempFile("screenshot", ".png");
+        InputStream inputStream = source.createInputStream();
         try {
-            FileUtil.writeToFile(source.createInputStream(), tmpPngFile);
-            CLog.i("Created file at %s", tmpPngFile.getAbsolutePath());
-            assertTrue("Saved png file is less than 10K - is it invalid?",
-                    tmpPngFile.length() > 10*1024);
-            // TODO: add more stringent checks
+            BufferedImage screenshotImage = ImageIO.read(inputStream);
+            CLog.i(LOG_TAG, "testGetScreenshot w=%d, h=%d",
+                    screenshotImage.getWidth(), screenshotImage.getHeight());
+            assertTrue(screenshotImage.getWidth() > 0);
+            assertTrue(screenshotImage.getHeight() > 0);
         } finally {
-            FileUtil.deleteFile(tmpPngFile);
-            source.cancel();
+            StreamUtil.cancel(source);
+            StreamUtil.close(inputStream);
         }
     }