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.
16 #include <widget_uninstall/job_widget_uninstall.h>
17 #include <widget_uninstall/widget_uninstall_errors.h>
18 #include <widget_uninstall/task_check.h>
19 #include <widget_uninstall/task_db_update.h>
20 #include <widget_uninstall/task_remove_files.h>
21 #include <widget_uninstall/task_smack.h>
22 #include <widget_uninstall/task_uninstall_ospsvc.h>
23 #include <pkg-manager/pkgmgr_signal.h>
25 using namespace WrtDB;
27 namespace { //anonymous
28 class UninstallerTaskFail :
29 public DPL::TaskDecl<UninstallerTaskFail>
37 ThrowMsg(Jobs::WidgetUninstall::Exceptions::WidgetNotExist,
38 "Widget does not exist");
40 Throw(Jobs::WidgetUninstall::Exceptions::Base);
45 UninstallerTaskFail(bool uninstalled) :
46 DPL::TaskDecl<UninstallerTaskFail>(this),
47 m_uninstalled(uninstalled)
49 AddStep(&UninstallerTaskFail::StepFail);
55 namespace WidgetUninstall {
56 JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
57 const WidgetUninstallationStruct &uninstallerStruct) :
59 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
61 using namespace PackageManager;
62 m_context.widgetHandle = widgetHandle;
63 m_context.removeStarted = false;
64 m_context.removeFinished = false;
65 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
69 WrtDB::WidgetDAOReadOnly dao(widgetHandle);
70 m_context.pkgname = DPL::ToUTF8String(*dao.getPkgname());
71 LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
73 AddTask(new TaskSmack(m_context));
74 AddTask(new TaskCheck(m_context));
76 if (dao.getPkgType() == PKG_TYPE_TIZEN_WITHSVCAPP) {
77 AddTask(new TaskUninstallOspsvc(m_context));
79 AddTask(new TaskRemoveFiles(m_context));
80 AddTask(new TaskDbUpdate(m_context));
82 // send start signal of pkgmgr
83 if (PkgmgrSignalSingleton::Instance().setPkgname(m_context.pkgname)) {
84 PkgmgrSignalSingleton::Instance().sendSignal(
86 PKGMGR_START_UNINSTALL);
89 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
90 AddTask(new UninstallerTaskFail(true));
91 } Catch (WidgetDAOReadOnly::Exception::Base) {
92 AddTask(new UninstallerTaskFail(false));
96 WidgetHandle JobWidgetUninstall::getRemovedWidgetHandle() const
98 return m_context.widgetHandle;
101 bool JobWidgetUninstall::getRemoveStartedFlag() const
103 return m_context.removeStarted;
106 bool JobWidgetUninstall::getRemoveFinishedFlag() const
108 return m_context.removeFinished;
111 void JobWidgetUninstall::SendProgress()
113 using namespace PackageManager;
114 if (!getRemoveStartedFlag() ||
115 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
116 if (NULL != getInstallerStruct().progressCallback) {
117 // send progress signal of pkgmgr
118 std::ostringstream percent;
119 percent << static_cast<int>(GetProgressPercent());
120 PkgmgrSignalSingleton::Instance().sendSignal(
124 LogDebug("Call widget uninstall progressCallback");
125 getInstallerStruct().progressCallback(
126 getInstallerStruct().userParam,
127 GetProgressPercent(), GetProgressDescription());
132 void JobWidgetUninstall::SendFinishedSuccess()
134 using namespace PackageManager;
135 // send signal of pkgmgr
136 PkgmgrSignalSingleton::Instance().sendSignal(
140 LogDebug("Call widget uninstall success finishedCallback");
141 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
142 getRemovedWidgetHandle(),Exceptions::Success);
145 void JobWidgetUninstall::SendFinishedFailure()
147 using namespace PackageManager;
148 LogError("Error in uninstallation step: " << m_exceptionCaught);
149 LogError("Message: " << m_exceptionMessage);
151 // send signal of pkgmgr
152 PkgmgrSignalSingleton::Instance().sendSignal(
156 LogDebug("Call widget uninstall failure finishedCallback");
157 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
158 getRemovedWidgetHandle(), m_exceptionCaught); //TODO
159 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
162 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
164 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
165 m_exceptionMessage = e.GetMessage();
167 } //namespace WidgetUninstall