Camera2: guard full raw test by capability

Need to check if device supports RAW capability before doing
full raw test.

Change-Id: Iea9b4049380bd633088e0dff2927743a8ef2c463
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
index 2384fb4..1b915f4 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
@@ -199,6 +199,12 @@
             try {
                 Log.i(TAG, "Testing raw capture for Camera " + mCameraIds[i]);
                 openDevice(mCameraIds[i]);
+                if (!mStaticInfo.isCapabilitySupported(
+                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
+                    Log.i(TAG, "RAW capability is not supported in camera " + mCameraIds[i] +
+                            ". Skip the test.");
+                    continue;
+                }
 
                 fullRawCaptureTestByCamera();
             } finally {
@@ -728,9 +734,11 @@
                 validateRaw16Image(rawImage, size);
 
 
-                DngCreator dngCreator = new DngCreator(mStaticInfo.getCharacteristics(), result);
                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-                dngCreator.writeImage(outputStream, rawImage);
+                try (DngCreator dngCreator =
+                        new DngCreator(mStaticInfo.getCharacteristics(), result)) {
+                    dngCreator.writeImage(outputStream, rawImage);
+                }
 
                 if (DEBUG) {
                     byte[] rawBuffer = outputStream.toByteArray();