operator== and != for hidl_vec.

Test: libhidl_test

Bug: 32834072
Change-Id: Iae9b454f5c1e9d8b3b10394ef6de9d4ba4cdd959
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 1a4fd3c..1b0184a 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -382,6 +382,24 @@
         return v;
     }
 
+    // equality check, assuming that T::operator== is defined.
+    bool operator==(const hidl_vec &other) const {
+        if (mSize != other.size()) {
+            return false;
+        }
+        for (size_t i = 0; i < mSize; ++i) {
+            if (!(mBuffer[i] == other.mBuffer[i])) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    // inequality check, assuming that T::operator== is defined.
+    inline bool operator!=(const hidl_vec &other) const {
+        return !((*this) == other);
+    }
+
     size_t size() const {
         return mSize;
     }
@@ -649,6 +667,20 @@
                 &mBuffer[index * details::product<SIZES...>::value]);
     }
 
+    // equality check, assuming that T::operator== is defined.
+    bool operator==(const hidl_array &other) const {
+        for (size_t i = 0; i < elementCount(); ++i) {
+            if (!(mBuffer[i] == other.mBuffer[i])) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    inline bool operator!=(const hidl_array &other) const {
+        return !((*this) == other);
+    }
+
     using size_tuple_type = std::tuple<decltype(SIZE1), decltype(SIZES)...>;
 
     static constexpr size_tuple_type size() {
@@ -696,6 +728,20 @@
         return mBuffer[index];
     }
 
+    // equality check, assuming that T::operator== is defined.
+    bool operator==(const hidl_array &other) const {
+        for (size_t i = 0; i < elementCount(); ++i) {
+            if (!(mBuffer[i] == other.mBuffer[i])) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    inline bool operator!=(const hidl_array &other) const {
+        return !((*this) == other);
+    }
+
     static constexpr size_t size() { return SIZE1; }
     static constexpr size_t elementCount() { return SIZE1; }