tizen beta release
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_ace_check.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file    task_ace_check.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task ace check
21  */
22
23 #include <widget_install/task_ace_check.h>
24 #include <dpl/assert.h>
25
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>
30
31 #include <dpl/ace/PolicyResult.h>
32 #include <dpl/ace/Request.h>
33
34 namespace Jobs {
35 namespace WidgetInstall {
36 TaskAceCheck::TaskAceCheck(InstallerContext& context) :
37     DPL::TaskDecl<TaskAceCheck>(this),
38     m_context(context)
39 {
40     AddStep(&TaskAceCheck::StepPrepareForAce);
41     AddStep(&TaskAceCheck::StepAceCheck);
42     AddStep(&TaskAceCheck::StepProcessAceResponse);
43     AddStep(&TaskAceCheck::StepCheckAceResponse);
44 }
45
46 void TaskAceCheck::StepPrepareForAce()
47 {
48     Assert(!!m_context.widgetHandle);
49     m_context.featureLogic =
50         FeatureLogicPtr(new FeatureLogic(*m_context.widgetHandle));
51 }
52
53 void TaskAceCheck::StepAceCheck()
54 {
55
56     LogInfo("StepAceCheck!");
57     // This widget does not use any device cap
58     if (m_context.featureLogic->isDone()) {
59         return;
60     }
61
62     LogInfo("StepAceCheck!");
63     DPL::String deviceCap = m_context.featureLogic->getDevice();
64
65     LogInfo("StepAceCheck!");
66
67     Assert(!!m_context.widgetHandle);
68     Request *request = new Request(*m_context.widgetHandle,
69                                    WidgetExecutionPhase_WidgetInstall);
70     request->addDeviceCapability(DPL::ToUTF8String(deviceCap));
71
72     CONTROLLER_POST_EVENT(
73         SecurityController,
74         SecurityControllerEvents::AuthorizeWidgetInstallEvent(
75             request,
76             makeICDelegate(&TaskAceCheck::ProcessAceResponse)));
77
78     // PorcessAceResponse will Resume me.
79     m_context.job->Pause();
80 }
81
82 void TaskAceCheck::StepProcessAceResponse()
83 {
84     LogInfo("StepProcessAceResponse");
85     m_context.featureLogic->next();
86
87     // No device caps left to process
88     if (m_context.featureLogic->isDone()) {
89         LogInfo("All responses has been received from ACE.");
90         return;
91     }
92
93     LogInfo("Next device cap.");
94     // Process next device cap
95     SwitchToStep(&TaskAceCheck::StepAceCheck);
96 }
97
98 void TaskAceCheck::StepCheckAceResponse()
99 {
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.");
105     }
106     LogInfo("Installation continues...");
107 }
108
109 void TaskAceCheck::ProcessAceResponse(PolicyResult policyResult)
110 {
111     LogInfo("Received ACE response.");
112
113     DPL::String deviceCap = m_context.featureLogic->getDevice();
114
115     if (policyResult == PolicyEffect::PERMIT)
116       m_context.staticPermittedDevCaps.insert(deviceCap);
117
118     m_context.featureLogic->setAceResponse(policyResult != PolicyEffect::DENY);
119     m_context.job->Resume();
120 }
121
122 } //namespace WidgetInstall
123 } //namespace Jobs