From affe078baa94cc800e0eefda9262936826e828d7 Mon Sep 17 00:00:00 2001
From: Piotr Kosko
Date: Tue, 3 Apr 2018 10:12:44 +0200
Subject: [PATCH] [Download] Fixed unexpected result of fixing coverity issues
[Bug] When running on TV device, checking status of cellular network
returned not supported error, the checking status of cellular needed
to be moved into correct section instead of running this code in common
code part.
[Verification] TCT result - 100%
Change-Id: I6cb171034588b2616222bde4101a278c491fdc52
Signed-off-by: Piotr Kosko
---
src/download/download_instance.cc | 162 ++++++++++++++++++++++----------------
src/download/download_instance.h | 45 ++++++-----
2 files changed, 117 insertions(+), 90 deletions(-)
diff --git a/src/download/download_instance.cc b/src/download/download_instance.cc
index a2770b3..f33102c 100644
--- a/src/download/download_instance.cc
+++ b/src/download/download_instance.cc
@@ -470,6 +470,85 @@ void DownloadInstance::progress_changed_cb(int download_id, long long unsigned r
g_idle_add(OnProgressChanged, down_cb_ptr);
}
+#define CHECK_CONNECTION_ERROR(ret) \
+ switch (ret) { \
+ case CONNECTION_ERROR_NONE: \
+ break; \
+ case CONNECTION_ERROR_NOT_SUPPORTED: \
+ return LogAndCreateResult( \
+ common::ErrorCode::NOT_SUPPORTED_ERR, \
+ "The networkType of the given DownloadRequest is not supported", \
+ ("The networkType of the given DownloadRequest is not supported")); \
+ default: \
+ return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occurred", \
+ ("Connection problem occurred")); \
+ }
+
+common::PlatformResult DownloadInstance::CheckNetworkConnection(const std::string& network_type,
+ bool& network_support,
+ bool& network_available,
+ DownloadInfoPtr di_ptr) {
+ connection_h connection = nullptr;
+ int ret = connection_create(&connection);
+ CHECK_CONNECTION_ERROR(ret)
+ SCOPE_EXIT {
+ connection_destroy(connection);
+ };
+
+ connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
+ ret = connection_get_type(connection, &connection_type);
+ CHECK_CONNECTION_ERROR(ret)
+
+ if (CONNECTION_TYPE_DISCONNECTED == connection_type) {
+ return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occurred",
+ ("Connection type is disconnected"));
+ }
+
+ if ("CELLULAR" == network_type) {
+ // check if connection type is supported
+ bool cell_support = false;
+ system_info_get_platform_bool("http://tizen.org/feature/network.telephony", &cell_support);
+
+ // check if connection is available
+ connection_cellular_state_e cell_state = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
+ ret = connection_get_cellular_state(connection, &cell_state);
+ CHECK_CONNECTION_ERROR(ret)
+ bool cell_available = (CONNECTION_CELLULAR_STATE_CONNECTED == cell_state);
+
+ // setup download parameters using cellular network
+ network_support = cell_support;
+ network_available = cell_available;
+ di_ptr->network_type = DOWNLOAD_NETWORK_DATA_NETWORK;
+ } else if ("WIFI" == network_type) {
+ // check if connection type is supported
+ bool wifi_support = false;
+ system_info_get_platform_bool("http://tizen.org/feature/network.wifi", &wifi_support);
+
+ // check if connection is available
+ connection_wifi_state_e wifi_state = CONNECTION_WIFI_STATE_DEACTIVATED;
+ ret = connection_get_wifi_state(connection, &wifi_state);
+ CHECK_CONNECTION_ERROR(ret)
+ bool wifi_available = (CONNECTION_WIFI_STATE_CONNECTED == wifi_state);
+
+ // setup download parameters using wifi network
+ network_support = wifi_support;
+ network_available = wifi_available;
+ di_ptr->network_type = DOWNLOAD_NETWORK_WIFI;
+ } else if (("ALL" == network_type) && (CONNECTION_TYPE_DISCONNECTED != connection_type)) {
+ // setup download parameters using 'all' network
+ network_support = true;
+ network_available = true;
+ di_ptr->network_type = DOWNLOAD_NETWORK_ALL;
+ } else {
+ return LogAndCreateResult(
+ common::ErrorCode::INVALID_VALUES_ERR,
+ "The input parameter contains an invalid network type.",
+ ("The input parameter contains an invalid network type: %s", network_type.c_str()));
+ }
+ return common::PlatformResult(common::ErrorCode::NO_ERROR);
+}
+#undef CHECK_CONNECTION_ERROR
+
void DownloadInstance::DownloadManagerStart(const picojson::value& args, picojson::object& out) {
ScopeLogger();
CHECK_PRIVILEGE_ACCESS(kPrivilegeDownload, &out);
@@ -477,7 +556,7 @@ void DownloadInstance::DownloadManagerStart(const picojson::value& args, picojso
CHECK_EXIST(args, "url", out)
int ret;
- std::string networkType;
+ std::string network_type;
DownloadInfoPtr di_ptr(new DownloadInfo);
@@ -499,86 +578,30 @@ void DownloadInstance::DownloadManagerStart(const picojson::value& args, picojso
}
if (!args.get("networkType").is()) {
- networkType = args.get("networkType").is()
- ? args.get("networkType").get()
- : "ALL";
+ network_type = args.get("networkType").is()
+ ? args.get("networkType").get()
+ : "ALL";
}
bool network_support = false;
- bool cell_support = false;
- bool wifi_support = false;
-
- system_info_get_platform_bool("http://tizen.org/feature/network.telephony", &cell_support);
- system_info_get_platform_bool("http://tizen.org/feature/network.wifi", &wifi_support);
-
-#define CHECK_CONNECTION_ERROR(ret) \
- if (CONNECTION_ERROR_NONE != ret) { \
- LogAndReportError( \
- common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occured"), \
- &out, ("Connection type is disconnected")); \
- return; \
- }
-
- connection_h connection = nullptr;
- ret = connection_create(&connection);
- CHECK_CONNECTION_ERROR(ret)
- SCOPE_EXIT {
- connection_destroy(connection);
- };
-
- connection_cellular_state_e cell_state = CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE;
- connection_wifi_state_e wifi_state = CONNECTION_WIFI_STATE_DEACTIVATED;
-
- ret = connection_get_cellular_state(connection, &cell_state);
- CHECK_CONNECTION_ERROR(ret)
- ret = connection_get_wifi_state(connection, &wifi_state);
- CHECK_CONNECTION_ERROR(ret)
-
- connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
- ret = connection_get_type(connection, &connection_type);
- CHECK_CONNECTION_ERROR(ret)
-
-#undef CHECK_CONNECTION_ERROR
-
- if (CONNECTION_TYPE_DISCONNECTED == connection_type) {
- LogAndReportError(
- common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occured"), &out,
- ("Connection type is disconnected"));
- return;
- }
-
bool network_available = false;
- bool cell_available = (CONNECTION_CELLULAR_STATE_CONNECTED == cell_state);
- bool wifi_available = (CONNECTION_WIFI_STATE_CONNECTED == wifi_state);
- if ("CELLULAR" == networkType) {
- network_support = cell_support;
- network_available = cell_available;
- di_ptr->network_type = DOWNLOAD_NETWORK_DATA_NETWORK;
- } else if ("WIFI" == networkType) {
- network_support = wifi_support;
- network_available = wifi_available;
- di_ptr->network_type = DOWNLOAD_NETWORK_WIFI;
- } else if (("ALL" == networkType) && (CONNECTION_TYPE_DISCONNECTED != connection_type)) {
- network_support = true;
- network_available = true;
- di_ptr->network_type = DOWNLOAD_NETWORK_ALL;
- } else {
- LogAndReportError(
- common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR,
- "The input parameter contains an invalid network type."),
- &out, ("The input parameter contains an invalid network type: %s", networkType.c_str()));
+ common::PlatformResult result =
+ CheckNetworkConnection(network_type, network_support, network_available, di_ptr);
+ if (!result) {
+ LogAndReportError(result, &out);
return;
}
/*
- * There is no relevant feature for networkType == "ALL".
+ * There is no relevant feature for network_type == "ALL".
*/
- if (!network_support && ("ALL" != networkType)) {
+ if (!network_support && ("ALL" != network_type)) {
LogAndReportError(common::PlatformResult(common::ErrorCode::NOT_SUPPORTED_ERR,
"The networkType of the given DownloadRequest "
"is not supported on this device."),
- &out, ("Requested network type (%s) is not supported.", networkType.c_str()));
+ &out,
+ ("Requested network type (%s) is not supported.", network_type.c_str()));
return;
}
@@ -586,7 +609,8 @@ void DownloadInstance::DownloadManagerStart(const picojson::value& args, picojso
LogAndReportError(common::PlatformResult(common::ErrorCode::NETWORK_ERR,
"The networkType of the given DownloadRequest "
"is currently not available on this device."),
- &out, ("Requested network type (%s) is not available.", networkType.c_str()));
+ &out,
+ ("Requested network type (%s) is not available.", network_type.c_str()));
return;
}
diff --git a/src/download/download_instance.h b/src/download/download_instance.h
index 4993b0d..947e2ad 100644
--- a/src/download/download_instance.h
+++ b/src/download/download_instance.h
@@ -45,27 +45,6 @@ class DownloadInstance : public common::ParsedInstance {
virtual ~DownloadInstance();
private:
- void DownloadManagerStart(const picojson::value& args, picojson::object& out);
- void DownloadManagerCancel(const picojson::value& args, picojson::object& out);
- void DownloadManagerPause(const picojson::value& args, picojson::object& out);
- void DownloadManagerResume(const picojson::value& args, picojson::object& out);
- void DownloadManagerGetstate(const picojson::value& args, picojson::object& out);
- void DownloadManagerGetmimetype(const picojson::value& args, picojson::object& out);
-
- bool GetDownloadID(const int download_id, int& native_download_id);
-
- static common::PlatformResult convertError(int err, const std::string& message = "");
- static void OnStateChanged(int download_id, download_state_e state, void* user_data);
- static void progress_changed_cb(int download_id, long long unsigned received, void* user_data);
- static void OnStart(int download_id, void* user_data);
-
- static gboolean OnProgressChanged(void* user_data);
- static gboolean OnFinished(void* user_data);
- static gboolean OnPaused(void* user_data);
- static gboolean OnCanceled(void* user_data);
- static gboolean OnFailed(void* user_data);
- static bool CheckInstance(DownloadInstance* instance);
-
struct DownloadInfo {
int download_id;
std::string url;
@@ -91,6 +70,30 @@ class DownloadInstance : public common::ParsedInstance {
typedef std::shared_ptr DownloadInfoPtr;
typedef std::map DownloadInfoMap;
+ common::PlatformResult CheckNetworkConnection(const std::string& network_type,
+ bool& network_support, bool& network_available,
+ DownloadInfoPtr di_ptr);
+ void DownloadManagerStart(const picojson::value& args, picojson::object& out);
+ void DownloadManagerCancel(const picojson::value& args, picojson::object& out);
+ void DownloadManagerPause(const picojson::value& args, picojson::object& out);
+ void DownloadManagerResume(const picojson::value& args, picojson::object& out);
+ void DownloadManagerGetstate(const picojson::value& args, picojson::object& out);
+ void DownloadManagerGetmimetype(const picojson::value& args, picojson::object& out);
+
+ bool GetDownloadID(const int download_id, int& native_download_id);
+
+ static common::PlatformResult convertError(int err, const std::string& message = "");
+ static void OnStateChanged(int download_id, download_state_e state, void* user_data);
+ static void progress_changed_cb(int download_id, long long unsigned received, void* user_data);
+ static void OnStart(int download_id, void* user_data);
+
+ static gboolean OnProgressChanged(void* user_data);
+ static gboolean OnFinished(void* user_data);
+ static gboolean OnPaused(void* user_data);
+ static gboolean OnCanceled(void* user_data);
+ static gboolean OnFailed(void* user_data);
+ static bool CheckInstance(DownloadInstance* instance);
+
static std::mutex instances_mutex_;
static std::vector instances_;
--
2.7.4