From 496a026826b9affa94b85417608a2b80d88e6712 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Thu, 14 May 2020 13:32:43 +0200
Subject: [PATCH] [mediacontroller] Fix to handle changed behaviour of native
API
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 | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/mediacontroller/mediacontroller_client.cc b/src/mediacontroller/mediacontroller_client.cc
index 3fb6d3f..1cdcfef 100644
--- a/src/mediacontroller/mediacontroller_client.cc
+++ b/src/mediacontroller/mediacontroller_client.cc
@@ -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);
--
2.7.4