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
27 #include <widget_install/task_ace_check.h>
28 #include <dpl/assert.h>
29 #include <dpl/log/log.h>
30 #include <dpl/foreach.h>
32 #include <widget_install/widget_install_context.h>
33 #include <widget_install/widget_install_errors.h>
34 #include <widget_install/job_widget_install.h>
36 #include <dpl/wrt-dao-rw/widget_dao.h>
37 #include <ace_api_install.h>
40 namespace WidgetInstall {
42 TaskAceCheck::TaskAceCheck(InstallerContext& context) :
43 DPL::TaskDecl<TaskAceCheck>(this),
46 AddStep(&TaskAceCheck::StepPrepareForAce);
47 AddStep(&TaskAceCheck::StepAceCheck);
48 AddStep(&TaskAceCheck::StepProcessAceResponse);
49 AddStep(&TaskAceCheck::StepCheckAceResponse);
52 void TaskAceCheck::StepPrepareForAce()
54 Assert(!!m_context.widgetHandle);
55 m_context.featureLogic =
56 FeatureLogicPtr(new FeatureLogic(*m_context.widgetHandle));
57 m_context.job->UpdateProgress(
58 InstallerContext::INSTALL_ACE_PREPARE,
59 "Widget Access Control Check Prepared");
62 void TaskAceCheck::StepAceCheck()
65 LogInfo("StepAceCheck!");
66 // This widget does not use any device cap
67 if (m_context.featureLogic->isDone()) {
71 LogInfo("StepAceCheck!");
72 DPL::String deviceCap = m_context.featureLogic->getDevice();
74 LogInfo("StepAceCheck!");
75 LogInfo("DevCap is : " << deviceCap);
77 Assert(!!m_context.widgetHandle);
78 std::string devCapStr = DPL::ToUTF8String(deviceCap);
79 ace_policy_result_t policyResult = ACE_DENY;
80 ace_return_t ret = ace_get_policy_result(
81 const_cast<const ace_resource_t>(devCapStr.c_str()),
82 *m_context.widgetHandle,
85 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
89 LogInfo("PolicyResult is : " << static_cast<int>(policyResult));
90 m_context.staticPermittedDevCaps.insert(std::make_pair(deviceCap,
91 policyResult == ACE_PERMIT));
93 m_context.featureLogic->setAceResponse(policyResult != ACE_DENY);
96 void TaskAceCheck::StepProcessAceResponse()
98 if (m_context.browserRequest) {
102 LogInfo("StepProcessAceResponse");
103 m_context.featureLogic->next();
105 // No device caps left to process
106 if (m_context.featureLogic->isDone()) {
107 LogInfo("All responses has been received from ACE.");
108 // Data to convert to C API
109 std::vector<std::string> devCaps;
110 std::vector<bool> devCapsSmack;
111 // Saving static dev cap permissions
112 FOREACH (cap, m_context.staticPermittedDevCaps) {
113 LogInfo("staticPermittedDevCaps : " << cap->first
114 << " smack: " << cap->second);
115 std::string devCapStr = DPL::ToUTF8String(cap->first);
116 devCaps.push_back(devCapStr);
117 devCapsSmack.push_back(cap->second);
119 ace_requested_dev_cap_list_t list;
120 list.count = devCaps.size();
121 list.items = new ace_requested_dev_cap_t[list.count];
123 for (unsigned int i = 0; i < devCaps.size(); ++i) {
124 list.items[i].device_capability =
125 const_cast<const ace_resource_t>(devCaps[i].c_str());
126 list.items[i].smack_granted =
127 devCapsSmack[i] ? ACE_TRUE : ACE_FALSE;
129 ace_return_t ret = ace_set_requested_dev_caps(*(m_context.widgetHandle),
132 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
135 delete [] list.items;
137 std::vector<std::string> acceptedFeature;
138 auto it = m_context.featureLogic->resultBegin();
139 for (;it != m_context.featureLogic->resultEnd(); ++it) {
140 if (!(it->rejected)) {
141 acceptedFeature.push_back(DPL::ToUTF8String(it->name));
144 ace_feature_list_t featureList;
145 featureList.count = acceptedFeature.size();
146 featureList.items = new ace_string_t[featureList.count];
148 for (size_t i=0; i<acceptedFeature.size(); ++i) {
149 featureList.items[i] =
150 const_cast<char *>(acceptedFeature[i].c_str());
153 ret = ace_set_accepted_feature(
154 *(m_context.widgetHandle),
157 delete [] featureList.items;
160 LogError("Error in ace_set_feature");
161 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
162 "ace_set_feature failure.");
167 LogInfo("Next device cap.");
168 // Process next device cap
169 SwitchToStep(&TaskAceCheck::StepAceCheck);
172 void TaskAceCheck::StepCheckAceResponse()
174 LogInfo("Checking ACE response");
175 if (m_context.featureLogic->isRejected()) {
176 LogDebug("Installation failure. Some devCap was not accepted by ACE.");
177 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
178 "Some deviceCap was not accepted by ACE.");
180 LogInfo("Updating \"feature reject status\" in database!");
181 auto it = m_context.featureLogic->resultBegin();
182 auto end = m_context.featureLogic->resultEnd();
183 for(;it != end; ++it){
184 LogInfo(" |- Feature: " << it->name << " has reject status: " << it->rejected);
186 WrtDB::WidgetDAO dao(*(m_context.widgetHandle));
187 dao.updateFeatureRejectStatus(*it);
190 LogInfo("Installation continues...");
192 m_context.job->UpdateProgress(
193 InstallerContext::INSTALL_ACE_CHECK,
194 "Widget Access Control Check Finished");
197 } //namespace WidgetInstall