Allow hidl_vec = initializer list

Currently, a hidl vector can be constructed using an initializer list, but
it cannot be made equal to an initializer list.
Add the missing operator here to allow for simpler usage.

Test: atest libhidl_test
Bug: 117935272
Change-Id: Id21e9cafee754968a7300a3d7bc85481d32dcc3a
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 43e84c0..55f21ea 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -345,19 +345,7 @@
         *this = std::move(other);
     }
 
-    hidl_vec(const std::initializer_list<T> list)
-            : mOwnsBuffer(true) {
-        if (list.size() > UINT32_MAX) {
-            details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
-        }
-        mSize = static_cast<uint32_t>(list.size());
-        mBuffer = new T[mSize];
-
-        size_t idx = 0;
-        for (auto it = list.begin(); it != list.end(); ++it) {
-            mBuffer[idx++] = *it;
-        }
-    }
+    hidl_vec(const std::initializer_list<T> list) : hidl_vec() { *this = list; }
 
     hidl_vec(const std::vector<T> &other) : hidl_vec() {
         *this = other;
@@ -453,6 +441,24 @@
         return *this;
     }
 
+    hidl_vec& operator=(const std::initializer_list<T> list) {
+        if (list.size() > UINT32_MAX) {
+            details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
+        }
+        if (mOwnsBuffer) {
+            delete[] mBuffer;
+        }
+        mSize = static_cast<uint32_t>(list.size());
+        mBuffer = new T[mSize];
+        mOwnsBuffer = true;
+
+        size_t idx = 0;
+        for (auto it = list.begin(); it != list.end(); ++it) {
+            mBuffer[idx++] = *it;
+        }
+        return *this;
+    }
+
     // cast to an std::vector.
     operator std::vector<T>() const {
         std::vector<T> v(mSize);