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 * @file job_widget_install.cpp
18 * @author Radoslaw Wicik r.wicik@samsung.com
19 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @brief Implementation file for main installer task
30 #include <dpl/utils/wrt_utility.h>
31 #include <dpl/utils/path.h>
32 #include <dpl/localization/w3c_file_localization.h>
34 #include <pkg-manager/pkgmgr_signal.h>
35 #include <app_manager.h>
37 #include "root_parser.h"
38 #include "widget_parser.h"
39 #include "parser_runner.h"
40 #include <widget_install/job_widget_install.h>
41 #include <widget_install/task_certify.h>
42 #include <widget_install/task_certify_level.h>
43 #include <widget_install/task_process_config.h>
44 #include <widget_install/task_file_manipulation.h>
45 #include <widget_install/task_ace_check.h>
46 #include <widget_install/task_smack.h>
47 #include <widget_install/task_manifest_file.h>
48 #include <widget_install/task_prepare_files.h>
49 #include <widget_install/task_recovery.h>
50 #include <widget_install/task_install_ospsvc.h>
51 #include <widget_install/task_update_files.h>
52 #include <widget_install/task_database.h>
53 #include <widget_install/task_remove_backup.h>
54 #include <widget_install/task_encrypt_resource.h>
55 #include <widget_install/task_pkg_info_update.h>
56 #include <widget_install/task_commons.h>
57 #include <widget_install/task_prepare_reinstall.h>
58 #include <widget_install/task_configuration.h>
59 #include <widget_install/task_user_data_manipulation.h>
61 #include <widget_install_to_external.h>
62 #include <widget_install/widget_unzip.h>
64 #include <installer_log.h>
66 using namespace WrtDB;
67 using namespace Jobs::Exceptions;
70 namespace WidgetInstall {
72 JobWidgetInstall::JobWidgetInstall(
73 std::string const &widgetPath,
74 std::string const &tzPkgId,
75 const Jobs::WidgetInstall::WidgetInstallationStruct &
77 Job(UnknownInstallation),
78 JobContextBase<Jobs::WidgetInstall::WidgetInstallationStruct>(installerStruct),
79 m_exceptionCaught(Jobs::Exceptions::Success)
81 m_installerContext.mode = m_jobStruct.m_installMode;
82 m_installerContext.requestedPath = widgetPath;
83 m_jobStruct.pkgmgrInterface->setPkgname(tzPkgId);
85 //start configuration of installation
86 AddTask(new TaskConfiguration(m_installerContext));
88 // Init installer context
89 m_installerContext.installStep = InstallerContext::INSTALL_START;
90 m_installerContext.job = this;
92 m_installerContext.callerPkgId
93 = DPL::FromUTF8String(m_jobStruct.pkgmgrInterface->getCallerId());
94 _D("Caller Package Id : %s", DPL::ToUTF8String(m_installerContext.callerPkgId).c_str());
97 void JobWidgetInstall::appendNewInstallationTaskList()
99 _D("Configure installation succeeded");
100 m_installerContext.job->SetProgressFlag(true);
102 AddTask(new TaskRecovery(m_installerContext));
104 AddTask(new TaskFileManipulation(m_installerContext));
105 AddTask(new TaskProcessConfig(m_installerContext));
106 if (m_installerContext.widgetConfig.packagingType ==
107 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
109 AddTask(new TaskPrepareFiles(m_installerContext));
111 AddTask(new TaskCertify(m_installerContext));
112 AddTask(new TaskCertifyLevel(m_installerContext));
113 AddTask(new TaskUserDataManipulation(m_installerContext));
114 if (m_installerContext.needEncryption) {
115 AddTask(new TaskEncryptResource(m_installerContext));
117 AddTask(new TaskManifestFile(m_installerContext));
118 if (m_installerContext.widgetConfig.packagingType ==
119 PKG_TYPE_HYBRID_WEB_APP)
121 AddTask(new TaskInstallOspsvc(m_installerContext));
123 AddTask(new TaskDatabase(m_installerContext));
124 AddTask(new TaskAceCheck(m_installerContext));
125 AddTask(new TaskSmack(m_installerContext));
126 AddTask(new TaskPkgInfoUpdate(m_installerContext));
129 void JobWidgetInstall::appendUpdateInstallationTaskList()
131 _D("Configure installation updated");
133 m_installerContext.job->SetProgressFlag(true);
135 if (m_installerContext.mode.command ==
136 InstallMode::Command::REINSTALL)
138 AddTask(new TaskPrepareReinstall(m_installerContext));
141 if (m_installerContext.mode.extension !=
142 InstallMode::ExtensionType::DIR) {
143 AddTask(new TaskUpdateFiles(m_installerContext));
144 AddTask(new TaskFileManipulation(m_installerContext));
147 AddTask(new TaskProcessConfig(m_installerContext));
149 if (m_installerContext.widgetConfig.packagingType ==
150 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
152 AddTask(new TaskPrepareFiles(m_installerContext));
155 AddTask(new TaskCertify(m_installerContext));
156 AddTask(new TaskCertifyLevel(m_installerContext));
157 AddTask(new TaskUserDataManipulation(m_installerContext));
158 if (m_installerContext.needEncryption) {
159 AddTask(new TaskEncryptResource(m_installerContext));
162 AddTask(new TaskManifestFile(m_installerContext));
163 if (m_installerContext.widgetConfig.packagingType ==
164 PKG_TYPE_HYBRID_WEB_APP)
166 AddTask(new TaskInstallOspsvc(m_installerContext));
169 AddTask(new TaskDatabase(m_installerContext));
170 AddTask(new TaskAceCheck(m_installerContext));
171 //TODO: remove widgetHandle from this task and move before database task
172 // by now widget handle is needed in ace check
173 // Any error in acecheck while update will break widget
174 AddTask(new TaskSmack(m_installerContext));
175 AddTask(new TaskRemoveBackupFiles(m_installerContext));
176 AddTask(new TaskPkgInfoUpdate(m_installerContext));
179 void JobWidgetInstall::SendProgress()
181 using namespace PackageManager;
182 if (GetProgressFlag() != false) {
183 if (GetInstallerStruct().progressCallback != NULL) {
184 // send progress signal of pkgmgr
185 GetInstallerStruct().pkgmgrInterface->sendProgress(GetProgressPercent());
187 _D("Call widget install progressCallback");
188 GetInstallerStruct().progressCallback(
189 GetInstallerStruct().userParam,
190 GetProgressPercent(),
191 GetProgressDescription());
196 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
198 using namespace PackageManager;
199 if (GetProgressFlag() != false) {
200 if (GetInstallerStruct().progressCallback != NULL) {
201 // send progress signal of pkgmgr
202 GetInstallerStruct().pkgmgrInterface->sendIconPath(path);
207 void JobWidgetInstall::SendFinishedSuccess()
209 using namespace PackageManager;
210 // TODO : sync should move to separate task.
213 if (INSTALL_LOCATION_TYPE_PREFER_EXTERNAL == m_installerContext.locationType) {
214 if (m_installerContext.isUpdateMode) {
215 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
217 WidgetInstallToExtSingleton::Instance().postInstallation(true);
219 WidgetInstallToExtSingleton::Instance().deinitialize();
222 // remove widget install information file
223 unlink(m_installerContext.installInfo.c_str());
226 JobWidgetInstall::displayWidgetInfo();
228 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
230 // send signal of pkgmgr
231 GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught);
233 _D("Call widget install successfinishedCallback");
234 GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam,
236 tizenId), Jobs::Exceptions::Success);
239 void JobWidgetInstall::SendFinishedFailure()
241 using namespace PackageManager;
242 // remove widget install information file
243 unlink(m_installerContext.installInfo.c_str());
245 _E("Error number: %d", m_exceptionCaught);
246 _E("Message: %s", m_exceptionMessage.c_str());
247 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
249 _D("Call widget install failure finishedCallback");
251 // send signal of pkgmgr
252 GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught);
254 GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam,
256 tizenId), m_exceptionCaught);
259 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
261 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
262 m_exceptionMessage = e.GetMessage();
265 void JobWidgetInstall::displayWidgetInfo()
267 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
269 std::ostringstream out;
270 WidgetLocalizedInfo localizedInfo =
271 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
274 "===================================== INSTALLED WIDGET INFO =========" \
275 "============================";
276 out << std::endl << "Name: " << localizedInfo.name;
277 out << std::endl << "AppId: " << dao.getTzAppId();
278 WidgetSize size = dao.getPreferredSize();
279 out << std::endl << "Width: " << size.width;
280 out << std::endl << "Height: " << size.height;
281 out << std::endl << "Start File: " <<
282 W3CFileLocalization::getStartFile(dao.getTzAppId());
283 out << std::endl << "Version: " << dao.getVersion();
284 out << std::endl << "Licence: " <<
285 localizedInfo.license;
286 out << std::endl << "Licence Href: " <<
287 localizedInfo.licenseHref;
288 out << std::endl << "Description: " <<
289 localizedInfo.description;
290 out << std::endl << "Widget Id: " << dao.getGUID();
291 out << std::endl << "Widget recognized: " << dao.isRecognized();
292 out << std::endl << "Widget distributor signed: " <<
293 dao.isDistributorSigned();
294 out << std::endl << "Widget trusted: " << dao.isTrusted();
296 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
297 DPL::OptionalString iconSrc =
298 !!icon ? icon->src : DPL::OptionalString::Null;
299 out << std::endl << "Icon: " << iconSrc;
301 out << std::endl << "Preferences:";
303 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
306 out << std::endl << " Key: " <<
308 out << std::endl << " Readonly: " <<
313 out << std::endl << "Features:";
315 WidgetFeatureSet list = dao.getFeaturesList();
318 out << std::endl << " Name: " << it->name;
324 _D("%s", out.str().c_str());
326 } //namespace WidgetInstall