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_db_update.cpp
18 * @author Lukasz Wrzosek(l.wrzosek@samsung.com)
20 * @brief Implementation file for uninstaller task database updating
24 #include <web_provider_livebox_info.h>
26 #include <widget_uninstall/task_db_update.h>
27 #include <widget_uninstall/job_widget_uninstall.h>
28 #include <widget_uninstall/widget_uninstall_errors.h>
29 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30 #include <dpl/utils/wrt_utility.h>
31 #include <dpl/utils/path.h>
32 #include <ace_api_install.h>
33 #include <dpl/assert.h>
34 #include <ace-common/ace_api_common.h>
35 #include <dpl/wrt-dao-rw/widget_dao.h>
36 #include <installer_log.h>
38 using namespace WrtDB;
41 namespace WidgetUninstall {
42 TaskDbUpdate::TaskDbUpdate(UninstallerContext& context) :
43 DPL::TaskDecl<TaskDbUpdate>(this),
46 AddStep(&TaskDbUpdate::StartStep);
47 AddStep(&TaskDbUpdate::StepRemoveExternalLocations);
48 AddStep(&TaskDbUpdate::StepDbUpdate);
50 AddStep(&TaskDbUpdate::StepLiveboxDBDelete);
52 AddStep(&TaskDbUpdate::EndStep);
55 TaskDbUpdate::~TaskDbUpdate()
58 void TaskDbUpdate::StepDbUpdate()
62 //TODO: widget handle should not be used any more
63 FOREACH(it , m_context.tzAppIdList){
64 ace_unregister_widget(static_cast<ace_widget_handle_t>(WidgetDAOReadOnly::getHandle(*it)));
65 WidgetDAO::unregisterWidget(*it);
67 _D("Unregistered widget successfully!");
69 Catch(DPL::DB::SqlConnection::Exception::Base)
71 _E("Failed to handle StepDbUpdate!");
72 ReThrowMsg(Exceptions::DatabaseFailure,
73 "Failed to handle StepDbUpdate!");
78 void TaskDbUpdate::StepLiveboxDBDelete()
80 FOREACH(it, m_context.tzAppIdList){
82 web_provider_livebox_delete_by_app_id(DPL::ToUTF8String(*it).c_str());
85 _D("failed to delete box info");
87 _D("delete box info: %s", it);
93 void TaskDbUpdate::StepRemoveExternalLocations()
95 if (!m_context.removeAbnormal) {
96 FOREACH(it, m_context.tzAppIdList){
98 _D("Removing external locations:");
99 WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
100 FOREACH(file, externalPaths)
102 DPL::Utils::Path path(*file);
105 _D(" -> %s", path.Fullpath().c_str());
107 DPL::Utils::Remove(path);
108 } Catch(DPL::Utils::Path::BaseException){
109 _E("Failed to remove the file: %s", path.Fullpath().c_str());
111 } else if (path.IsDir()){
112 _D(" -> %s", path.Fullpath().c_str());
114 DPL::Utils::Remove(path);
115 } Catch(DPL::Utils::Path::BaseException){
116 Throw(Jobs::WidgetUninstall::TaskDbUpdate::
117 Exception::RemoveFilesFailed);
121 _W(" -> %s(no such a path)", path.Fullpath().c_str());
124 dao.unregisterAllExternalLocations();
129 void TaskDbUpdate::StartStep()
131 LOGD("--------- <TaskDbUpdate> : START ----------");
134 void TaskDbUpdate::EndStep()
136 m_context.job->UpdateProgress(
137 UninstallerContext::UNINSTALL_DB_UPDATE,
138 "Widget DB Update Finished");
140 LOGD("--------- <TaskDbUpdate> : END ----------");
142 } //namespace WidgetUninstall