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.
18 #include <widget_uninstall/job_widget_uninstall.h>
19 #include <widget_uninstall/widget_uninstall_errors.h>
20 #include <widget_uninstall/task_check.h>
21 #include <widget_uninstall/task_db_update.h>
22 #include <widget_uninstall/task_remove_files.h>
23 #include <widget_uninstall/task_remove_custom_handlers.h>
24 #include <widget_uninstall/task_smack.h>
25 #include <widget_uninstall/task_uninstall_ospsvc.h>
26 #include <widget_uninstall/task_delete_certificates.h>
27 #include <pkg-manager/pkgmgr_signal.h>
28 #include <app2ext_interface.h>
30 using namespace WrtDB;
32 namespace { //anonymous
33 const char* REG_TIZEN_PKGID_PATTERN = "^[a-zA-Z0-9]{10}$";
34 class UninstallerTaskFail :
35 public DPL::TaskDecl<UninstallerTaskFail>
43 ThrowMsg(Jobs::WidgetUninstall::Exceptions::WidgetNotExist,
44 "Widget does not exist");
46 Throw(Jobs::WidgetUninstall::Exceptions::Base);
51 UninstallerTaskFail(bool uninstalled) :
52 DPL::TaskDecl<UninstallerTaskFail>(this),
53 m_uninstalled(uninstalled)
55 AddStep(&UninstallerTaskFail::StepFail);
61 namespace WidgetUninstall {
62 JobWidgetUninstall::JobWidgetUninstall(
63 const std::string & tizenAppId,
64 const WidgetUninstallationStruct &
67 JobContextBase<WidgetUninstallationStruct>(uninstallerStruct)
69 using namespace PackageManager;
70 m_context.removeStarted = false;
71 m_context.removeFinished = false;
72 m_context.uninstallStep = UninstallerContext::UNINSTALL_START;
74 m_context.isExternalWidget = getExternalWidgetFlag();
79 if(regcomp(®x, REG_TIZEN_PKGID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
80 LogDebug("Regcomp failed");
83 if ((regexec(®x, tizenAppId.c_str(),
84 static_cast<size_t>(0), NULL, 0) == REG_NOERROR)) {
86 WrtDB::WidgetDAOReadOnly::getTzAppId(
87 DPL::FromUTF8String(tizenAppId));
88 LogDebug("Get appid from pkgid : " << appid);
89 m_context.tzAppid = DPL::ToUTF8String(appid);
91 m_context.tzAppid = tizenAppId;
93 WrtDB::WidgetDAOReadOnly dao(DPL::FromUTF8String(m_context.tzAppid));
94 m_context.tzPkgid = DPL::ToUTF8String(dao.getTizenPkgId());
95 m_context.locations = WidgetLocation(m_context.tzPkgid);
96 m_context.locations->registerAppid(m_context.tzAppid);
98 LogInfo("Widget model exists. App id : " << m_context.tzAppid);
100 AddTask(new TaskSmack(m_context));
101 AddTask(new TaskCheck(m_context));
103 if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) {
104 AddTask(new TaskUninstallOspsvc(m_context));
106 AddTask(new TaskRemoveFiles(m_context));
107 AddTask(new TaskDbUpdate(m_context));
108 AddTask(new TaskRemoveCustomHandlers(m_context));
109 AddTask(new TaskDeleteCertificates(m_context));
111 // send start signal of pkgmgr
112 if (getInstallerStruct().pkgmgrInterface->setPkgname(m_context.tzAppid))
114 getInstallerStruct().pkgmgrInterface->sendSignal(
116 PKGMGR_START_UNINSTALL);
118 } Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
119 AddTask(new UninstallerTaskFail(true));
120 } Catch(WidgetDAOReadOnly::Exception::Base) {
121 AddTask(new UninstallerTaskFail(false));
125 std::string JobWidgetUninstall::getRemovedTizenId() const
127 return m_context.tzAppid;
130 bool JobWidgetUninstall::getRemoveStartedFlag() const
132 return m_context.removeStarted;
135 bool JobWidgetUninstall::getRemoveFinishedFlag() const
137 return m_context.removeFinished;
140 void JobWidgetUninstall::SendProgress()
142 using namespace PackageManager;
143 if (!getRemoveStartedFlag() ||
144 (getRemoveStartedFlag() && getRemoveFinishedFlag()))
146 if (NULL != getInstallerStruct().progressCallback) {
147 // send progress signal of pkgmgr
148 std::ostringstream percent;
149 percent << static_cast<int>(GetProgressPercent());
150 getInstallerStruct().pkgmgrInterface->sendSignal(
154 LogDebug("Call widget uninstall progressCallback");
155 getInstallerStruct().progressCallback(
156 getInstallerStruct().userParam,
157 GetProgressPercent(), GetProgressDescription());
162 void JobWidgetUninstall::SendFinishedSuccess()
164 using namespace PackageManager;
165 // send signal of pkgmgr
166 getInstallerStruct().pkgmgrInterface->sendSignal(
170 LogDebug("Call widget uninstall success finishedCallback");
171 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
173 Exceptions::Success);
176 void JobWidgetUninstall::SendFinishedFailure()
178 using namespace PackageManager;
179 LogError("Error in uninstallation step: " << m_exceptionCaught);
180 LogError("Message: " << m_exceptionMessage);
182 // send signal of pkgmgr
183 getInstallerStruct().pkgmgrInterface->sendSignal(
187 LogDebug("Call widget uninstall failure finishedCallback");
188 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
190 m_exceptionCaught); //TODO
191 LogDebug("[JobWidgetUninstall] Asynchronous failure callback status sent");
194 void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
196 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
197 m_exceptionMessage = e.GetMessage();
200 bool JobWidgetUninstall::getExternalWidgetFlag() const
202 LogDebug("Get external widget");
203 if (APP2EXT_SD_CARD ==
204 app2ext_get_app_location(m_context.tzAppid.c_str()))
206 LogDebug("This widget is in external stroage");
211 } //namespace WidgetUninstall