[SECIOTSRK-452] Unistall malicious app feature for primitive devices integration
authorDmytro Logachev <d.logachev@samsung.com>
Fri, 1 Sep 2017 17:16:34 +0000 (20:16 +0300)
committerDmytro Logachev <d.logachev@samsung.com>
Fri, 1 Sep 2017 17:20:45 +0000 (20:20 +0300)
control_app/iot-manager-service/inc/network/network_manager.h
control_app/iot-manager-service/inc/network/nm_types.h
control_app/iot-manager-service/src/network/network_manager.cpp

index 19af591..1c9bc3e 100644 (file)
@@ -47,7 +47,7 @@ public:
     typedef NM_ErrorCode (*GetDevicePolicyFunc)(NM_hContext, const char* devId, const char * agentId, char** policy);
     typedef NM_ErrorCode (*SetDevicePolicyFunc)(NM_hContext, const char* devId, const char* policy);
     typedef NM_ErrorCode (*GetDeviceAgentsFunc)(NM_hContext, const char* devId, char** agents);
-    typedef NM_ErrorCode (*UninstallAppFunc)(NM_hContext, const char* devId, const char* appName);
+    typedef NM_ErrorCode (*UninstallAppFunc)(NM_hContext, const char* devId, const char* parentUUID, const char* appName);
 
 public:
 
@@ -88,7 +88,7 @@ public:
 
     ErrorCode NotifySubscribers(const std::string& title, const std::string& message);
 
-    ErrorCode UninstallApp(const std::string& devId, const std::string& appName);
+    ErrorCode UninstallApp(const std::string& devId, const std::string& parentId, const std::string& appName);
 
     struct ModuleSymbols
     {
index bfde64d..88137d0 100644 (file)
@@ -102,6 +102,7 @@ typedef struct
     const char* duid;
     const char* policy;
     const char* appname;
+    const char* parentUuid;
     CallbackState callbackState;
 } NM_NotificationData;
 
index 4434160..309f455 100644 (file)
@@ -279,6 +279,13 @@ static void PushNotificationCallback(NM_NotificationData data, void* userData)
 
     NetworkManager* nm = reinterpret_cast<NetworkManager*>(userData);
 
+    if (!nm)
+    {
+       LOG_ERR("Null context was passed");
+
+       return;
+    }
+
     if (data.message && data.title)
     {
         if (data.type == NM_NotificationType::NT_Notify)
@@ -286,7 +293,7 @@ static void PushNotificationCallback(NM_NotificationData data, void* userData)
             LOG_INFO("push simple notification: [%s] || [%s]", data.title, data.message);
             PushNotification::GetInstance().Push(data.title, data.message);
         }
-        else if (data.duid && data.appname && (data.type == NM_NotificationType::NT_RemoveAppRequest))
+        else if (data.duid && data.appname && data.parentUuid &&  (data.type == NM_NotificationType::NT_RemoveAppRequest))
         {
             std::string app {data.appname};
             LOG_INFO("appname ok");
@@ -297,13 +304,15 @@ static void PushNotificationCallback(NM_NotificationData data, void* userData)
             LOG_INFO("message ok");
             std::string duid {data.duid};
             LOG_INFO("duid ok");
+            std::string parentUuid {data.parentUuid};
+                       LOG_INFO("parent duid ok");
 
 //          if (PushNotification::GetInstance().PushActionRequest(data.title, data.message, data.duid, data.appname))
             if (PushNotification::GetInstance().PushActionRequest(title, msg, duid, app))
             {
                 int unistallRes = NM_ErrorCode::EC_OK;
 
-                if ((unistallRes = nm->UninstallApp(data.duid, data.appname)) != NM_ErrorCode::EC_OK)
+                if ((unistallRes = nm->UninstallApp(data.duid, data.parentUuid, data.appname)) != NM_ErrorCode::EC_OK)
                 {
                     LOG_ERR("failed to send remove app request, error code: %d", unistallRes);
                 }
@@ -696,14 +705,18 @@ ErrorCode NetworkManager::GetDevicePolicy(const std::string& deviceId,
     return GetPolicy(deviceId, agentId, policy);
 }
 
-ErrorCode NetworkManager::UninstallApp(const std::string& devId,
+ErrorCode NetworkManager::UninstallApp(const std::string& devId, const std::string& parentId,
                                        const std::string& appName)
 {
+       LOG_DBG("BEGIN");
     ASSERT_RETURN(m_moduleSymbols.m_nmUninstallAppFunc, "function isn't loaded", ErrorCode::Error);
 
     NM_ErrorCode res;
 
-    if ((res = m_moduleSymbols.m_nmUninstallAppFunc(m_context, devId.c_str(), appName.c_str()))
+    LOG_INFO("Send uninstall app request with params: dev id:[%s] parent id:[%s] appName:[%s]", devId.c_str(),
+               parentId.c_str(), appName.c_str());
+
+    if ((res = m_moduleSymbols.m_nmUninstallAppFunc(m_context, devId.c_str(), parentId.c_str(), appName.c_str()))
         != NM_ErrorCode::EC_OK)
     {
         LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
@@ -711,6 +724,8 @@ ErrorCode NetworkManager::UninstallApp(const std::string& devId,
         return GetCorrespondingErrorCode(res);
     }
 
+    LOG_DBG("END");
+
     return ErrorCode::Success;
 }