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/platform.h>
31 #include <dpl/utils/wrt_utility.h>
32 #include <dpl/utils/path.h>
33 #include <dpl/localization/w3c_file_localization.h>
35 #include <pkg-manager/pkgmgr_signal.h>
36 #include <app_manager.h>
37 #include <privilege-control.h>
38 #include "root_parser.h"
39 #include "widget_parser.h"
40 #include "parser_runner.h"
41 #include <widget_install/job_widget_install.h>
42 #include <widget_install/task_certify.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>
60 #include <widget_install/task_status_check.h>
61 #if ENABLE(PRE_LAUNCH)
62 #include <widget_install/task_prelaunching_registration.h>
64 #include <widget_install_to_external.h>
65 #include <boost/filesystem.hpp>
66 #include <dpl/log/secure_log.h>
68 namespace bf = boost::filesystem;
70 using namespace WrtDB;
71 using namespace Jobs::Exceptions;
74 namespace WidgetInstall {
76 JobWidgetInstall::JobWidgetInstall(
77 std::string const &widgetPath,
78 std::string const &tzPkgId,
79 const Jobs::WidgetInstall::WidgetInstallationStruct &
81 Job(UnknownInstallation),
82 JobContextBase<Jobs::WidgetInstall::WidgetInstallationStruct>(installerStruct),
83 m_exceptionCaught(Jobs::Exceptions::Success)
85 m_installerContext.mode = m_jobStruct.m_installMode;
86 m_installerContext.requestedPath = widgetPath;
87 m_jobStruct.pkgmgrInterface->setPkgname(tzPkgId);
89 if (InstallMode::Command::RECOVERY == m_installerContext.mode.command) {
90 m_installerContext.widgetConfig.tzPkgid = DPL::FromUTF8String(tzPkgId);
91 AddTask(new TaskRecovery(this));
94 //start configuration of installation
95 AddTask(new TaskConfiguration(this));
97 m_installerContext.callerPkgId
98 = DPL::FromUTF8String(m_jobStruct.pkgmgrInterface->getCallerId());
99 _D("Caller Package Id : %s", DPL::ToUTF8String(m_installerContext.callerPkgId).c_str());
102 void JobWidgetInstall::appendNewInstallationTaskList()
104 _D("Configure installation succeeded");
105 SetProgressFlag(true);
107 AddTask(new TaskFileManipulation(this));
108 AddTask(new TaskProcessConfig(this));
109 if (m_installerContext.widgetConfig.packagingType ==
110 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
112 AddTask(new TaskPrepareFiles(this));
114 AddTask(new TaskCertify(this));
115 AddTask(new TaskUserDataManipulation(this));
116 if (m_installerContext.needEncryption) {
117 AddTask(new TaskEncryptResource(this));
119 AddTask(new TaskManifestFile(this));
120 if (m_installerContext.widgetConfig.packagingType ==
121 PKG_TYPE_HYBRID_WEB_APP) {
122 AddTask(new TaskInstallOspsvc(this));
124 AddTask(new TaskDatabase(this));
125 AddTask(new TaskAceCheck(this));
126 AddTask(new TaskSmack(this));
127 AddTask(new TaskPkgInfoUpdate(this));
128 #if ENABLE(PRE_LAUNCH)
129 if (m_installerContext.isNeedPreLaunching) {
130 AddTask(new TaskPreLaunchingRegistration(this));
135 void JobWidgetInstall::appendUpdateInstallationTaskList()
137 _D("Configure installation updated");
139 SetProgressFlag(true);
140 AddTask(new TaskStatusCheck(this));
142 if (m_installerContext.mode.command ==
143 InstallMode::Command::REINSTALL) {
144 AddTask(new TaskPrepareReinstall(this));
147 if (m_installerContext.mode.extension !=
148 InstallMode::ExtensionType::DIRECTORY) {
149 AddTask(new TaskUpdateFiles(this));
150 AddTask(new TaskFileManipulation(this));
153 AddTask(new TaskProcessConfig(this));
155 if (m_installerContext.widgetConfig.packagingType ==
156 WrtDB::PKG_TYPE_HOSTED_WEB_APP) {
157 AddTask(new TaskPrepareFiles(this));
160 AddTask(new TaskCertify(this));
161 AddTask(new TaskUserDataManipulation(this));
162 if (m_installerContext.needEncryption) {
163 AddTask(new TaskEncryptResource(this));
165 AddTask(new TaskManifestFile(this));
166 if (m_installerContext.widgetConfig.packagingType ==
167 PKG_TYPE_HYBRID_WEB_APP) {
168 AddTask(new TaskInstallOspsvc(this));
171 AddTask(new TaskDatabase(this));
172 AddTask(new TaskAceCheck(this));
173 //TODO: remove widgetHandle from this task and move before database task
174 // by now widget handle is needed in ace check
175 // Any error in acecheck while update will break widget
176 AddTask(new TaskSmack(this));
177 AddTask(new TaskRemoveBackupFiles(this));
178 AddTask(new TaskPkgInfoUpdate(this));
181 void JobWidgetInstall::appendRDSUpdateTaskList()
183 _D("Configure installation RDS updated");
184 SetProgressFlag(true);
185 AddTask(new TaskStatusCheck(this));
186 AddTask(new TaskPrepareReinstall(this));
187 AddTask(new TaskCertify(this));
190 void JobWidgetInstall::appendRecoveryTaskList()
193 SetProgressFlag(true);
195 AddTask(new TaskProcessConfig(this));
197 AddTask(new TaskCertify(this));
198 AddTask(new TaskManifestFile(this));
199 if (m_installerContext.widgetConfig.packagingType ==
200 PKG_TYPE_HYBRID_WEB_APP) {
201 AddTask(new TaskInstallOspsvc(this));
203 AddTask(new TaskSmack(this));
206 void JobWidgetInstall::appendFotaInstallationTaskList()
209 _D("Configure installation succeeded");
210 SetProgressFlag(true);
212 AddTask(new TaskProcessConfig(this));
213 AddTask(new TaskCertify(this));
214 AddTask(new TaskUserDataManipulation(this));
215 if (m_installerContext.needEncryption) {
216 AddTask(new TaskEncryptResource(this));
218 AddTask(new TaskManifestFile(this));
219 if (m_installerContext.widgetConfig.packagingType ==
220 PKG_TYPE_HYBRID_WEB_APP)
222 AddTask(new TaskInstallOspsvc(this));
224 AddTask(new TaskDatabase(this));
225 AddTask(new TaskAceCheck(this));
226 AddTask(new TaskSmack(this));
227 AddTask(new TaskPkgInfoUpdate(this));
230 void JobWidgetInstall::appendFotaUpdateTaskList()
232 _D("Configure installation updated");
234 SetProgressFlag(true);
236 AddTask(new TaskProcessConfig(this));
237 AddTask(new TaskCertify(this));
238 AddTask(new TaskUserDataManipulation(this));
239 if (m_installerContext.needEncryption) {
240 AddTask(new TaskEncryptResource(this));
243 AddTask(new TaskManifestFile(this));
244 if (m_installerContext.widgetConfig.packagingType ==
245 PKG_TYPE_HYBRID_WEB_APP)
247 AddTask(new TaskInstallOspsvc(this));
250 AddTask(new TaskDatabase(this));
251 AddTask(new TaskAceCheck(this));
252 //TODO: remove widgetHandle from this task and move before database task
253 // by now widget handle is needed in ace check
254 // Any error in acecheck while update will break widget
255 AddTask(new TaskSmack(this));
256 AddTask(new TaskPkgInfoUpdate(this));
257 #if ENABLE(PRE_LAUNCH)
258 if (m_installerContext.isNeedPreLaunching) {
259 AddTask(new TaskPreLaunchingRegistration(this));
264 void JobWidgetInstall::SendProgress()
266 using namespace PackageManager;
267 if (GetProgressFlag() != false) {
268 if (GetInstallerStruct().progressCallback != NULL) {
269 // send progress signal of pkgmgr
270 GetInstallerStruct().pkgmgrInterface->sendProgressInstall(GetProgressPercent());
272 _D("Call widget install progressCallback");
273 GetInstallerStruct().progressCallback(
274 GetInstallerStruct().userParam,
275 GetProgressPercent(),
276 GetProgressDescription());
281 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
283 using namespace PackageManager;
284 if (GetProgressFlag() != false) {
285 if (GetInstallerStruct().progressCallback != NULL) {
286 // send progress signal of pkgmgr
287 GetInstallerStruct().pkgmgrInterface->sendIconPath(path);
292 void JobWidgetInstall::SendFinishedSuccess()
294 using namespace PackageManager;
295 // TODO : sync should move to separate task.
298 if (INSTALL_LOCATION_TYPE_PREFER_EXTERNAL == m_installerContext.locationType) {
299 if (m_installerContext.isUpdateMode) {
300 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
302 WidgetInstallToExtSingleton::Instance().postInstallation(true);
304 WidgetInstallToExtSingleton::Instance().deinitialize();
307 /* smack label of ".mmc" is changed to "wrt-installer" after calling above function.
308 smack label of ".mmc" must be set to [pkgid] to success uninstallation by app2ext. */
309 std::string mmcDir = m_installerContext.locations->getPackageInstallationDir() + "/.mmc";
310 std::string pkgid = DPL::ToUTF8String(m_installerContext.widgetConfig.tzPkgid);
311 if (PC_OPERATION_SUCCESS != perm_app_setup_path(pkgid.c_str(), mmcDir.c_str(), APP_PATH_PRIVATE)) {
312 _W("change to wrt-installer label to %s", mmcDir.c_str());
316 JobWidgetInstall::displayWidgetInfo();
318 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
320 // send signal of pkgmgr
321 GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught);
323 _D("Call widget install successfinishedCallback");
324 GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam,
326 tizenId), Jobs::Exceptions::Success);
329 void JobWidgetInstall::SendFinishedFailure()
331 using namespace PackageManager;
333 // print error message
334 LOGE("Error number: %d", m_exceptionCaught);
335 LOGE("Error message: %s", m_exceptionMessage.c_str());
336 fprintf(stderr, "[Err:%d] %s", m_exceptionCaught, m_exceptionMessage.c_str());
338 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
340 _D("Call widget install failure finishedCallback");
342 // send signal of pkgmgr
343 GetInstallerStruct().pkgmgrInterface->endJob(m_exceptionCaught, m_exceptionMessage.c_str());
345 GetInstallerStruct().finishedCallback(GetInstallerStruct().userParam,
347 tizenId), m_exceptionCaught);
350 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
352 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
353 m_exceptionMessage = e.GetMessage();
356 void JobWidgetInstall::displayWidgetInfo()
358 if (m_installerContext.widgetConfig.webAppType.appType == WrtDB::APP_TYPE_TIZENWEBAPP)
360 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
362 std::ostringstream out;
363 WidgetLocalizedInfo localizedInfo =
364 W3CFileLocalization::getLocalizedInfo(dao.getTizenAppId());
367 "===================================== INSTALLED WIDGET INFO =========" \
368 "============================";
369 out << std::endl << "Name: " << localizedInfo.name;
370 out << std::endl << "AppId: " << dao.getTizenAppId();
371 WidgetSize size = dao.getPreferredSize();
372 out << std::endl << "Width: " << size.width;
373 out << std::endl << "Height: " << size.height;
374 out << std::endl << "Start File: " <<
375 W3CFileLocalization::getStartFile(dao.getTizenAppId());
376 out << std::endl << "Version: " << dao.getVersion();
377 out << std::endl << "Licence: " <<
378 localizedInfo.license;
379 out << std::endl << "Licence Href: " <<
380 localizedInfo.licenseHref;
381 out << std::endl << "Description: " <<
382 localizedInfo.description;
383 out << std::endl << "Widget Id: " << dao.getGUID();
385 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTizenAppId());
386 DPL::OptionalString iconSrc =
387 !!icon ? icon->src : DPL::OptionalString();
388 out << std::endl << "Icon: " << iconSrc;
390 out << std::endl << "Preferences:";
392 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
395 out << std::endl << " Key: " <<
397 out << std::endl << " Readonly: " <<
404 _D("%s", out.str().c_str());
408 void JobWidgetInstall::SecureRemove(const bf::path& path)
411 _E("error for get path");
412 ThrowMsg(Jobs::WidgetInstall::Exceptions::RemovingFileFailure, "Try to remove insecure location");
416 const char* blacklist[] = {
423 "/opt/share/widget/",
424 "/opt/share/widget/temp_info",
425 "/opt/share/widget/temp_info/",
426 "/opt/share/packages",
427 "/opt/share/packages/",
428 "/opt/share/applications",
429 "/opt/share/applications/",
437 char* canonicalizeFilePath = canonicalize_file_name(path.c_str());
438 if (!canonicalizeFilePath) {
439 _E("error : a pathname[%s] component is unreadable or does not exist", path.c_str());
440 //ThrowMsg(Jobs::WidgetInstall::Exceptions::RemovingFileFailure, "Try to remove insecure location");
445 while(blacklist[idx]){
446 char* cmpFilePath = canonicalize_file_name(blacklist[idx]);
448 if(!strcmp(canonicalizeFilePath, cmpFilePath)) {
449 _E("illegal access : %s", path.c_str());
451 free(canonicalizeFilePath);
452 ThrowMsg(Jobs::WidgetInstall::Exceptions::RemovingFileFailure, "Try to remove insecure location");
459 free(canonicalizeFilePath);
460 bf::remove_all(path);
462 } //namespace WidgetInstall