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 <widget_uninstall/job_widget_uninstall.h>
18 #include <widget_uninstall/widget_uninstall_errors.h>
19 #include <widget_uninstall/task_check.h>
20 #include <widget_uninstall/task_db_update.h>
21 #include <widget_uninstall/task_remove_files.h>
22 #include <widget_uninstall/task_smack.h>
23 #include <widget_uninstall/task_uninstall_ospsvc.h>
24 #include <widget_uninstall/task_delete_certificates.h>
25 #include <pkg-manager/pkgmgr_signal.h>
27 using namespace WrtDB;
29 namespace { //anonymous
30 class UninstallerTaskFail :
31 public DPL::TaskDecl<UninstallerTaskFail>
39 ThrowMsg(Jobs::WidgetUninstall::Exceptions::WidgetNotExist,
40 "Widget does not exist");
42 Throw(Jobs::WidgetUninstall::Exceptions::Base);
47 UninstallerTaskFail(bool uninstalled) :
48 DPL::TaskDecl<UninstallerTaskFail>(this),
49 m_uninstalled(uninstalled)
51 AddStep(&UninstallerTaskFail::StepFail);
57 namespace WidgetUninstall {
58 JobWidgetUninstall::JobWidgetUninstall(WidgetHandle widgetHandle,
59 const WidgetUninstallationStruct &uninstallerStruct) :
61 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
63 using namespace PackageManager;
64 m_context.widgetHandle = widgetHandle;
65 m_context.removeStarted = false;
66 m_context.removeFinished = false;
67 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
72 WrtDB::WidgetDAOReadOnly dao(widgetHandle);
73 m_context.pkgname = DPL::ToUTF8String(*dao.getPkgname());
74 m_context.locations = WidgetLocation(m_context.pkgname);
76 LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
78 AddTask(new TaskSmack(m_context));
79 AddTask(new TaskCheck(m_context));
81 if (dao.getPkgType() == PKG_TYPE_TIZEN_WITHSVCAPP) {
82 AddTask(new TaskUninstallOspsvc(m_context));
84 AddTask(new TaskRemoveFiles(m_context));
85 AddTask(new TaskDbUpdate(m_context));
86 AddTask(new TaskDeleteCertificates(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 (WidgetDAOReadOnly::Exception::WidgetNotExist) {
95 AddTask(new UninstallerTaskFail(true));
96 } Catch (WidgetDAOReadOnly::Exception::Base) {
97 AddTask(new UninstallerTaskFail(false));
101 WidgetHandle JobWidgetUninstall::getRemovedWidgetHandle() const
103 return m_context.widgetHandle;
106 std::string JobWidgetUninstall::getRemovedTizenId() const
108 return m_context.pkgname;
111 bool JobWidgetUninstall::getRemoveStartedFlag() const
113 return m_context.removeStarted;
116 bool JobWidgetUninstall::getRemoveFinishedFlag() const
118 return m_context.removeFinished;
121 void JobWidgetUninstall::SendProgress()
123 using namespace PackageManager;
124 if (!getRemoveStartedFlag() ||
125 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
126 if (NULL != getInstallerStruct().progressCallback) {
127 // send progress signal of pkgmgr
128 std::ostringstream percent;
129 percent << static_cast<int>(GetProgressPercent());
130 PkgmgrSignalSingleton::Instance().sendSignal(
134 LogDebug("Call widget uninstall progressCallback");
135 getInstallerStruct().progressCallback(
136 getInstallerStruct().userParam,
137 GetProgressPercent(), GetProgressDescription());
142 void JobWidgetUninstall::SendFinishedSuccess()
144 using namespace PackageManager;
145 // send signal of pkgmgr
146 PkgmgrSignalSingleton::Instance().sendSignal(
150 LogDebug("Call widget uninstall success finishedCallback");
151 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
152 getRemovedTizenId(),Exceptions::Success);
155 void JobWidgetUninstall::SendFinishedFailure()
157 using namespace PackageManager;
158 LogError("Error in uninstallation step: " << m_exceptionCaught);
159 LogError("Message: " << m_exceptionMessage);
161 // send signal of pkgmgr
162 PkgmgrSignalSingleton::Instance().sendSignal(
166 LogDebug("Call widget uninstall failure finishedCallback");
167 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
168 getRemovedTizenId(), m_exceptionCaught); //TODO
169 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
172 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
174 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
175 m_exceptionMessage = e.GetMessage();
177 } //namespace WidgetUninstall