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/abstract_waitable_input_adapter.h>
31 #include <dpl/abstract_waitable_output_adapter.h>
32 #include <dpl/zip_input.h>
33 #include <dpl/binary_queue.h>
35 #include <dpl/assert.h>
36 #include <dpl/sstream.h>
37 #include <dpl/file_input.h>
38 #include <dpl/utils/wrt_utility.h>
39 #include <dpl/utils/path.h>
40 #include <dpl/wrt-dao-ro/common_dao_types.h>
41 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
42 #include <dpl/wrt-dao-ro/global_config.h>
43 #include <dpl/wrt-dao-ro/config_parser_data.h>
44 #include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
45 #include <dpl/localization/w3c_file_localization.h>
47 #include <libiriwrapper.h>
48 #include <pkg-manager/pkgmgr_signal.h>
49 #include <app_manager.h>
51 #include "root_parser.h"
52 #include "widget_parser.h"
53 #include "parser_runner.h"
54 #include <widget_install/job_widget_install.h>
55 #include <widget_install/task_certify.h>
56 #include <widget_install/task_certify_level.h>
57 #include <widget_install/task_widget_config.h>
58 #include <widget_install/task_file_manipulation.h>
59 #include <widget_install/task_ace_check.h>
60 #include <widget_install/task_smack.h>
61 #include <widget_install/task_manifest_file.h>
62 #include <widget_install/task_prepare_files.h>
63 #include <widget_install/task_recovery.h>
64 #include <widget_install/task_install_ospsvc.h>
65 #include <widget_install/task_update_files.h>
66 #include <widget_install/task_database.h>
67 #include <widget_install/task_remove_backup.h>
68 #include <widget_install/task_encrypt_resource.h>
69 #include <widget_install/task_pkg_info_update.h>
70 #include <widget_install/task_commons.h>
71 #include <widget_install/task_prepare_reinstall.h>
72 #include <widget_install/task_configuration.h>
73 #include <widget_install/task_installer_fail.h>
75 #include <widget_install/widget_install_errors.h>
76 #include <widget_install/widget_install_context.h>
77 #include <widget_install_to_external.h>
78 #include <widget_install/widget_unzip.h>
80 using namespace WrtDB;
81 using namespace Jobs::Exceptions;
84 namespace WidgetInstall {
86 JobWidgetInstall::JobWidgetInstall(
87 std::string const &widgetPath,
88 const WidgetInstallationStruct &
91 JobContextBase<WidgetInstallationStruct>(installerStruct),
92 m_exceptionCaught(Jobs::Exceptions::Success)
94 m_installerContext.mode = m_jobStruct.m_installMode;
95 m_installerContext.requestedPath = widgetPath;
97 //start configuration of installation
98 AddTask(new TaskConfiguration(m_installerContext));
100 // Init installer context
101 m_installerContext.installStep = InstallerContext::INSTALL_START;
102 m_installerContext.job = this;
103 m_installerContext.widgetConfig.shareHref = std::string();
106 void JobWidgetInstall::appendNewInstallationTaskList()
108 LogDebug("Configure installation succeeded");
109 m_installerContext.job->SetProgressFlag(true);
111 AddTask(new TaskRecovery(m_installerContext));
113 AddTask(new TaskWidgetConfig(m_installerContext));
114 if (m_installerContext.widgetConfig.packagingType ==
115 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
117 AddTask(new TaskPrepareFiles(m_installerContext));
119 AddTask(new TaskCertify(m_installerContext));
120 AddTask(new TaskCertifyLevel(m_installerContext));
121 if (m_installerContext.needEncryption) {
122 AddTask(new TaskEncryptResource(m_installerContext));
124 AddTask(new TaskFileManipulation(m_installerContext));
125 AddTask(new TaskManifestFile(m_installerContext));
126 if (m_installerContext.widgetConfig.packagingType ==
127 PKG_TYPE_HYBRID_WEB_APP)
129 AddTask(new TaskInstallOspsvc(m_installerContext));
131 AddTask(new TaskDatabase(m_installerContext));
132 AddTask(new TaskAceCheck(m_installerContext));
133 AddTask(new TaskSmack(m_installerContext));
134 AddTask(new TaskPkgInfoUpdate(m_installerContext));
137 void JobWidgetInstall::appendUpdateInstallationTaskList()
139 LogDebug("Configure installation updated");
140 LogDebug("Widget Update");
141 m_installerContext.job->SetProgressFlag(true);
143 if (m_installerContext.mode.command ==
144 InstallMode::Command::REINSTALL)
146 AddTask(new TaskPrepareReinstall(m_installerContext));
149 AddTask(new TaskWidgetConfig(m_installerContext));
151 if (m_installerContext.widgetConfig.packagingType ==
152 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
154 AddTask(new TaskPrepareFiles(m_installerContext));
157 AddTask(new TaskCertify(m_installerContext));
158 AddTask(new TaskCertifyLevel(m_installerContext));
159 if (m_installerContext.needEncryption) {
160 AddTask(new TaskEncryptResource(m_installerContext));
163 if (m_installerContext.mode.extension !=
164 InstallMode::ExtensionType::DIR) {
165 AddTask(new TaskUpdateFiles(m_installerContext));
166 AddTask(new TaskFileManipulation(m_installerContext));
169 AddTask(new TaskManifestFile(m_installerContext));
170 if (m_installerContext.widgetConfig.packagingType ==
171 PKG_TYPE_HYBRID_WEB_APP)
173 AddTask(new TaskInstallOspsvc(m_installerContext));
176 AddTask(new TaskDatabase(m_installerContext));
177 AddTask(new TaskAceCheck(m_installerContext));
178 //TODO: remove widgetHandle from this task and move before database task
179 // by now widget handle is needed in ace check
180 // Any error in acecheck while update will break widget
181 AddTask(new TaskSmack(m_installerContext));
182 AddTask(new TaskRemoveBackupFiles(m_installerContext));
183 AddTask(new TaskPkgInfoUpdate(m_installerContext));
186 void JobWidgetInstall::appendFailureTaskList()
188 // Installation is not allowed to proceed due to widget update policy
189 LogWarning("Configure installation failed!");
190 getInstallerStruct().pkgmgrInterface->sendSignal(
192 PKGMGR_START_INSTALL);
193 getInstallerStruct().pkgmgrInterface->sendSignal(
197 AddTask(new InstallerTaskFail(m_installerContext.confResult));
200 void JobWidgetInstall::SendProgress()
202 using namespace PackageManager;
203 if (GetProgressFlag() != false) {
204 if (getInstallerStruct().progressCallback != NULL) {
205 // send progress signal of pkgmgr
206 std::ostringstream percent;
207 percent << static_cast<int>(GetProgressPercent());
208 getInstallerStruct().pkgmgrInterface->sendSignal(
212 LogPedantic("Call widget install progressCallback");
213 getInstallerStruct().progressCallback(
214 getInstallerStruct().userParam,
215 GetProgressPercent(),
216 GetProgressDescription());
221 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
223 using namespace PackageManager;
224 if (GetProgressFlag() != false) {
225 if (getInstallerStruct().progressCallback != NULL) {
226 // send progress signal of pkgmgr
227 getInstallerStruct().pkgmgrInterface->sendSignal(
234 void JobWidgetInstall::SendFinishedSuccess()
236 using namespace PackageManager;
237 // TODO : sync should move to separate task.
240 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
241 if (m_installerContext.isUpdateMode) {
242 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
244 WidgetInstallToExtSingleton::Instance().postInstallation(true);
246 WidgetInstallToExtSingleton::Instance().deinitialize();
249 // remove widget install information file
250 unlink(m_installerContext.installInfo.c_str());
253 JobWidgetInstall::displayWidgetInfo();
255 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
257 // send signal of pkgmgr
258 getInstallerStruct().pkgmgrInterface->sendSignal(
262 LogDebug("Call widget install successfinishedCallback");
263 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
265 tizenId), Jobs::Exceptions::Success);
268 void JobWidgetInstall::SendFinishedFailure()
270 using namespace PackageManager;
271 // remove widget install information file
272 unlink(m_installerContext.installInfo.c_str());
274 LogError("Error number: " << m_exceptionCaught);
275 LogError("Message: " << m_exceptionMessage);
276 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
278 LogDebug("Call widget install failure finishedCallback");
279 std::stringstream errorNum;
280 errorNum << m_exceptionCaught;
282 // send signal of pkgmgr
283 getInstallerStruct().pkgmgrInterface->sendSignal(
287 getInstallerStruct().pkgmgrInterface->sendSignal(
291 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
293 tizenId), m_exceptionCaught);
296 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
298 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
299 m_exceptionMessage = e.GetMessage();
302 void JobWidgetInstall::displayWidgetInfo()
304 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
306 std::ostringstream out;
307 WidgetLocalizedInfo localizedInfo =
308 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
311 "===================================== INSTALLED WIDGET INFO =========" \
312 "============================";
313 out << std::endl << "Name: " << localizedInfo.name;
314 out << std::endl << "AppId: " << dao.getTzAppId();
315 WidgetSize size = dao.getPreferredSize();
316 out << std::endl << "Width: " << size.width;
317 out << std::endl << "Height: " << size.height;
318 out << std::endl << "Start File: " <<
319 W3CFileLocalization::getStartFile(dao.getTzAppId());
320 out << std::endl << "Version: " << dao.getVersion();
321 out << std::endl << "Licence: " <<
322 localizedInfo.license;
323 out << std::endl << "Licence Href: " <<
324 localizedInfo.licenseHref;
325 out << std::endl << "Description: " <<
326 localizedInfo.description;
327 out << std::endl << "Widget Id: " << dao.getGUID();
328 out << std::endl << "Widget recognized: " << dao.isRecognized();
329 out << std::endl << "Widget distributor signed: " <<
330 dao.isDistributorSigned();
331 out << std::endl << "Widget trusted: " << dao.isTrusted();
333 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
334 DPL::OptionalString iconSrc =
335 !!icon ? icon->src : DPL::OptionalString::Null;
336 out << std::endl << "Icon: " << iconSrc;
338 out << std::endl << "Preferences:";
340 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
343 out << std::endl << " Key: " <<
345 out << std::endl << " Readonly: " <<
350 out << std::endl << "Features:";
352 WidgetFeatureSet list = dao.getFeaturesList();
355 out << std::endl << " Name: " << it->name;
363 } //namespace WidgetInstall