[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_ace_check.cpp
index a8a6a6e..72628c4 100644 (file)
 
 namespace Jobs {
 namespace WidgetInstall {
-
 TaskAceCheck::TaskAceCheck(InstallerContext& context) :
     DPL::TaskDecl<TaskAceCheck>(this),
     m_context(context)
 {
+    AddStep(&TaskAceCheck::StartStep);
     AddStep(&TaskAceCheck::StepPrepareForAce);
     AddStep(&TaskAceCheck::StepAceCheck);
     AddStep(&TaskAceCheck::StepProcessAceResponse);
     AddStep(&TaskAceCheck::StepCheckAceResponse);
+    AddStep(&TaskAceCheck::EndStep);
 }
 
 void TaskAceCheck::StepPrepareForAce()
 {
-    Assert(!!m_context.widgetHandle);
     m_context.featureLogic =
-        FeatureLogicPtr(new FeatureLogic(*m_context.widgetHandle));
+        FeatureLogicPtr(new FeatureLogic(m_context.widgetConfig.tzAppid));
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_ACE_PREPARE,
         "Widget Access Control Check Prepared");
@@ -61,57 +61,67 @@ void TaskAceCheck::StepPrepareForAce()
 
 void TaskAceCheck::StepAceCheck()
 {
-
-    LogInfo("StepAceCheck!");
+    WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
+    LogDebug("StepAceCheck!");
     // This widget does not use any device cap
     if (m_context.featureLogic->isDone()) {
         return;
     }
 
-    LogInfo("StepAceCheck!");
+    LogDebug("StepAceCheck!");
     DPL::String deviceCap = m_context.featureLogic->getDevice();
 
-    LogInfo("StepAceCheck!");
-    LogInfo("DevCap is : " << deviceCap);
+    LogDebug("StepAceCheck!");
+    LogDebug("DevCap is : " << deviceCap);
 
-    Assert(!!m_context.widgetHandle);
     std::string devCapStr = DPL::ToUTF8String(deviceCap);
     ace_policy_result_t policyResult = ACE_DENY;
-    ace_return_t ret = ace_get_policy_result(
-            const_cast<const ace_resource_t>(devCapStr.c_str()),
-            *m_context.widgetHandle,
-            &policyResult);
-    if (ACE_OK != ret) {
-        ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
-                 "ACE check failure");
+
+    //TODO: remove dao.getHandle()
+    if (m_context.mode.installTime == InstallMode::InstallTime::PRELOAD) {
+        LogDebug("This widget is prealoaded. So ace check will be skiped");
+        policyResult = ACE_PERMIT;
+    } else {
+        ace_return_t ret = ace_get_policy_result(
+                const_cast<const ace_resource_t>(devCapStr.c_str()),
+                dao.getHandle(),
+                &policyResult);
+        if (ACE_OK != ret) {
+            ThrowMsg(Exceptions::AceCheckFailed, "Instalation failure. "
+                    "ACE check failure");
+        }
     }
 
-    LogInfo("PolicyResult is : " << static_cast<int>(policyResult));
+    LogDebug("PolicyResult is : " << static_cast<int>(policyResult));
     m_context.staticPermittedDevCaps.insert(std::make_pair(deviceCap,
-            policyResult == ACE_PERMIT));
+                                                           policyResult ==
+                                                           ACE_PERMIT));
 
     m_context.featureLogic->setAceResponse(policyResult != ACE_DENY);
 }
 
 void TaskAceCheck::StepProcessAceResponse()
 {
-    if (m_context.locations->browserRequest()) {
+    WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
+    if (m_context.widgetConfig.packagingType ==
+        WrtDB::PKG_TYPE_HOSTED_WEB_APP)
+    {
         return;
     }
 
-    LogInfo("StepProcessAceResponse");
+    LogDebug("StepProcessAceResponse");
     m_context.featureLogic->next();
 
     // No device caps left to process
     if (m_context.featureLogic->isDone()) {
-        LogInfo("All responses has been received from ACE.");
+        LogDebug("All responses has been received from ACE.");
         // Data to convert to C API
         std::vector<std::string> devCaps;
         std::vector<bool> devCapsSmack;
         // Saving static dev cap permissions
-        FOREACH (cap, m_context.staticPermittedDevCaps) {
-            LogInfo("staticPermittedDevCaps : " << cap->first
-                    << " smack: " << cap->second);
+        FOREACH(cap, m_context.staticPermittedDevCaps) {
+            LogDebug("staticPermittedDevCaps : " << cap->first
+                                                << " smack: " << cap->second);
             std::string devCapStr = DPL::ToUTF8String(cap->first);
             devCaps.push_back(devCapStr);
             devCapsSmack.push_back(cap->second);
@@ -122,21 +132,22 @@ void TaskAceCheck::StepProcessAceResponse()
 
         for (unsigned int i = 0; i < devCaps.size(); ++i) {
             list.items[i].device_capability =
-                    const_cast<const ace_resource_t>(devCaps[i].c_str());
+                const_cast<const ace_resource_t>(devCaps[i].c_str());
             list.items[i].smack_granted =
-                    devCapsSmack[i] ? ACE_TRUE : ACE_FALSE;
+                devCapsSmack[i] ? ACE_TRUE : ACE_FALSE;
         }
-        ace_return_t ret = ace_set_requested_dev_caps(*(m_context.widgetHandle),  //TODO: (ace_widget_handle_t not int needed)
+        //TODO: remove dao.getHandle()
+        ace_return_t ret = ace_set_requested_dev_caps(dao.getHandle(),
                                                       &list);
         if (ACE_OK != ret) {
-            ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
-                     "ACE failure");
+            ThrowMsg(Exceptions::AceCheckFailed, "Instalation failure. "
+                                             "ACE failure");
         }
-        delete [] list.items;
+        delete[] list.items;
 
         std::set<std::string> acceptedFeature;
         auto it = m_context.featureLogic->resultBegin();
-        for (;it != m_context.featureLogic->resultEnd(); ++it) {
+        for (; it != m_context.featureLogic->resultEnd(); ++it) {
             if (!(it->rejected)) {
                 acceptedFeature.insert(DPL::ToUTF8String(it->name));
             }
@@ -145,57 +156,70 @@ void TaskAceCheck::StepProcessAceResponse()
         featureList.count = acceptedFeature.size();
         featureList.items = new ace_string_t[featureList.count];
 
-        size_t i=0;
+        size_t i = 0;
         for (std::set<std::string>::const_iterator iter = acceptedFeature.begin();
-                iter != acceptedFeature.end(); ++iter) {
+             iter != acceptedFeature.end(); ++iter)
+        {
             LogDebug("Accepted feature item: " << iter->c_str());
             featureList.items[i] = const_cast<char *>(iter->c_str());
             i++;
         }
 
-        ret = ace_set_accepted_feature(
-          *(m_context.widgetHandle),
-          &featureList);
+        //TODO: remove dao.getHandle()
+        ret = ace_set_accepted_feature(dao.getHandle(), &featureList);
 
-        delete [] featureList.items;
+        delete[] featureList.items;
 
         if (ACE_OK != ret) {
             LogError("Error in ace_set_feature");
-            ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
-              "ace_set_feature failure.");
+            ThrowMsg(Exceptions::AceCheckFailed, "Instalation failure. "
+                                             "ace_set_feature failure.");
         }
         return;
     }
 
-    LogInfo("Next device cap.");
+    LogDebug("Next device cap.");
     // Process next device cap
     SwitchToStep(&TaskAceCheck::StepAceCheck);
 }
 
 void TaskAceCheck::StepCheckAceResponse()
 {
-    LogInfo("Checking ACE response");
+    LogDebug("Checking ACE response");
     if (m_context.featureLogic->isRejected()) {
         LogError("Installation failure. Some devCap was not accepted by ACE.");
-        ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
+        ThrowMsg(
+            Exceptions::PrivilegeLevelViolation,
+            "Instalation failure. "
             "Some deviceCap was not accepted by ACE.");
     }
-    LogInfo("Updating \"feature reject status\" in database!");
+    LogDebug("Updating \"feature reject status\" in database!");
     auto it = m_context.featureLogic->resultBegin();
     auto end = m_context.featureLogic->resultEnd();
-    for(;it != end; ++it){
-        LogInfo("  |-  Feature: " << it->name << " has reject status: " << it->rejected);
+    for (; it != end; ++it) {
+        LogDebug(
+            "  |-  Feature: " << it->name << " has reject status: " <<
+            it->rejected);
         if (it->rejected) {
-            WrtDB::WidgetDAO dao(*(m_context.widgetHandle));
+            WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
             dao.updateFeatureRejectStatus(*it);
         }
     }
-    LogInfo("Installation continues...");
+    LogDebug("Installation continues...");
+}
 
+void TaskAceCheck::StartStep()
+{
+    LogDebug("--------- <TaskAceCheck> : START ----------");
+}
+
+void TaskAceCheck::EndStep()
+{
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_ACE_CHECK,
         "Widget Access Control Check Finished");
-}
 
+    LogDebug("--------- <TaskAceCheck> : END ----------");
+}
 } //namespace WidgetInstall
 } //namespace Jobs