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 #include <dpl/utils/file_utils.h>
19 #include <widget_uninstall/job_widget_uninstall.h>
20 #include <widget_uninstall/widget_uninstall_errors.h>
21 #include <widget_uninstall/task_check.h>
22 #include <widget_uninstall/task_db_update.h>
23 #include <widget_uninstall/task_remove_files.h>
24 #include <widget_uninstall/task_smack.h>
25 #include <widget_uninstall/task_uninstall_ospsvc.h>
26 #include <pkg-manager/pkgmgr_signal.h>
28 using namespace WrtDB;
30 namespace { //anonymous
31 class UninstallerTaskFail :
32 public DPL::TaskDecl<UninstallerTaskFail>
40 ThrowMsg(Jobs::WidgetUninstall::Exceptions::WidgetNotExist,
41 "Widget does not exist");
43 Throw(Jobs::WidgetUninstall::Exceptions::Base);
48 UninstallerTaskFail(bool uninstalled) :
49 DPL::TaskDecl<UninstallerTaskFail>(this),
50 m_uninstalled(uninstalled)
52 AddStep(&UninstallerTaskFail::StepFail);
58 namespace WidgetUninstall {
59 JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
60 const WidgetUninstallationStruct &uninstallerStruct) :
62 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
64 using namespace PackageManager;
65 m_context.widgetHandle = widgetHandle;
66 m_context.removeStarted = false;
67 m_context.removeFinished = false;
68 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
73 WrtDB::WidgetDAOReadOnly dao(widgetHandle);
74 m_context.pkgname = DPL::ToUTF8String(*dao.getPkgname());
75 m_context.locations = WidgetLocation(m_context.pkgname);
77 LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
79 AddTask(new TaskSmack(m_context));
80 AddTask(new TaskCheck(m_context));
82 if (dao.getPkgType() == PKG_TYPE_TIZEN_WITHSVCAPP) {
83 AddTask(new TaskUninstallOspsvc(m_context));
85 AddTask(new TaskRemoveFiles(m_context));
86 AddTask(new TaskDbUpdate(m_context));
88 // send start signal of pkgmgr
89 if (PkgmgrSignalSingleton::Instance().setPkgname(m_context.pkgname)) {
90 PkgmgrSignalSingleton::Instance().sendSignal(
92 PKGMGR_START_UNINSTALL);
94 } Catch(FileUtils::CreateDirectoryException) {
95 LogError("Failed to create temporary path for widget");
96 AddTask(new UninstallerTaskFail(false));
97 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
98 AddTask(new UninstallerTaskFail(true));
99 } Catch (WidgetDAOReadOnly::Exception::Base) {
100 AddTask(new UninstallerTaskFail(false));
104 WidgetHandle JobWidgetUninstall::getRemovedWidgetHandle() const
106 return m_context.widgetHandle;
109 bool JobWidgetUninstall::getRemoveStartedFlag() const
111 return m_context.removeStarted;
114 bool JobWidgetUninstall::getRemoveFinishedFlag() const
116 return m_context.removeFinished;
119 void JobWidgetUninstall::SendProgress()
121 using namespace PackageManager;
122 if (!getRemoveStartedFlag() ||
123 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
124 if (NULL != getInstallerStruct().progressCallback) {
125 // send progress signal of pkgmgr
126 std::ostringstream percent;
127 percent << static_cast<int>(GetProgressPercent());
128 PkgmgrSignalSingleton::Instance().sendSignal(
132 LogDebug("Call widget uninstall progressCallback");
133 getInstallerStruct().progressCallback(
134 getInstallerStruct().userParam,
135 GetProgressPercent(), GetProgressDescription());
140 void JobWidgetUninstall::SendFinishedSuccess()
142 using namespace PackageManager;
143 // send signal of pkgmgr
144 PkgmgrSignalSingleton::Instance().sendSignal(
148 LogDebug("Call widget uninstall success finishedCallback");
149 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
150 getRemovedWidgetHandle(),Exceptions::Success);
153 void JobWidgetUninstall::SendFinishedFailure()
155 using namespace PackageManager;
156 LogError("Error in uninstallation step: " << m_exceptionCaught);
157 LogError("Message: " << m_exceptionMessage);
159 // send signal of pkgmgr
160 PkgmgrSignalSingleton::Instance().sendSignal(
164 LogDebug("Call widget uninstall failure finishedCallback");
165 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
166 getRemovedWidgetHandle(), m_exceptionCaught); //TODO
167 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
170 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
172 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
173 m_exceptionMessage = e.GetMessage();
175 } //namespace WidgetUninstall