[Download] Checking if device is connected before 86/150386/4
authorMichal Bistyga <m.bistyga@samsung.com>
Fri, 15 Sep 2017 09:46:00 +0000 (11:46 +0200)
committerMichal Bistyga <m.bistyga@samsung.com>
Tue, 19 Sep 2017 12:13:48 +0000 (14:13 +0200)
When wi-fi has been disconnected, plugins would throw not intuitive error description.
It was especially important on XU3, where short disconnect occurs more often.

[Verification] 100% TCT pass rate on TM1

Change-Id: I22712dd8e815ac810b8fec5549c370e91498ed85
Signed-off-by: Michal Bistyga <m.bistyga@samsung.com>
src/download/download_instance.cc

index dca989a440756cb1568a81feb487227df6f7a350..68179a18ae68592b181728b9003157cb72db4032 100755 (executable)
@@ -25,6 +25,7 @@
 #include "common/logger.h"
 #include "common/typeutil.h"
 #include "common/filesystem/filesystem_provider.h"
+#include "common/scope_exit.h"
 
 namespace extension {
 namespace download {
@@ -522,6 +523,9 @@ void DownloadInstance::DownloadManagerStart
 
   connection_h connection = nullptr;
   connection_create(&connection);
+  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;
@@ -532,7 +536,12 @@ void DownloadInstance::DownloadManagerStart
   connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
   connection_get_type(connection, &connection_type);
 
-  connection_destroy(connection);
+  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);