2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file task_ace_check.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
20 * @brief Implementation file for installer task ace check
23 #include <widget_install/task_ace_check.h>
24 #include <dpl/assert.h>
26 #include <widget_install/widget_install_context.h>
27 #include <widget_install/widget_install_errors.h>
28 #include <widget_install/job_widget_install.h>
29 #include <security_controller.h>
31 #include <dpl/ace/PolicyResult.h>
32 #include <dpl/ace/Request.h>
35 namespace WidgetInstall {
36 TaskAceCheck::TaskAceCheck(InstallerContext& context) :
37 DPL::TaskDecl<TaskAceCheck>(this),
40 AddStep(&TaskAceCheck::StepPrepareForAce);
41 AddStep(&TaskAceCheck::StepAceCheck);
42 AddStep(&TaskAceCheck::StepProcessAceResponse);
43 AddStep(&TaskAceCheck::StepCheckAceResponse);
46 void TaskAceCheck::StepPrepareForAce()
48 Assert(!!m_context.widgetHandle);
49 m_context.featureLogic =
50 FeatureLogicPtr(new FeatureLogic(*m_context.widgetHandle));
53 void TaskAceCheck::StepAceCheck()
56 LogInfo("StepAceCheck!");
57 // This widget does not use any device cap
58 if (m_context.featureLogic->isDone()) {
62 LogInfo("StepAceCheck!");
63 DPL::String deviceCap = m_context.featureLogic->getDevice();
65 LogInfo("StepAceCheck!");
67 Assert(!!m_context.widgetHandle);
68 Request *request = new Request(*m_context.widgetHandle,
69 WidgetExecutionPhase_WidgetInstall);
70 request->addDeviceCapability(DPL::ToUTF8String(deviceCap));
72 CONTROLLER_POST_EVENT(
74 SecurityControllerEvents::AuthorizeWidgetInstallEvent(
76 makeICDelegate(&TaskAceCheck::ProcessAceResponse)));
78 // PorcessAceResponse will Resume me.
79 m_context.job->Pause();
82 void TaskAceCheck::StepProcessAceResponse()
84 LogInfo("StepProcessAceResponse");
85 m_context.featureLogic->next();
87 // No device caps left to process
88 if (m_context.featureLogic->isDone()) {
89 LogInfo("All responses has been received from ACE.");
93 LogInfo("Next device cap.");
94 // Process next device cap
95 SwitchToStep(&TaskAceCheck::StepAceCheck);
98 void TaskAceCheck::StepCheckAceResponse()
100 LogInfo("Checking ACE response");
101 if (m_context.featureLogic->isRejected()) {
102 LogDebug("Installation failure. Some devCap was not accepted by ACE.");
103 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
104 "Some deviceCap was not accepted by ACE.");
106 LogInfo("Installation continues...");
109 void TaskAceCheck::ProcessAceResponse(PolicyResult policyResult)
111 LogInfo("Received ACE response.");
113 DPL::String deviceCap = m_context.featureLogic->getDevice();
115 if (policyResult == PolicyEffect::PERMIT)
116 m_context.staticPermittedDevCaps.insert(deviceCap);
118 m_context.featureLogic->setAceResponse(policyResult != PolicyEffect::DENY);
119 m_context.job->Resume();
122 } //namespace WidgetInstall