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 m_context.featureLogic =
55 FeatureLogicPtr(new FeatureLogic(m_context.widgetConfig.tzAppid));
56 m_context.job->UpdateProgress(
57 InstallerContext::INSTALL_ACE_PREPARE,
58 "Widget Access Control Check Prepared");
61 void TaskAceCheck::StepAceCheck()
63 WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
64 LogInfo("StepAceCheck!");
65 // This widget does not use any device cap
66 if (m_context.featureLogic->isDone()) {
70 LogInfo("StepAceCheck!");
71 DPL::String deviceCap = m_context.featureLogic->getDevice();
73 LogInfo("StepAceCheck!");
74 LogInfo("DevCap is : " << deviceCap);
76 std::string devCapStr = DPL::ToUTF8String(deviceCap);
77 ace_policy_result_t policyResult = ACE_DENY;
78 ace_return_t ret = ace_get_policy_result(
79 const_cast<const ace_resource_t>(devCapStr.c_str()),
80 dao.getHandle(), //TODO: remove dao.getHandle()
83 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
87 LogInfo("PolicyResult is : " << static_cast<int>(policyResult));
88 m_context.staticPermittedDevCaps.insert(std::make_pair(deviceCap,
89 policyResult == ACE_PERMIT));
91 m_context.featureLogic->setAceResponse(policyResult != ACE_DENY);
94 void TaskAceCheck::StepProcessAceResponse()
96 WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
97 if (m_context.widgetConfig.packagingType ==
98 WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
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(dao.getHandle(), //TODO: remove dao.getHandle()
132 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
135 delete [] list.items;
137 std::set<std::string> acceptedFeature;
138 auto it = m_context.featureLogic->resultBegin();
139 for (;it != m_context.featureLogic->resultEnd(); ++it) {
140 if (!(it->rejected)) {
141 acceptedFeature.insert(DPL::ToUTF8String(it->name));
144 ace_feature_list_t featureList;
145 featureList.count = acceptedFeature.size();
146 featureList.items = new ace_string_t[featureList.count];
149 for (std::set<std::string>::const_iterator iter = acceptedFeature.begin();
150 iter != acceptedFeature.end(); ++iter) {
151 LogDebug("Accepted feature item: " << iter->c_str());
152 featureList.items[i] = const_cast<char *>(iter->c_str());
156 ret = ace_set_accepted_feature(dao.getHandle(), &featureList); //TODO: remove dao.getHandle()
158 delete [] featureList.items;
161 LogError("Error in ace_set_feature");
162 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
163 "ace_set_feature failure.");
168 LogInfo("Next device cap.");
169 // Process next device cap
170 SwitchToStep(&TaskAceCheck::StepAceCheck);
173 void TaskAceCheck::StepCheckAceResponse()
175 LogInfo("Checking ACE response");
176 if (m_context.featureLogic->isRejected()) {
177 LogError("Installation failure. Some devCap was not accepted by ACE.");
178 ThrowMsg(Exceptions::NotAllowed, "Instalation failure. "
179 "Some deviceCap was not accepted by ACE.");
181 LogInfo("Updating \"feature reject status\" in database!");
182 auto it = m_context.featureLogic->resultBegin();
183 auto end = m_context.featureLogic->resultEnd();
184 for(;it != end; ++it){
185 LogInfo(" |- Feature: " << it->name << " has reject status: " << it->rejected);
187 WrtDB::WidgetDAO dao(m_context.widgetConfig.tzAppid);
188 dao.updateFeatureRejectStatus(*it);
191 LogInfo("Installation continues...");
193 m_context.job->UpdateProgress(
194 InstallerContext::INSTALL_ACE_CHECK,
195 "Widget Access Control Check Finished");
198 } //namespace WidgetInstall