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_remove_custom_handlers.h>
23 #include <widget_uninstall/task_smack.h>
24 #include <widget_uninstall/task_uninstall_ospsvc.h>
25 #include <widget_uninstall/task_delete_certificates.h>
26 #include <pkg-manager/pkgmgr_signal.h>
27 #include <app2ext_interface.h>
29 using namespace WrtDB;
31 namespace { //anonymous
32 class UninstallerTaskFail :
33 public DPL::TaskDecl<UninstallerTaskFail>
41 ThrowMsg(Jobs::WidgetUninstall::Exceptions::WidgetNotExist,
42 "Widget does not exist");
44 Throw(Jobs::WidgetUninstall::Exceptions::Base);
49 UninstallerTaskFail(bool uninstalled) :
50 DPL::TaskDecl<UninstallerTaskFail>(this),
51 m_uninstalled(uninstalled)
53 AddStep(&UninstallerTaskFail::StepFail);
59 namespace WidgetUninstall {
60 JobWidgetUninstall::JobWidgetUninstall(const std::string & widgetPkgName,
61 const WidgetUninstallationStruct &uninstallerStruct) :
63 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
65 using namespace PackageManager;
66 m_context.removeStarted = false;
67 m_context.removeFinished = false;
68 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
70 m_context.pkgname = widgetPkgName;
71 m_context.isExternalWidget = getExternalWidgetFlag();
75 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(widgetPkgName));
76 m_context.locations = WidgetLocation(m_context.pkgname);
78 LogInfo("Widget model exists. Pkg name: " << m_context.pkgname);
80 AddTask(new TaskSmack(m_context));
81 AddTask(new TaskCheck(m_context));
83 if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
84 AddTask(new TaskUninstallOspsvc(m_context));
86 AddTask(new TaskRemoveFiles(m_context));
87 AddTask(new TaskDbUpdate(m_context));
88 AddTask(new TaskRemoveCustomHandlers(m_context));
89 AddTask(new TaskDeleteCertificates(m_context));
91 // send start signal of pkgmgr
92 if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.pkgname)) {
93 getInstallerStruct().pkgmgrInterface->sendSignal(
95 PKGMGR_START_UNINSTALL);
97 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
98 AddTask(new UninstallerTaskFail(true));
99 } Catch (WidgetDAOReadOnly::Exception::Base) {
100 AddTask(new UninstallerTaskFail(false));
104 std::string JobWidgetUninstall::getRemovedTizenId() const
106 return m_context.pkgname;
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 getInstallerStruct().pkgmgrInterface->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 getInstallerStruct().pkgmgrInterface->sendSignal(
148 LogDebug("Call widget uninstall success finishedCallback");
149 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
150 getRemovedTizenId(),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 getInstallerStruct().pkgmgrInterface->sendSignal(
164 LogDebug("Call widget uninstall failure finishedCallback");
165 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
166 getRemovedTizenId(), 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();
176 bool JobWidgetUninstall::getExternalWidgetFlag() const
179 LogDebug("Get external widget");
180 if (APP2EXT_SD_CARD == app2ext_get_app_location(m_context.pkgname.c_str())) {
181 LogDebug("This widget is in external stroage");
187 } //namespace WidgetUninstall