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_new_db_insert.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
19 * @author Soyoung kim(sy037.kim@samsung.com)
21 * @brief Implementation file for installer task database updating for widget
27 #include <widget_install/task_database.h>
28 #include <widget_install/job_widget_install.h>
29 #include <widget_install/widget_install_errors.h>
30 #include <widget_install/widget_install_context.h>
31 #include <web_provider_livebox_info.h>
32 #include <dpl/wrt-dao-rw/widget_dao.h>
33 #include <dpl/wrt-dao-ro/vconf_config.h>
34 #include <dpl/foreach.h>
35 #include <dpl/utils/wrt_utility.h>
36 #include <dpl/log/log.h>
37 #include <dpl/assert.h>
38 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
39 #include <dpl/wrt-dao-ro/widget_dao_types.h>
42 #include <ace_api_install.h>
43 #include <ace_registration.h>
49 using namespace WrtDB;
52 namespace WidgetInstall {
53 TaskDatabase::TaskDatabase(InstallerContext& context) :
54 DPL::TaskDecl<TaskDatabase>(this),
56 m_handleToRemove(INVALID_WIDGET_HANDLE),
57 m_handle(INVALID_WIDGET_HANDLE)
59 AddStep(&TaskDatabase::StepRegisterExternalFiles);
60 AddStep(&TaskDatabase::StepWrtDBInsert);
61 AddStep(&TaskDatabase::StepAceDBInsert);
62 AddStep(&TaskDatabase::StepSecurityOriginDBInsert);
63 AddStep(&TaskDatabase::StepRemoveExternalFiles);
64 AddStep(&TaskDatabase::StepCreateVconf);
65 AddStep(&TaskDatabase::StepLiveboxDBInsert);
67 AddAbortStep(&TaskDatabase::StepAbortDBInsert);
70 void TaskDatabase::StepWrtDBInsert()
74 /* Set install Time */
75 time(&m_context.widgetConfig.installedTime);
77 if (m_context.isUpdateMode) { //update
78 LogInfo("Registering widget... (update)");
81 m_handleToRemove = WidgetDAOReadOnly::getHandle(
82 m_context.widgetConfig.tzAppid);
84 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
87 "Given tizenId not found for update installation (Same GUID?)");
88 ThrowMsg(Exceptions::DatabaseFailure,
89 "Given tizenId not found for update installation");
91 WidgetDAO::registerOrUpdateWidget(
92 m_context.widgetConfig.tzAppid,
93 m_context.widgetConfig,
94 m_context.wacSecurity);
95 m_handle = WidgetDAOReadOnly::getHandle(
96 m_context.widgetConfig.tzAppid);
97 } else { //new installation
98 LogInfo("Registering widget...");
99 WidgetDAO::registerWidget(
100 m_context.widgetConfig.tzAppid,
101 m_context.widgetConfig,
102 m_context.wacSecurity);
103 m_handle = WidgetDAOReadOnly::getHandle(
104 m_context.widgetConfig.tzAppid);
107 FOREACH(cap, m_context.staticPermittedDevCaps) {
109 "staticPermittedDevCaps : " << cap->first
110 << " smack status: " <<
114 LogInfo("Widget registered");
116 Catch(WidgetDAO::Exception::DatabaseError)
118 LogError("Database failure!");
119 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
121 Catch(DPL::DB::SqlConnection::Exception::Base)
123 LogError("Database failure!");
124 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
128 void TaskDatabase::StepAceDBInsert()
130 LogDebug("Inserting Ace database entry. New handle: " << m_handle);
131 if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
132 LogDebug("Removing old insallation. Handle: " << m_handleToRemove);
133 if (ACE_OK != ace_unregister_widget(
134 static_cast<ace_widget_handle_t>(m_handleToRemove)))
137 "Error while removing ace entry for previous insallation");
141 if (!AceApi::registerAceWidget(m_handle, m_context.widgetConfig,
142 m_context.wacSecurity.getCertificateList()))
144 LogError("ace database insert failed");
145 ThrowMsg(Exceptions::UpdateFailed,
146 "Update failure. ace_register_widget failed");
148 LogDebug("Ace data inserted");
151 void TaskDatabase::StepSecurityOriginDBInsert()
153 LogDebug("Create Security origin database");
154 // automatically create security origin database
155 using namespace SecurityOriginDB;
156 using namespace WrtDB;
158 SecurityOriginDAO dao(m_context.locations->getPkgId());
160 // Checking privilege list for setting security origin exception data
161 FOREACH(it, m_context.widgetConfig.configInfo.privilegeList) {
162 std::map<std::string, Feature>::const_iterator result =
163 g_W3CPrivilegeTextMap.find(DPL::ToUTF8String(it->name));
164 if (result != g_W3CPrivilegeTextMap.end()) {
165 if (result->second == FEATURE_USER_MEDIA) {
166 dao.setPrivilegeSecurityOriginData(result->second, false);
167 } else if (result->second == FEATURE_FULLSCREEN_MODE) {
170 dao.setPrivilegeSecurityOriginData(result->second);
175 m_context.job->UpdateProgress(
176 InstallerContext::INSTALL_NEW_DB_INSERT,
177 "New Widget DB UPDATE Finished");
180 void TaskDatabase::StepRegisterExternalFiles()
182 WrtDB::ExternalLocationList externalLocationsUpdate =
183 m_context.locations->listExternalLocations();
184 if (m_context.isUpdateMode) { //update
187 WidgetDAO dao(m_context.widgetConfig.tzAppid);
188 WrtDB::ExternalLocationList externalLocationsDB =
189 dao.getWidgetExternalLocations();
190 FOREACH(file, externalLocationsDB)
192 if (std::find(externalLocationsUpdate.begin(),
193 externalLocationsUpdate.end(),
194 *file) == externalLocationsUpdate.end())
196 m_externalLocationsToRemove.push_back(*file);
200 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
203 "Given tizenId not found for update installation (Same GUID?)");
204 ThrowMsg(Exceptions::UpdateFailed,
205 "Given tizenId not found for update installation");
208 LogDebug("Registering external files:");
209 FOREACH(file, externalLocationsUpdate)
211 LogDebug(" -> " << *file);
214 //set external locations to be registered
215 m_context.widgetConfig.externalLocations = externalLocationsUpdate;
218 void TaskDatabase::StepRemoveExternalFiles()
220 if (!m_externalLocationsToRemove.empty()) {
221 LogDebug("Removing external files:");
224 FOREACH(file, m_externalLocationsToRemove)
226 if (WrtUtilFileExists(*file)) {
227 LogDebug(" -> " << *file);
228 if (-1 == TEMP_FAILURE_RETRY(remove(file->c_str()))) {
229 ThrowMsg(Exceptions::RemovingFileFailure,
230 "Failed to remove external file");
232 } else if (WrtUtilDirExists(*file)) {
233 LogDebug(" -> " << *file);
234 if (!WrtUtilRemove(*file)) {
235 ThrowMsg(Exceptions::RemovingFolderFailure,
236 "Failed to remove external directory");
239 LogWarning(" -> " << *file << "(no such a path)");
244 void TaskDatabase::StepCreateVconf()
246 LogDebug("StepCreateVconf");
247 std::map<std::string, WrtDB::SettingsType> vconfData;
249 WrtDB::VconfConfig::GetVconfKeyPopupUsage(
250 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
252 WrtDB::VconfConfig::GetVconfKeyGeolocationUsage(
253 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
255 WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
256 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
258 WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
259 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_OFF;
261 // vconftool -g 5000 set -t int <path> initialize value
262 // Current installer should use vconftool for setting group ID
263 // In case of install application by pkgcmd, permission for others
265 FOREACH(it, vconfData) {
266 std::ostringstream command;
267 command << "vconftool -g 5000 set -t int ";
268 command << (*it).first;
269 command << " \"" << static_cast<int>((*it).second) << "\"";
270 int ret = system(command.str().c_str());
272 ThrowMsg(Exceptions::CreateVconfFailure,
273 "Failed to create vconf files");
278 void TaskDatabase::StepAbortDBInsert()
280 LogWarning("[DB Update Task] Aborting... (DB Clean)");
283 WidgetDAO::unregisterWidget(m_context.widgetConfig.tzAppid);
284 LogDebug("Cleaning DB successful!");
286 Catch(DPL::DB::SqlConnection::Exception::Base)
288 LogError("Failed to handle StepAbortDBClean!");
291 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
292 // Remove also old one. If it was already updated nothing wrong will happen,
293 // but if not old widget will be removed.
294 if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
295 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
299 void TaskDatabase::StepLiveboxDBInsert()
301 if (m_context.widgetConfig.configInfo.m_livebox.size() <= 0) {
305 std::string tizenId = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
307 // insert specific information to web livebox db
308 for (auto it = m_context.widgetConfig.configInfo.m_livebox.begin();
309 it != m_context.widgetConfig.configInfo.m_livebox.end(); ++it)
311 std::string boxId = DPL::ToUTF8String((**it).m_liveboxId);
313 if ((**it).m_type.empty()) {
314 boxType = web_provider_livebox_get_default_type();
316 boxType = DPL::ToUTF8String((**it).m_type);
318 LogInfo("livebox id: " << boxId);
319 LogInfo("livebox type: " << boxType);
321 int autoLaunch = (**it).m_autoLaunch == L"true" ? 1 : 0;
322 LogInfo("livebox auto-launch: " << autoLaunch);
324 int mouseEvent = (**it).m_boxInfo.m_boxMouseEvent == L"true" ? 1 : 0;
325 LogInfo("livebox mouse-event: " << mouseEvent);
327 int pdFastOpen = (**it).m_boxInfo.m_pdFastOpen == L"true" ? 1 : 0;
328 LogInfo("livebox pd fast-open: " << pdFastOpen);
330 web_provider_livebox_insert_box_info(
331 boxId.c_str(), tizenId.c_str(), boxType.c_str(),
332 autoLaunch, mouseEvent, pdFastOpen);
335 } //namespace WidgetInstall