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 task_install_ospsvc.cpp
18 * @author Soyoung Kim (sy037.kim@samsung.com)
20 * @brief Implementation file for installer task install osp service
22 #include "task_install_ospsvc.h"
27 #include <pkgmgr/pkgmgr_parser.h>
28 #include <pkgmgr-info.h>
30 #include <dpl/errno_string.h>
31 #include <dpl/foreach.h>
32 #include <dpl/wrt-dao-ro/global_config.h>
33 #include <dpl/utils/bash_utils.h>
34 #include <privilege-control.h>
36 #include <widget_install/widget_install_context.h>
37 #include <widget_install/widget_install_errors.h>
38 #include <dpl/log/secure_log.h>
40 using namespace WrtDB;
43 const int MAX_BUF_SIZE = 128;
44 const char* OSP_INSTALL_STR1 = "/usr/etc/package-manager/backend/tpk -iv ";
45 const char* OSP_INSTALL_STR2 = " -p ";
47 #if USE(CORE_HYBRID_PKG)
48 const char* CORE_INSTALL_STR1 = "/usr/etc/package-manager/backend/rpm -iv ";
49 const char* CORE_INSTALL_STR2 = " -p ";
50 const char* const CORE_MANIFEST_XML = "tizen-manifest.xml";
56 namespace WidgetInstall {
57 TaskInstallOspsvc::TaskInstallOspsvc(JobWidgetInstall * const &jobContext) :
58 DPL::TaskDecl<TaskInstallOspsvc>(this),
59 m_jobContext(jobContext)
61 AddStep(&TaskInstallOspsvc::StartStep);
62 AddStep(&TaskInstallOspsvc::StepUninstallSmack);
63 AddStep(&TaskInstallOspsvc::StepInstallOspService);
64 AddStep(&TaskInstallOspsvc::EndStep);
67 void TaskInstallOspsvc::StepUninstallSmack()
69 std::string pkgId = DPL::ToUTF8String(m_jobContext->m_installerContext.widgetConfig.tzPkgid);
70 if (m_jobContext->m_installerContext.isUpdateMode) {
71 _D("StepUninstallSmack");
72 if (PC_OPERATION_SUCCESS != perm_app_uninstall(pkgId.c_str())) {
73 _E("failure in removing smack rules file");
74 ThrowMsg(Exceptions::NotAllowed, "Update failure. "
75 "failure in delete smack rules file before update.");
80 void TaskInstallOspsvc::StepInstallOspService()
82 _D("Step: installation for hybrid service");
84 std::ostringstream commStr;
86 #if USE(CORE_HYBRID_PKG)
89 bf::path corePath(m_jobContext->m_installerContext.locations->getPackageInstallationDir());
91 corePath /= CORE_MANIFEST_XML;
92 if (bf::exists(corePath)) {
95 } catch (const bf::filesystem_error& ex) {
96 _E("Not a hybrid app");
100 #if USE(CORE_HYBRID_PKG)
102 commStr << CORE_INSTALL_STR1 << BashUtils::escape_arg(
103 m_jobContext->m_installerContext.locations->getPackageInstallationDir())
104 << CORE_INSTALL_STR2 << m_jobContext->m_installerContext.certLevel;
107 commStr << OSP_INSTALL_STR1 << BashUtils::escape_arg(
108 m_jobContext->m_installerContext.locations->getPackageInstallationDir())
109 << OSP_INSTALL_STR2 << m_jobContext->m_installerContext.certLevel;
110 #if USE(CORE_HYBRID_PKG)
114 _D("hybrid install command : %s", commStr.str().c_str());
116 char readBuf[MAX_BUF_SIZE];
118 fd = popen(commStr.str().c_str(), "r");
120 _E("Failed to installtion hybrid service");
121 ThrowMsg(Exceptions::InstallOspsvcFailed,
122 "Error occurs during\
123 install hybrid service");
126 if (fgets(readBuf, MAX_BUF_SIZE, fd) == NULL)
128 _E("Failed to installtion hybrid service.\
129 Inability of reading file.");
130 ThrowMsg(Exceptions::InstallOspsvcFailed,
131 "Error occurs during\
132 install hybrid service");
134 _D("return value : %s", readBuf);
136 int result = atoi(readBuf);
138 ThrowMsg(Exceptions::InstallOspsvcFailed,
139 "Error occurs during\
140 install hybrid service");
146 void TaskInstallOspsvc::StartStep()
148 LOGI("--------- <TaskInstallOspsvc> : START ----------");
151 void TaskInstallOspsvc::EndStep()
153 m_jobContext->UpdateProgress(
154 InstallerContext::INSTALL_INSTALL_OSPSVC,
155 "Installed Osp servcie");
157 LOGI("--------- <TaskInstallOspsvc> : END ----------");
159 } //namespace WidgetInstall