pal: ipc_client: Correct resizing of devs_hidl & modskv_hidl vector and
remove resizing of attr_hidl vector

Resize devs_hidl in pal stream set device and
pal stream open, resize  modskv_hidl vector with no_of_devices in
pal stream open and remove the resize of attr_hidl.

Correct resizing of devs_hidl & modskv_hidl vector, which was wrongly
resized,causing an issue on the server side validation.

Remove resizing of attr_hidl vector, which was wrongly
resized, causing an issue on the server side validation.

Change-Id: I7b99cba5f52938ec3f6cf02b8521745bd92f6daf
diff --git a/ipc/HwBinders/pal_ipc_client/src/pal_client_wrapper.cpp b/ipc/HwBinders/pal_ipc_client/src/pal_client_wrapper.cpp
index 894da97..4e132ae 100644
--- a/ipc/HwBinders/pal_ipc_client/src/pal_client_wrapper.cpp
+++ b/ipc/HwBinders/pal_ipc_client/src/pal_client_wrapper.cpp
@@ -351,12 +351,11 @@
         if (pal_client == nullptr)
             return ret;
 
-        hidl_vec<PalStreamAttributes> attr_hidl;
+        hidl_vec<PalStreamAttributes> attr_hidl(1);
         hidl_vec<PalDevice> devs_hidl;
         hidl_vec<ModifierKV> modskv_hidl;
         uint16_t in_channels = 0;
         uint16_t out_channels = 0;
-        uint32_t dev_size = 0;
         int cnt = 0;
         uint8_t *temp = NULL;
         struct pal_stream_info info = attr->info.opt_stream_info;
@@ -367,8 +366,6 @@
             info.version, info.size, info.duration_us, info.has_video, info.is_streaming,
             info.loopback_type);
 
-        attr_hidl.resize(sizeof(::vendor::qti::hardware::pal::V1_0::PalStreamAttributes) + in_channels +
-                         out_channels);
         attr_hidl.data()->type = (PalStreamType)attr->type;
         attr_hidl.data()->info.version = info.version;
         attr_hidl.data()->info.size = info.size;
@@ -382,7 +379,8 @@
 
         if (in_channels) {
             attr_hidl.data()->in_media_config.ch_info.channels = attr->in_media_config.ch_info.channels;
-            attr_hidl.data()->in_media_config.ch_info.ch_map = attr->in_media_config.ch_info.ch_map;
+            memcpy(&attr_hidl.data()->in_media_config.ch_info.ch_map, &attr->in_media_config.ch_info.ch_map,
+                sizeof(uint8_t[64]));
         }
         attr_hidl.data()->in_media_config.aud_fmt_id = (PalAudioFmt)attr->in_media_config.aud_fmt_id;
 
