am 4764bfaf: Merge "CameraITS: require ITS to pass on all cameras" into lmp-sprout-dev

* commit '4764bfaf61e311978579b9de2053e480882b6668':
  CameraITS: require ITS to pass on all cameras
diff --git a/apps/CameraITS/pymodules/its/device.py b/apps/CameraITS/pymodules/its/device.py
index 51590a9..f4107a0 100644
--- a/apps/CameraITS/pymodules/its/device.py
+++ b/apps/CameraITS/pymodules/its/device.py
@@ -507,10 +507,11 @@
         return rets if len(rets)>1 else rets[0]
 
     @staticmethod
-    def report_result(success):
+    def report_result(camera_id, success):
+        resultstr = "%s=%s" % (camera_id, 'True' if success else 'False')
         _run(('%s shell am broadcast '
-              '-a %s --ez %s %s') % (ItsSession.ADB, ItsSession.ACTION_ITS_RESULT, \
-              ItsSession.EXTRA_SUCCESS, 'True' if success else 'False' ))
+              '-a %s --es %s %s') % (ItsSession.ADB, ItsSession.ACTION_ITS_RESULT, \
+              ItsSession.EXTRA_SUCCESS, resultstr))
 
 
 def _run(cmd):
diff --git a/apps/CameraITS/tools/run_all_tests.py b/apps/CameraITS/tools/run_all_tests.py
index 6a57943..9f005db 100644
--- a/apps/CameraITS/tools/run_all_tests.py
+++ b/apps/CameraITS/tools/run_all_tests.py
@@ -64,6 +64,12 @@
         os.mkdir(os.path.join(topdir, d))
     print "Saving output files to:", topdir, "\n"
 
+    # determine camera id
+    camera_id = 0
+    for s in sys.argv[1:]:
+        if s[:7] == "camera=" and len(s) > 7:
+            camera_id = s[7:]
+
     # Run each test, capturing stdout and stderr.
     numpass = 0
     numnotmandatedfail = 0
@@ -91,7 +97,7 @@
             numpass, len(tests), 100.0*float(numpass)/len(tests))
     if numnotmandatedfail > 0:
         print "(*) tests are not yet mandated"
-    its.device.ItsSession.report_result(numpass == len(tests))
+    its.device.ItsSession.report_result(camera_id, numpass == len(tests))
 
 if __name__ == '__main__':
     main()
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index a7aeeed..ec3f8d0 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -778,7 +778,8 @@
         (cd CameraITS; source build/envsetup.sh;).
         \n\n3. Setup the test scene described in the CameraITS README file, and aim the camera
         at it.
-        \n\n4. Run the full ITS test suite (cd CameraITS; python tools/run_all_tests.py;).  Once all
+        \n\n4. Run the full ITS test suite on all possible camera Ids.
+        (cd CameraITS; python tools/run_all_tests.py camera=[cameraId]).  Once all
         of the tests have been run, the \'PASS\' button will be enabled if all of the tests have
         succeeded.  Please note that these tests can take 20+ minutes to run.
     </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 7c433bc..12b9bfc 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
@@ -27,6 +27,8 @@
 import android.os.Bundle;
 import android.util.Log;
 import android.widget.Toast;
+import java.util.HashSet;
+import java.util.Arrays;
 
 import com.android.cts.verifier.PassFailButtons;
 import com.android.cts.verifier.R;
@@ -48,12 +50,25 @@
         public void onReceive(Context context, Intent intent) {
             Log.i(TAG, "Received result for Camera ITS tests");
             if (ACTION_ITS_RESULT.equals(intent.getAction())) {
-                if(intent.getBooleanExtra(EXTRA_SUCCESS, false)) {
-                    Log.i(TAG, "Received Camera ITS SUCCESS from host.");
-                    ItsTestActivity.this.showToast(R.string.its_test_passed);
-                    ItsTestActivity.this.getPassButton().setEnabled(true);
+                String result = intent.getStringExtra(EXTRA_SUCCESS);
+                String[] parts = result.split("=");
+                if (parts.length != 2) {
+                    Toast.makeText(ItsTestActivity.this,
+                            "Received unknown ITS result string: " + result,
+                            Toast.LENGTH_SHORT).show();
+                }
+                String cameraId = parts[0];
+                boolean pass = parts[1].equals("True");
+                if(pass) {
+                    Log.i(TAG, "Received Camera " + cameraId + " ITS SUCCESS from host.");
+                    mITSPassedCameraIds.add(cameraId);
+                    if (mCameraIds != null &&
+                            mITSPassedCameraIds.containsAll(Arrays.asList(mCameraIds))) {
+                        ItsTestActivity.this.showToast(R.string.its_test_passed);
+                        ItsTestActivity.this.getPassButton().setEnabled(true);
+                    }
                 } else {
-                    Log.i(TAG, "Received Camera ITS FAILURE from host.");
+                    Log.i(TAG, "Received Camera " + cameraId + " ITS FAILURE from host.");
                     ItsTestActivity.this.showToast(R.string.its_test_failed);
                 }
             }
@@ -61,6 +76,8 @@
     }
 
     private final SuccessReceiver mSuccessReceiver = new SuccessReceiver();
+    private final HashSet<String> mITSPassedCameraIds = new HashSet<>();
+    private String[] mCameraIds = null;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -69,8 +86,6 @@
         setInfoResources(R.string.camera_its_test, R.string.camera_its_test_info, -1);
         setPassFailButtonClickListeners();
         getPassButton().setEnabled(false);
-        IntentFilter filter = new IntentFilter(ACTION_ITS_RESULT);
-        registerReceiver(mSuccessReceiver, filter);
     }
 
     @Override
@@ -81,9 +96,9 @@
             showToast(R.string.no_camera_manager);
         } else {
             try {
-                String[] cameraIds = manager.getCameraIdList();
+                mCameraIds = manager.getCameraIdList();
                 boolean allCamerasAreLegacy = true;
-                for (String id : cameraIds) {
+                for (String id : mCameraIds) {
                     CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);
                     if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
                             != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
@@ -100,12 +115,14 @@
                         "Received error from camera service while checking device capabilities: "
                                 + e, Toast.LENGTH_SHORT).show();
             }
+            IntentFilter filter = new IntentFilter(ACTION_ITS_RESULT);
+            registerReceiver(mSuccessReceiver, filter);
         }
     }
 
     @Override
-    protected void onDestroy() {
-        super.onDestroy();
+    protected void onPause() {
+        super.onPause();
         unregisterReceiver(mSuccessReceiver);
     }