0c391fd13dfdde283c2303144cac0abf6ae74a2e
[framework/web/wrt-installer.git] / src_wearable / jobs / widget_uninstall / task_db_update.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_db_update.cpp
18  * @author  Lukasz Wrzosek(l.wrzosek@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for uninstaller task database updating
21  */
22
23 #ifdef DBOX_ENABLED
24 #include <web_provider_livebox_info.h>
25 #endif
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>
37
38 using namespace WrtDB;
39
40 namespace Jobs {
41 namespace WidgetUninstall {
42 TaskDbUpdate::TaskDbUpdate(UninstallerContext& context) :
43     DPL::TaskDecl<TaskDbUpdate>(this),
44     m_context(context)
45 {
46     AddStep(&TaskDbUpdate::StartStep);
47     AddStep(&TaskDbUpdate::StepRemoveExternalLocations);
48     AddStep(&TaskDbUpdate::StepDbUpdate);
49 #ifdef DBOX_ENABLED
50     AddStep(&TaskDbUpdate::StepLiveboxDBDelete);
51 #endif
52     AddStep(&TaskDbUpdate::EndStep);
53 }
54
55 TaskDbUpdate::~TaskDbUpdate()
56 {}
57
58 void TaskDbUpdate::StepDbUpdate()
59 {
60     Try
61     {
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);
66         }
67         _D("Unregistered widget successfully!");
68     }
69     Catch(DPL::DB::SqlConnection::Exception::Base)
70     {
71         _E("Failed to handle StepDbUpdate!");
72         ReThrowMsg(Exceptions::DatabaseFailure,
73                    "Failed to handle StepDbUpdate!");
74     }
75 }
76
77 #ifdef DBOX_ENABLED
78 void TaskDbUpdate::StepLiveboxDBDelete()
79 {
80     FOREACH(it, m_context.tzAppIdList){
81     int ret =
82             web_provider_livebox_delete_by_app_id(DPL::ToUTF8String(*it).c_str());
83
84     if (ret < 0) {
85         _D("failed to delete box info");
86     } else {
87             _D("delete box info: %s", it);
88         }
89     }
90 }
91 #endif
92
93 void TaskDbUpdate::StepRemoveExternalLocations()
94 {
95     if (!m_context.removeAbnormal) {
96         FOREACH(it, m_context.tzAppIdList){
97             WidgetDAO dao(*it);
98             _D("Removing external locations:");
99             WrtDB::ExternalLocationList externalPaths = dao.getWidgetExternalLocations();
100             FOREACH(file, externalPaths)
101             {
102                 DPL::Utils::Path path(*file);
103                 if(path.Exists()){
104                     if(path.IsFile()){
105                         _D("  -> %s", path.Fullpath().c_str());
106                         Try {
107                             DPL::Utils::Remove(path);
108                         } Catch(DPL::Utils::Path::BaseException){
109                             _E("Failed to remove the file: %s", path.Fullpath().c_str());
110                         }
111                     } else if (path.IsDir()){
112                         _D("  -> %s", path.Fullpath().c_str());
113                         Try {
114                             DPL::Utils::Remove(path);
115                         } Catch(DPL::Utils::Path::BaseException){
116                             Throw(Jobs::WidgetUninstall::TaskDbUpdate::
117                                 Exception::RemoveFilesFailed);
118                         }
119                     }
120                 } else {
121                     _W("  -> %s(no such a path)", path.Fullpath().c_str());
122                 }
123             }
124             dao.unregisterAllExternalLocations();
125         }
126     }
127 }
128
129 void TaskDbUpdate::StartStep()
130 {
131     LOGD("--------- <TaskDbUpdate> : START ----------");
132 }
133
134 void TaskDbUpdate::EndStep()
135 {
136     m_context.job->UpdateProgress(
137         UninstallerContext::UNINSTALL_DB_UPDATE,
138         "Widget DB Update Finished");
139
140     LOGD("--------- <TaskDbUpdate> : END ----------");
141 }
142 } //namespace WidgetUninstall
143 } //namespace Jobs