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(const std::string & widgetPkgName,
59 const WidgetUninstallationStruct &uninstallerStruct) :
61 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
63 using namespace PackageManager;
64 m_context.removeStarted = false;
65 m_context.removeFinished = false;
66 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
68 m_context.pkgname = widgetPkgName;
72 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(widgetPkgName));
73 m_context.locations = WidgetLocation(m_context.pkgname);
75 LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
77 AddTask(new TaskSmack(m_context));
78 AddTask(new TaskCheck(m_context));
80 if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
81 AddTask(new TaskUninstallOspsvc(m_context));
83 AddTask(new TaskRemoveFiles(m_context));
84 AddTask(new TaskDbUpdate(m_context));
85 AddTask(new TaskDeleteCertificates(m_context));
87 // send start signal of pkgmgr
88 if (PkgmgrSignalSingleton::Instance().setPkgname(m_context.pkgname)) {
89 PkgmgrSignalSingleton::Instance().sendSignal(
91 PKGMGR_START_UNINSTALL);
93 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
94 AddTask(new UninstallerTaskFail(true));
95 } Catch (WidgetDAOReadOnly::Exception::Base) {
96 AddTask(new UninstallerTaskFail(false));
100 std::string JobWidgetUninstall::getRemovedTizenId() const
102 return m_context.pkgname;
105 bool JobWidgetUninstall::getRemoveStartedFlag() const
107 return m_context.removeStarted;
110 bool JobWidgetUninstall::getRemoveFinishedFlag() const
112 return m_context.removeFinished;
115 void JobWidgetUninstall::SendProgress()
117 using namespace PackageManager;
118 if (!getRemoveStartedFlag() ||
119 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
120 if (NULL != getInstallerStruct().progressCallback) {
121 // send progress signal of pkgmgr
122 std::ostringstream percent;
123 percent << static_cast<int>(GetProgressPercent());
124 PkgmgrSignalSingleton::Instance().sendSignal(
128 LogDebug("Call widget uninstall progressCallback");
129 getInstallerStruct().progressCallback(
130 getInstallerStruct().userParam,
131 GetProgressPercent(), GetProgressDescription());
136 void JobWidgetUninstall::SendFinishedSuccess()
138 using namespace PackageManager;
139 // send signal of pkgmgr
140 PkgmgrSignalSingleton::Instance().sendSignal(
144 LogDebug("Call widget uninstall success finishedCallback");
145 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
146 getRemovedTizenId(),Exceptions::Success);
149 void JobWidgetUninstall::SendFinishedFailure()
151 using namespace PackageManager;
152 LogError("Error in uninstallation step: " << m_exceptionCaught);
153 LogError("Message: " << m_exceptionMessage);
155 // send signal of pkgmgr
156 PkgmgrSignalSingleton::Instance().sendSignal(
160 LogDebug("Call widget uninstall failure finishedCallback");
161 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
162 getRemovedTizenId(), m_exceptionCaught); //TODO
163 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
166 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
168 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
169 m_exceptionMessage = e.GetMessage();
171 } //namespace WidgetUninstall