[mediacontroller] Fix to handle changed behaviour of native API 20/233420/2
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 14 May 2020 11:32:43 +0000 (13:32 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 14 May 2020 12:27:56 +0000 (14:27 +0200)
Native API was returning invalid pointer in case when metadata was
missing. This caused passing junk data to WebAPI. Now native API returns
null if metadata is missing. Unfortunately, Web API design does not
allow null value for metadata members. To workaround this problem, we
just pass empty strings to Javascript.

[Verification] mediacontroller  TCT passrate 100%.

Change-Id: Icb6813c10bc74caff4cecca2cbc6b55788f08a92

src/mediacontroller/mediacontroller_client.cc

index b41510e2f78a2ad922e20ce1d99f4227185b1df3..658562ececbfdc7d56c624c6c9705e18ffd9495d 100644 (file)
@@ -511,14 +511,20 @@ PlatformResult MediaControllerClient::GetMetadata(const std::string& server_name
         ErrorCode::UNKNOWN_ERR, "Error getting server metadata",
         ("mc_client_get_server_metadata() error: %d, message: %s", ret, get_error_message(ret)));
   }
-
   SCOPE_EXIT {
     mc_metadata_destroy(metadata_h);
   };
 
-  PlatformResult result = types::ConvertMetadata(metadata_h, metadata);
-  if (!result) {
-    return result;
+  // Native layer has changed behaviour and it allows returning null metadata if it is missing
+  // to keep backward compatibility, we just leave empty object and pass it to Javascript.
+  // This way if metadata will be not present, Web API will return object with all empty members.
+  if (metadata_h) {
+    PlatformResult result = types::ConvertMetadata(metadata_h, metadata);
+    if (!result) {
+      return result;
+    }
+  } else {
+    LoggerD("No metadata, returning empty object");
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);