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 update
25 #include <widget_install/task_database.h>
26 #include <widget_install/job_widget_install.h>
27 #include <widget_install/widget_install_errors.h>
28 #include <widget_install/widget_install_context.h>
29 #include <dpl/wrt-dao-rw/widget_dao.h>
30 #include <dpl/wrt-dao-ro/vconf_config.h>
31 #include <dpl/foreach.h>
32 #include <dpl/utils/wrt_utility.h>
33 #include <dpl/log/log.h>
34 #include <dpl/assert.h>
37 #include <ace_api_install.h>
38 #include <ace_registration.h>
43 using namespace WrtDB;
46 namespace WidgetInstall {
48 TaskDatabase::TaskDatabase(InstallerContext& context) :
49 DPL::TaskDecl<TaskDatabase>(this),
51 m_handleToRemove(INVALID_WIDGET_HANDLE),
52 m_handle(INVALID_WIDGET_HANDLE)
54 AddStep(&TaskDatabase::StepRegisterExternalFiles);
55 AddStep(&TaskDatabase::StepWrtDBInsert);
56 AddStep(&TaskDatabase::StepAceDBInsert);
57 AddStep(&TaskDatabase::StepRemoveExternalFiles);
58 AddStep(&TaskDatabase::StepCreateVconf);
60 AddAbortStep(&TaskDatabase::StepAbortDBInsert);
63 void TaskDatabase::StepWrtDBInsert()
67 /* Set install Time */
68 time(&m_context.widgetConfig.installedTime);
70 if (m_context.existingWidgetInfo.isExist) //update
72 m_handleToRemove = WidgetDAOReadOnly::getHandle(
73 m_context.locations->getPkgname());
74 LogInfo("Registering widget... (update)");
75 WidgetDAO::registerOrUpdateWidget(
76 m_context.locations->getPkgname(),
77 m_context.widgetConfig,
78 m_context.wacSecurity);
79 m_handle = WidgetDAOReadOnly::getHandle(
80 m_context.locations->getPkgname());
82 else //new installation
84 LogInfo("Registering widget...");
85 WidgetDAO::registerWidget(
86 m_context.locations->getPkgname(),
87 m_context.widgetConfig,
88 m_context.wacSecurity);
89 m_handle = WidgetDAOReadOnly::getHandle(
90 m_context.locations->getPkgname());
93 FOREACH (cap, m_context.staticPermittedDevCaps) {
94 LogInfo("staticPermittedDevCaps : " << cap->first
95 << " smack status: " << cap->second);
98 LogInfo("Widget registered");
100 Catch(WidgetDAO::Exception::DatabaseError)
102 LogError("Database failure!");
103 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
105 Catch(DPL::DB::SqlConnection::Exception::Base)
107 LogError("Database failure!");
108 ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
112 void TaskDatabase::StepAceDBInsert()
114 LogDebug("Inserting Ace database entry. New handle: " << m_handle);
115 if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
116 LogDebug("Removing old insallation. Handle: " << m_handleToRemove);
117 if (ACE_OK != ace_unregister_widget(
118 static_cast<ace_widget_handle_t>(m_handleToRemove)))
120 LogWarning("Error while removing ace entry for previous insallation");
124 if(!AceApi::registerAceWidget(m_handle, m_context.widgetConfig,
125 m_context.wacSecurity.getCertificateList()))
127 LogError("ace database insert failed");
128 ThrowMsg(Exceptions::NotAllowed, "Update failure. ace_register_widget failed");
130 LogDebug("Ace data inserted");
132 m_context.job->UpdateProgress(
133 InstallerContext::INSTALL_NEW_DB_INSERT,
134 "New Widget DB UPDATE Finished");
137 void TaskDatabase::StepRegisterExternalFiles()
139 WrtDB::ExternalLocationList externalLocationsUpdate = m_context.locations->listExternalLocations();
140 if (m_context.existingWidgetInfo.isExist) //update
142 WidgetDAO dao(m_context.locations->getPkgname());
143 WrtDB::ExternalLocationList externalLocationsDB = dao.getWidgetExternalLocations();
144 FOREACH(file, externalLocationsDB)
146 if(std::find(externalLocationsUpdate.begin(), externalLocationsUpdate.end(), *file) == externalLocationsUpdate.end())
148 m_externalLocationsToRemove.push_back(*file);
152 LogDebug("Registering external files:");
153 FOREACH(file, externalLocationsUpdate)
155 LogDebug(" -> " << *file);
158 //set external locations to be registered
159 m_context.widgetConfig.externalLocations = externalLocationsUpdate;
162 void TaskDatabase::StepRemoveExternalFiles()
164 if(!m_externalLocationsToRemove.empty())
166 LogDebug("Removing external files:");
169 FOREACH(file, m_externalLocationsToRemove)
171 if(WrtUtilFileExists(*file))
173 LogDebug(" -> " << *file);
174 remove(file->c_str());
176 else if(WrtUtilDirExists(*file))
178 LogDebug(" -> " << *file);
179 if(!WrtUtilRemove(*file)){
180 ThrowMsg(Exceptions::RemovingFolderFailure,
181 "Failed to remove external directory");
186 LogWarning(" -> " << *file << "(no such a path)");
191 void TaskDatabase::StepCreateVconf()
193 LogDebug("StepCreateVconf");
194 std::string popupUsageKey =
195 WrtDB::VconfConfig::GetVconfKeyPopupUsage(
196 m_context.locations->getPkgname());
197 std::string geolocationUsageKey =
198 WrtDB::VconfConfig::GetVconfKeyGeolocationUsage(
199 m_context.locations->getPkgname());
200 std::string webNotificationUsageKey =
201 WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
202 m_context.locations->getPkgname());
203 std::string webDatabaseUsageKey =
204 WrtDB::VconfConfig::GetVconfKeyWebDatabaseUsage(
205 m_context.locations->getPkgname());
206 std::string filesystemUsageKey =
207 WrtDB::VconfConfig::GetVconfKeyFilesystemUsage(
208 m_context.locations->getPkgname());
209 std::string memorySavingModeKey =
210 WrtDB::VconfConfig::GetVconfKeyMemorySavingMode(
211 m_context.locations->getPkgname());
213 vconf_set_int(popupUsageKey.c_str(),
214 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
215 // prevent permission error
216 vconf_unset(popupUsageKey.c_str());
217 vconf_set_int(popupUsageKey.c_str(),
218 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
219 vconf_set_int(geolocationUsageKey.c_str(),
220 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
221 vconf_set_int(webNotificationUsageKey.c_str(),
222 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
223 vconf_set_int(webDatabaseUsageKey.c_str(),
224 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
225 vconf_set_int(filesystemUsageKey.c_str(),
226 static_cast<int>(WrtDB::SETTINGS_TYPE_ON));
227 vconf_set_int(memorySavingModeKey.c_str(),
228 static_cast<int>(WrtDB::SETTINGS_TYPE_OFF));
231 void TaskDatabase::StepAbortDBInsert()
233 LogWarning("[DB Update Task] Aborting... (DB Clean)");
236 WidgetDAO::unregisterWidget(m_context.locations->getPkgname());
237 LogDebug("Cleaning DB successful!");
239 Catch(DPL::DB::SqlConnection::Exception::Base)
241 LogError("Failed to handle StepAbortDBClean!");
244 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
245 // Remove also old one. If it was already updated nothing wrong will happen,
246 // but if not old widget will be removed.
247 if (INVALID_WIDGET_HANDLE != m_handleToRemove)
248 ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
251 } //namespace WidgetInstall