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>
26 #include <app2ext_interface.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(const std::string & widgetPkgName,
60 const WidgetUninstallationStruct &uninstallerStruct) :
62 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
64 using namespace PackageManager;
65 m_context.removeStarted = false;
66 m_context.removeFinished = false;
67 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
69 m_context.pkgname = widgetPkgName;
70 m_context.isExternalWidget = getExternalWidgetFlag();
74 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(widgetPkgName));
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.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
83 AddTask(new TaskUninstallOspsvc(m_context));
85 AddTask(new TaskRemoveFiles(m_context));
86 AddTask(new TaskDbUpdate(m_context));
87 AddTask(new TaskDeleteCertificates(m_context));
89 // send start signal of pkgmgr
90 if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.pkgname)) {
91 getInstallerStruct().pkgmgrInterface->sendSignal(
93 PKGMGR_START_UNINSTALL);
95 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
96 AddTask(new UninstallerTaskFail(true));
97 } Catch (WidgetDAOReadOnly::Exception::Base) {
98 AddTask(new UninstallerTaskFail(false));
102 std::string JobWidgetUninstall::getRemovedTizenId() const
104 return m_context.pkgname;
107 bool JobWidgetUninstall::getRemoveStartedFlag() const
109 return m_context.removeStarted;
112 bool JobWidgetUninstall::getRemoveFinishedFlag() const
114 return m_context.removeFinished;
117 void JobWidgetUninstall::SendProgress()
119 using namespace PackageManager;
120 if (!getRemoveStartedFlag() ||
121 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
122 if (NULL != getInstallerStruct().progressCallback) {
123 // send progress signal of pkgmgr
124 std::ostringstream percent;
125 percent << static_cast<int>(GetProgressPercent());
126 getInstallerStruct().pkgmgrInterface->sendSignal(
130 LogDebug("Call widget uninstall progressCallback");
131 getInstallerStruct().progressCallback(
132 getInstallerStruct().userParam,
133 GetProgressPercent(), GetProgressDescription());
138 void JobWidgetUninstall::SendFinishedSuccess()
140 using namespace PackageManager;
141 // send signal of pkgmgr
142 getInstallerStruct().pkgmgrInterface->sendSignal(
146 LogDebug("Call widget uninstall success finishedCallback");
147 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
148 getRemovedTizenId(),Exceptions::Success);
151 void JobWidgetUninstall::SendFinishedFailure()
153 using namespace PackageManager;
154 LogError("Error in uninstallation step: " << m_exceptionCaught);
155 LogError("Message: " << m_exceptionMessage);
157 // send signal of pkgmgr
158 getInstallerStruct().pkgmgrInterface->sendSignal(
162 LogDebug("Call widget uninstall failure finishedCallback");
163 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
164 getRemovedTizenId(), m_exceptionCaught); //TODO
165 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
168 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
170 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
171 m_exceptionMessage = e.GetMessage();
174 bool JobWidgetUninstall::getExternalWidgetFlag() const
177 LogDebug("Get external widget");
178 if (APP2EXT_SD_CARD == app2ext_get_app_location(m_context.pkgname.c_str())) {
179 LogDebug("This widget is in external stroage");
185 } //namespace WidgetUninstall