Snap for 11224086 from caf5103d939f86120501cf195bc4c2e1a0a1561c to mainline-tzdata5-release

Change-Id: I245de12cf63644c6e2dfd7e3ebc3990289537700
diff --git a/ArmnnPreparedModel_1_3.cpp b/ArmnnPreparedModel_1_3.cpp
index bd5261e..353bdaf 100644
--- a/ArmnnPreparedModel_1_3.cpp
+++ b/ArmnnPreparedModel_1_3.cpp
@@ -343,6 +343,12 @@
             return Void();
         }
 
+        if (fenceNativeHandle->numFds != 1)
+        {
+            cb(V1_3::ErrorStatus::INVALID_ARGUMENT, hidl_handle(nullptr), nullptr);
+            return Void();
+        }
+
         if (sync_wait(fenceNativeHandle->data[0], -1) < 0)
         {
             ALOGE("ArmnnPreparedModel_1_3::executeFenced sync fence failed.");
diff --git a/Utils.cpp b/Utils.cpp
index e708f01..1517b2a 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -21,6 +21,7 @@
 #include <sstream>
 #include <cstdio>
 #include <time.h>
+#include <string>
 
 
 
@@ -43,6 +44,22 @@
     armnnUtils::Permute(armnnUtils::Permuted(inTensorShape, mappings), mappings, input, output, dataTypeSize);
 }
 
+template<typename Dimensions>
+auto GetDimensionsSpecificity(const Dimensions& dimensions)
+{
+    // We can't use std::vector<bool> since that is a specialization that packs
+    // bits, so use a string of bools instead. This also has the benefit of
+    // using small string optimization.
+    std::basic_string<bool> specificity(dimensions.size(), false);
+
+    for (std::size_t i = 0; i < dimensions.size(); ++i)
+    {
+        specificity[i] = dimensions.data()[i] != 0;
+    }
+
+    return specificity;
+}
+
 } // anonymous namespace
 
 void SwizzleAndroidNn4dTensorToArmNn(const armnn::TensorInfo& tensor, const void* input, void* output,
@@ -65,7 +82,6 @@
         assert(0);
     }
 }
-
 void* GetMemoryFromPool(V1_0::DataLocation location, const std::vector<android::nn::RunTimePoolInfo>& memPools)
 {
     // find the location within the pool
@@ -108,20 +124,8 @@
     }
     else
     {
-        bool dimensionsSpecificity[5] = { true, true, true, true, true };
-        int count = 0;
-        std::for_each(operand.dimensions.data(),
-                      operand.dimensions.data() +  operand.dimensions.size(),
-                      [&](const unsigned int val)
-                      {
-                          if (val == 0)
-                          {
-                              dimensionsSpecificity[count] = false;
-                          }
-                          count++;
-                      });
-
-        TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity);
+        auto dimensionsSpecificity = GetDimensionsSpecificity(operand.dimensions);
+        TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity.data());
         ret = TensorInfo(tensorShape, type);
     }
 
@@ -177,20 +181,8 @@
     }
     else
     {
-        bool dimensionsSpecificity[5] = { true, true, true, true, true };
-        int count = 0;
-        std::for_each(operand.dimensions.data(),
-                      operand.dimensions.data() +  operand.dimensions.size(),
-                      [&](const unsigned int val)
-                      {
-                          if (val == 0)
-                          {
-                              dimensionsSpecificity[count] = false;
-                          }
-                          count++;
-                      });
-
-        TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity);
+        auto dimensionsSpecificity = GetDimensionsSpecificity(operand.dimensions);
+        TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity.data());
         ret = TensorInfo(tensorShape, type);
     }
 
@@ -276,20 +268,8 @@
         }
         else
         {
-            bool dimensionsSpecificity[5] = { true, true, true, true, true };
-            int count = 0;
-            std::for_each(operand.dimensions.data(),
-                          operand.dimensions.data() +  operand.dimensions.size(),
-                          [&](const unsigned int val)
-                          {
-                              if (val == 0)
-                              {
-                                  dimensionsSpecificity[count] = false;
-                              }
-                              count++;
-                          });
-
-            TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity);
+            auto dimensionsSpecificity = GetDimensionsSpecificity(operand.dimensions);
+            TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity.data());
             ret = TensorInfo(tensorShape, type);
         }
     }