CameraITS: improve ITS user experience

Do not require user to click the pass button manually
if all cameras on device are exempted from ITS anymore.

Bug: 20104406

Change-Id: Ia44af80d21e45122e36faf3e57da0e9a7f4acef7
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index a19bcec..9bff601 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -795,8 +795,8 @@
         No camera manager exists!  This test device is in a bad state.
     </string>
     <string name="all_legacy_devices">
-        All cameras on this device are LEGACY mode only - ITS tests will only be applied to LIMITED
-        or better devices.  \'PASS\' button enabled.
+        All cameras on this device are LEGACY mode only - ITS tests are only required on LIMITED
+        or better devices.  Pass.
     </string>
     <string name="its_test_passed">All Camera ITS tests passed.  Pass button enabled!</string>
     <string name="its_test_failed">Some Camera ITS tests failed.</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsTestActivity.java
index 17df106..1fdd044 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/its/ItsTestActivity.java
@@ -138,6 +138,33 @@
         setContentView(R.layout.its_main);
         setInfoResources(R.string.camera_its_test, R.string.camera_its_test_info, -1);
         setPassFailButtonClickListeners();
+
+        // Hide the test if all camera devices are legacy
+        CameraManager manager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE);
+        try {
+            String[] cameraIds = manager.getCameraIdList();
+            mNonLegacyCameraIds = new ArrayList<String>();
+            boolean allCamerasAreLegacy = true;
+            for (String id : cameraIds) {
+                CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
+                if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
+                        != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
+                    mNonLegacyCameraIds.add(id);
+                    allCamerasAreLegacy = false;
+                }
+            }
+            if (allCamerasAreLegacy) {
+                showToast(R.string.all_legacy_devices);
+                ItsTestActivity.this.getReportLog().setSummary(
+                        "PASS: all cameras on this device are LEGACY"
+                        , 1.0, ResultType.NEUTRAL, ResultUnit.NONE);
+                setTestResultAndFinish(true);
+            }
+        } catch (CameraAccessException e) {
+            Toast.makeText(ItsTestActivity.this,
+                    "Received error from camera service while checking device capabilities: "
+                            + e, Toast.LENGTH_SHORT).show();
+        }
         getPassButton().setEnabled(false);
     }
 
@@ -148,27 +175,6 @@
         if (manager == null) {
             showToast(R.string.no_camera_manager);
         } else {
-            try {
-                String[] cameraIds = manager.getCameraIdList();
-                mNonLegacyCameraIds = new ArrayList<String>();
-                boolean allCamerasAreLegacy = true;
-                for (String id : cameraIds) {
-                    CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
-                    if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
-                            != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
-                        mNonLegacyCameraIds.add(id);
-                        allCamerasAreLegacy = false;
-                    }
-                }
-                if (allCamerasAreLegacy) {
-                    showToast(R.string.all_legacy_devices);
-                    getPassButton().setEnabled(true);
-                }
-            } catch (CameraAccessException e) {
-                Toast.makeText(ItsTestActivity.this,
-                        "Received error from camera service while checking device capabilities: "
-                                + e, Toast.LENGTH_SHORT).show();
-            }
             Log.d(TAG, "register ITS result receiver");
             IntentFilter filter = new IntentFilter(ACTION_ITS_RESULT);
             registerReceiver(mSuccessReceiver, filter);