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-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>
40 #include <ace_api_install.h>
41 #include <ace_registration.h>
47 using namespace WrtDB;
50 namespace WidgetInstall {
51 TaskDatabase::TaskDatabase(InstallerContext& context) :
52 DPL::TaskDecl<TaskDatabase>(this),
54 m_handleToRemove(INVALID_WIDGET_HANDLE),
55 m_handle(INVALID_WIDGET_HANDLE)
57 AddStep(&TaskDatabase::StepRegisterExternalFiles);
58 AddStep(&TaskDatabase::StepWrtDBInsert);
59 AddStep(&TaskDatabase::StepAceDBInsert);
60 AddStep(&TaskDatabase::StepRemoveExternalFiles);
61 AddStep(&TaskDatabase::StepCreateVconf);
62 AddStep(&TaskDatabase::StepLiveboxDBInsert);
64 AddAbortStep(&TaskDatabase::StepAbortDBInsert);
67 void TaskDatabase::StepWrtDBInsert()
71 /* Set install Time */
72 time(&m_context.widgetConfig.installedTime);
74 if (m_context.existingWidgetInfo.isExist) { //update
75 LogInfo("Registering widget... (update)");
78 m_handleToRemove = WidgetDAOReadOnly::getHandle(
79 m_context.widgetConfig.tzAppid);
81 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
84 "Given tizenId not found for update installation (Same GUID?)");
85 ThrowMsg(Exceptions::InvalidPackage,
86 "Given tizenId not found for update installation");
88 WidgetDAO::registerOrUpdateWidget(
89 m_context.widgetConfig.tzAppid,
90 m_context.widgetConfig,
91 m_context.wacSecurity);
92 m_handle = WidgetDAOReadOnly::getHandle(
93 m_context.widgetConfig.tzAppid);
94 } else { //new installation
95 LogInfo("Registering widget...");
96 WidgetDAO::registerWidget(
97 m_context.widgetConfig.tzAppid,
98 m_context.widgetConfig,
99 m_context.wacSecurity);
100 m_handle = WidgetDAOReadOnly::getHandle(
101 m_context.widgetConfig.tzAppid);
104 FOREACH(cap, m_context.staticPermittedDevCaps) {
106 "staticPermittedDevCaps : " << cap->first
107 << " smack status: " <<
111 LogInfo("Widget registered");
113 Catch(WidgetDAO::Exception::DatabaseError)
115 LogError("Database failure!");
116 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
118 Catch(DPL::DB::SqlConnection::Exception::Base)
120 LogError("Database failure!");
121 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
125 void TaskDatabase::StepAceDBInsert()
127 LogDebug("Inserting Ace database entry. New handle: " << m_handle);
128 if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
129 LogDebug("Removing old insallation. Handle: " << m_handleToRemove);
130 if (ACE_OK != ace_unregister_widget(
131 static_cast<ace_widget_handle_t>(m_handleToRemove)))
134 "Error while removing ace entry for previous insallation");
138 if (!AceApi::registerAceWidget(m_handle, m_context.widgetConfig,
139 m_context.wacSecurity.getCertificateList()))
141 LogError("ace database insert failed");
142 ThrowMsg(Exceptions::UpdateFailed,
143 "Update failure. ace_register_widget failed");
145 LogDebug("Ace data inserted");
147 m_context.job->UpdateProgress(
148 InstallerContext::INSTALL_NEW_DB_INSERT,
149 "New Widget DB UPDATE Finished");
152 void TaskDatabase::StepRegisterExternalFiles()
154 WrtDB::ExternalLocationList externalLocationsUpdate =
155 m_context.locations->listExternalLocations();
156 if (m_context.existingWidgetInfo.isExist) { //update
159 WidgetDAO dao(m_context.widgetConfig.tzAppid);
160 WrtDB::ExternalLocationList externalLocationsDB =
161 dao.getWidgetExternalLocations();
162 FOREACH(file, externalLocationsDB)
164 if (std::find(externalLocationsUpdate.begin(),
165 externalLocationsUpdate.end(),
166 *file) == externalLocationsUpdate.end())
168 m_externalLocationsToRemove.push_back(*file);
172 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
175 "Given tizenId not found for update installation (Same GUID?)");
176 ThrowMsg(Exceptions::UpdateFailed,
177 "Given tizenId not found for update installation");
180 LogDebug("Registering external files:");
181 FOREACH(file, externalLocationsUpdate)
183 LogDebug(" -> " << *file);
186 //set external locations to be registered
187 m_context.widgetConfig.externalLocations = externalLocationsUpdate;
190 void TaskDatabase::StepRemoveExternalFiles()
192 if (!m_externalLocationsToRemove.empty()) {
193 LogDebug("Removing external files:");
196 FOREACH(file, m_externalLocationsToRemove)
198 if (WrtUtilFileExists(*file)) {
199 LogDebug(" -> " << *file);
200 if (-1 == TEMP_FAILURE_RETRY(remove(file->c_str()))) {
201 ThrowMsg(Exceptions::RemovingFileFailure,
202 "Failed to remove external file");
204 } else if (WrtUtilDirExists(*file)) {
205 LogDebug(" -> " << *file);
206 if (!WrtUtilRemove(*file)) {
207 ThrowMsg(Exceptions::RemovingFolderFailure,
208 "Failed to remove external directory");
211 LogWarning(" -> " << *file << "(no such a path)");
216 void TaskDatabase::StepCreateVconf()
218 LogDebug("StepCreateVconf");
219 std::map<std::string, WrtDB::SettingsType> vconfData;
221 WrtDB::VconfConfig::GetVconfKeyPopupUsage(
222 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
224 WrtDB::VconfConfig::GetVconfKeyGeolocationUsage(
225 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
227 WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
228 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
230 WrtDB::VconfConfig::GetVconfKeyWebDatabaseUsage(
231 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
233 WrtDB::VconfConfig::GetVconfKeyFilesystemUsage(
234 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_ON;
236 WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
237 m_context.widgetConfig.tzAppid)] = WrtDB::SETTINGS_TYPE_OFF;
239 // vconftool -g 5000 set -t int <path> initialize value
240 // Current installer should use vconftool for setting group ID
241 // In case of install application by pkgcmd, permission for others
243 FOREACH(it, vconfData) {
244 std::ostringstream command;
245 command << "vconftool -g 5000 set -t int ";
246 command << (*it).first;
247 command << " \"" << static_cast<int>((*it).second) << "\"";
248 int ret = system(command.str().c_str());
250 ThrowMsg(Exceptions::CreateVconfFailure,
251 "Failed to create vconf files");
256 void TaskDatabase::StepAbortDBInsert()
258 LogWarning("[DB Update Task] Aborting... (DB Clean)");
261 WidgetDAO::unregisterWidget(m_context.widgetConfig.tzAppid);
262 LogDebug("Cleaning DB successful!");
264 Catch(DPL::DB::SqlConnection::Exception::Base)
266 LogError("Failed to handle StepAbortDBClean!");
269 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
270 // Remove also old one. If it was already updated nothing wrong will happen,
271 // but if not old widget will be removed.
272 if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
273 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
277 void TaskDatabase::StepLiveboxDBInsert()
279 if (m_context.widgetConfig.configInfo.m_livebox.size() <= 0) {
283 std::string tizenId = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
285 for (auto it = m_context.widgetConfig.configInfo.m_livebox.begin();
286 it != m_context.widgetConfig.configInfo.m_livebox.end(); ++it)
288 std::string boxId = DPL::ToUTF8String((**it).m_liveboxId);
290 if ((**it).m_type == L"") {
291 boxType = web_provider_info_get_default_type();
293 boxType = DPL::ToUTF8String((**it).m_type);
295 LogInfo("livebox id: " << boxId);
296 LogInfo("livebox type: " << boxType);
299 web_provider_info_insert_box_type(
300 boxId.c_str(), tizenId.c_str(), boxType.c_str());
303 LogDebug("failed to set type of livebox: " << boxId);
307 } //namespace WidgetInstall