@@ -394,26 +392,28 @@
         attr_hidl.data()->out_media_config.bit_width = attr->out_media_config.bit_width;
         if (out_channels) {
             attr_hidl.data()->out_media_config.ch_info.channels = attr->out_media_config.ch_info.channels;
-            attr_hidl.data()->out_media_config.ch_info.ch_map = attr->out_media_config.ch_info.ch_map;
+            memcpy(&attr_hidl.data()->out_media_config.ch_info.ch_map, &attr->out_media_config.ch_info.ch_map,
+                sizeof(uint8_t[64]));
         }
         attr_hidl.data()->out_media_config.aud_fmt_id = (PalAudioFmt)attr->out_media_config.aud_fmt_id;
         if (devices) {
-            dev_size = no_of_devices * sizeof(struct pal_device);
-            devs_hidl.resize(dev_size);
-            PalDevice *dev_hidl = devs_hidl.data();
+            devs_hidl.resize(no_of_devices);
             for ( cnt = 0; cnt < no_of_devices; cnt++) {
-                 dev_hidl->id =(PalDeviceId)devices[cnt].id;
-                 dev_hidl->config.sample_rate = devices[cnt].config.sample_rate;
-                 dev_hidl->config.bit_width = devices[cnt].config.bit_width;
-                 dev_hidl->config.ch_info.channels = devices[cnt].config.ch_info.channels;
-                 dev_hidl->config.ch_info.ch_map = devices[cnt].config.ch_info.ch_map;
-                 dev_hidl->config.aud_fmt_id = (PalAudioFmt)devices[cnt].config.aud_fmt_id;
-                 dev_hidl =  (PalDevice *)(devs_hidl.data() + sizeof(PalDevice));
+                 devs_hidl[cnt].id =(PalDeviceId)devices[cnt].id;
+                 devs_hidl[cnt].config.sample_rate = devices[cnt].config.sample_rate;
+                 devs_hidl[cnt].config.bit_width = devices[cnt].config.bit_width;
+                 devs_hidl[cnt].config.ch_info.channels = devices[cnt].config.ch_info.channels;
+                 memcpy(&devs_hidl[cnt].config.ch_info.ch_map, &devices[cnt].config.ch_info.ch_map,
+                 sizeof(uint8_t [64]));
+                 devs_hidl[cnt].config.aud_fmt_id = (PalAudioFmt)devices[cnt].config.aud_fmt_id;
             }
         }
         if (modifiers) {
-            modskv_hidl.resize(sizeof(struct modifier_kv) * no_of_modifiers);
-            memcpy(modskv_hidl.data(), modifiers, sizeof(struct modifier_kv) * no_of_modifiers);
+            modskv_hidl.resize(no_of_modifiers);
+            for ( cnt = 0; cnt < no_of_modifiers; cnt++) {
+                modskv_hidl[cnt].key = modifiers[cnt].key;
+                modskv_hidl[cnt].value = modifiers[cnt].value;
+            } 
         }
         pal_client->ipc_pal_stream_open(attr_hidl, no_of_devices, devs_hidl, no_of_modifiers,
                                         modskv_hidl, ClbkBinder, cookie,
@@ -778,7 +778,6 @@
 {
     hidl_vec<PalDevice> devs_hidl;
     int32_t cnt = 0;
-    uint32_t dev_size = 0;
     int32_t ret = -EINVAL;
 
     if (!pal_server_died) {
@@ -789,18 +788,16 @@
 
 
         if (devices) {
-           dev_size = no_of_devices * sizeof(struct pal_device);
-           ALOGD("dev_size %d", dev_size);
-           devs_hidl.resize(dev_size);
-           PalDevice *dev_hidl = devs_hidl.data();
+           ALOGD("no_of_devices %d", no_of_devices);
+           devs_hidl.resize(no_of_devices);
            for (cnt = 0; cnt < no_of_devices; cnt++) {
-                dev_hidl->id =(PalDeviceId)devices[cnt].id;
-                dev_hidl->config.sample_rate = devices[cnt].config.sample_rate;
-                dev_hidl->config.bit_width = devices[cnt].config.bit_width;
-                dev_hidl->config.ch_info.channels = devices[cnt].config.ch_info.channels;
-                dev_hidl->config.ch_info.ch_map = devices[cnt].config.ch_info.ch_map;
-                dev_hidl->config.aud_fmt_id = (PalAudioFmt)devices[cnt].config.aud_fmt_id;
-                dev_hidl =  (PalDevice *)(devs_hidl.data() + sizeof(PalDevice));
+                devs_hidl[cnt].id =(PalDeviceId)devices[cnt].id;
+                devs_hidl[cnt].config.sample_rate = devices[cnt].config.sample_rate;
+                devs_hidl[cnt].config.bit_width = devices[cnt].config.bit_width;
+                devs_hidl[cnt].config.ch_info.channels = devices[cnt].config.ch_info.channels;
+                memcpy(&devs_hidl[cnt].config.ch_info.ch_map, &devices[cnt].config.ch_info.ch_map,
+                sizeof(uint8_t [64]));
+                devs_hidl[cnt].config.aud_fmt_id = (PalAudioFmt)devices[cnt].config.aud_fmt_id;
            }
            ret = pal_client->ipc_pal_stream_set_device((PalStreamHandle)stream_handle,
                                                        no_of_devices, devs_hidl);
diff --git a/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp b/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
index 1896d31..3f7647d 100644
--- a/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
+++ b/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
@@ -510,24 +510,22 @@
     }
 
     if (devs_hidl.size()) {
-        PalDevice *dev_hidl = NULL;
         devices = (struct pal_device *)calloc (1,
                                       sizeof(struct pal_device) * noOfDevices);
         if (!devices) {
             ALOGE("Not enough memory for devices");
             goto exit;
         }
-        dev_hidl = (PalDevice *)devs_hidl.data();
+
         for ( cnt = 0; cnt < noOfDevices; cnt++) {
-             devices[cnt].id = (pal_device_id_t)dev_hidl->id;
-             devices[cnt].config.sample_rate = dev_hidl->config.sample_rate;
-             devices[cnt].config.bit_width = dev_hidl->config.bit_width;
-             devices[cnt].config.ch_info.channels = dev_hidl->config.ch_info.channels;
-             memcpy(&devices[cnt].config.ch_info.ch_map, &dev_hidl->config.ch_info.ch_map,
+             devices[cnt].id = (pal_device_id_t)devs_hidl[cnt].id;
+             devices[cnt].config.sample_rate = devs_hidl[cnt].config.sample_rate;
+             devices[cnt].config.bit_width = devs_hidl[cnt].config.bit_width;
+             devices[cnt].config.ch_info.channels = devs_hidl[cnt].config.ch_info.channels;
+             memcpy(&devices[cnt].config.ch_info.ch_map, &devs_hidl[cnt].config.ch_info.ch_map,
                     sizeof(uint8_t [64]));
              devices[cnt].config.aud_fmt_id =
-                                  (pal_audio_fmt_t)dev_hidl->config.aud_fmt_id;
-             dev_hidl =  (PalDevice *)(dev_hidl + sizeof(PalDevice));
+                                  (pal_audio_fmt_t)devs_hidl[cnt].config.aud_fmt_id;
         }
     }
 
@@ -874,24 +872,22 @@
     int cnt = 0;
     int32_t ret = -ENOMEM;
     if (devs_hidl.size()) {
-        PalDevice *dev_hidl = NULL;
         devices = (struct pal_device *)calloc (1,
                                     sizeof(struct pal_device) * noOfDevices);
         if (!devices) {
             ALOGE("Not enough memory for devices");
             goto exit;
         }
-        dev_hidl = (PalDevice *)devs_hidl.data();
+
         for (cnt = 0; cnt < noOfDevices; cnt++) {
-            devices[cnt].id = (pal_device_id_t)dev_hidl->id;
-            devices[cnt].config.sample_rate = dev_hidl->config.sample_rate;
-            devices[cnt].config.bit_width = dev_hidl->config.bit_width;
-            devices[cnt].config.ch_info.channels = dev_hidl->config.ch_info.channels;
-            memcpy(&devices[cnt].config.ch_info.ch_map, &dev_hidl->config.ch_info.ch_map,
+            devices[cnt].id = (pal_device_id_t)devs_hidl[cnt].id;
+            devices[cnt].config.sample_rate = devs_hidl[cnt].config.sample_rate;
+            devices[cnt].config.bit_width = devs_hidl[cnt].config.bit_width;
+            devices[cnt].config.ch_info.channels = devs_hidl[cnt].config.ch_info.channels;
+            memcpy(&devices[cnt].config.ch_info.ch_map, &devs_hidl[cnt].config.ch_info.ch_map,
                    sizeof(uint8_t [64]));
             devices[cnt].config.aud_fmt_id =
-                                (pal_audio_fmt_t)dev_hidl->config.aud_fmt_id;
-            dev_hidl = (PalDevice *)(dev_hidl + sizeof(PalDevice));
+                                (pal_audio_fmt_t)devs_hidl[cnt].config.aud_fmt_id;
         }
     }