Improve validateHalVersion error message

This change replaces the following error message:

    OperationsUtils: NN_RET_CHECK failed (frameworks/ml/nn/common/OperationsUtils.cpp:80):
    The given inputs and outputs are only supported in HAL version 1.3 and later
    (validating using HAL version 1.2)

with

    OperationsUtils: NN_RET_CHECK failed (frameworks/ml/nn/common/OperationsUtils.cpp:81):
    Operation IDENTITY with inputs {BOOL} and outputs {BOOL} is only supported
    since HAL version 1.3 (validating using HAL version 1.2)

The new message provides information what operation is being validated and what
its input and output types are.

Note that the new message is imprecise if we reject based on operand shapes or
extraParams.

Fix: 141852946
Bug: 139181916
Test: NeuralNetworksTest_static
Change-Id: I8b001f40cddc93648d7f04768aa3e92f4a7081fd
Merged-In: I8b001f40cddc93648d7f04768aa3e92f4a7081fd
(cherry picked from commit 9e9aaf43cad28b411d05467b1a6f2c83426aa459)
diff --git a/common/OperationsUtils.cpp b/common/OperationsUtils.cpp
index cec15fc..5c50e3d 100644
--- a/common/OperationsUtils.cpp
+++ b/common/OperationsUtils.cpp
@@ -21,6 +21,7 @@
 #include "Utils.h"
 
 #include <cmath>
+#include <sstream>
 
 namespace android {
 namespace nn {
@@ -60,9 +61,24 @@
 bool validateHalVersion(const IOperationValidationContext* context,
                         HalVersion minSupportedHalVersion) {
     if (context->getHalVersion() < minSupportedHalVersion) {
-        NN_RET_CHECK_FAIL() << "The given inputs and outputs are only supported in "
-                            << toString(minSupportedHalVersion) << " and later (validating using "
-                            << toString(context->getHalVersion()) << ")";
+        std::ostringstream message;
+        message << "Operation " << context->getOperationName() << " with inputs {";
+        for (uint32_t i = 0, n = context->getNumInputs(); i < n; ++i) {
+            if (i != 0) {
+                message << ", ";
+            }
+            message << toString(context->getInputType(i));
+        }
+        message << "} and outputs {";
+        for (uint32_t i = 0, n = context->getNumOutputs(); i < n; ++i) {
+            if (i != 0) {
+                message << ", ";
+            }
+            message << toString(context->getOutputType(i));
+        }
+        message << "} is only supported since " << toString(minSupportedHalVersion)
+                << " (validating using " << toString(context->getHalVersion()) << ")";
+        NN_RET_CHECK_FAIL() << message.str();
     }
     return true;
 }