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 & tizenAppId,
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.tzAppid = tizenAppId;
71 m_context.isExternalWidget = getExternalWidgetFlag();
75 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(tizenAppId));
76 m_context.locations = WidgetLocation(m_context.tzAppid);
77 m_context.tzPkgid = DPL::ToUTF8String(dao.getTizenPkgId());
79 LogInfo("Widget model exists. Pkg name: " << m_context.tzAppid);
81 AddTask(new TaskSmack(m_context));
82 AddTask(new TaskCheck(m_context));
84 if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
85 AddTask(new TaskUninstallOspsvc(m_context));
87 AddTask(new TaskRemoveFiles(m_context));
88 AddTask(new TaskDbUpdate(m_context));
89 AddTask(new TaskRemoveCustomHandlers(m_context));
90 AddTask(new TaskDeleteCertificates(m_context));
92 // send start signal of pkgmgr
93 if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.tzAppid)) {
94 getInstallerStruct().pkgmgrInterface->sendSignal(
96 PKGMGR_START_UNINSTALL);
98 } Catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
99 AddTask(new UninstallerTaskFail(true));
100 } Catch (WidgetDAOReadOnly::Exception::Base) {
101 AddTask(new UninstallerTaskFail(false));
105 std::string JobWidgetUninstall::getRemovedTizenId() const
107 return m_context.tzAppid;
110 bool JobWidgetUninstall::getRemoveStartedFlag() const
112 return m_context.removeStarted;
115 bool JobWidgetUninstall::getRemoveFinishedFlag() const
117 return m_context.removeFinished;
120 void JobWidgetUninstall::SendProgress()
122 using namespace PackageManager;
123 if (!getRemoveStartedFlag() ||
124 (getRemoveStartedFlag() && getRemoveFinishedFlag())) {
125 if (NULL != getInstallerStruct().progressCallback) {
126 // send progress signal of pkgmgr
127 std::ostringstream percent;
128 percent << static_cast<int>(GetProgressPercent());
129 getInstallerStruct().pkgmgrInterface->sendSignal(
133 LogDebug("Call widget uninstall progressCallback");
134 getInstallerStruct().progressCallback(
135 getInstallerStruct().userParam,
136 GetProgressPercent(), GetProgressDescription());
141 void JobWidgetUninstall::SendFinishedSuccess()
143 using namespace PackageManager;
144 // send signal of pkgmgr
145 getInstallerStruct().pkgmgrInterface->sendSignal(
149 LogDebug("Call widget uninstall success finishedCallback");
150 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
151 getRemovedTizenId(),Exceptions::Success);
154 void JobWidgetUninstall::SendFinishedFailure()
156 using namespace PackageManager;
157 LogError("Error in uninstallation step: " << m_exceptionCaught);
158 LogError("Message: " << m_exceptionMessage);
160 // send signal of pkgmgr
161 getInstallerStruct().pkgmgrInterface->sendSignal(
165 LogDebug("Call widget uninstall failure finishedCallback");
166 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
167 getRemovedTizenId(), m_exceptionCaught); //TODO
168 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
171 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
173 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
174 m_exceptionMessage = e.GetMessage();
177 bool JobWidgetUninstall::getExternalWidgetFlag() const
180 LogDebug("Get external widget");
181 if (APP2EXT_SD_CARD == app2ext_get_app_location(m_context.tzAppid.c_str())) {
182 LogDebug("This widget is in external stroage");
188 } //namespace WidgetUninstall