Add to privilege level for install hybrid app.
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_install_ospsvc.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_install_ospsvc.cpp
18  * @author  Soyoung Kim (sy037.kim@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for installer task  install osp service
21  */
22 #include "task_install_ospsvc.h"
23
24 #include <unistd.h>
25 #include <string>
26
27 #include <pkgmgr/pkgmgr_parser.h>
28 #include <pkgmgr-info.h>
29 #include <fstream>
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
35 #include <widget_install/job_widget_install.h>
36 #include <widget_install/widget_install_context.h>
37 #include <widget_install/widget_install_errors.h>
38
39 #include <installer_log.h>
40
41 using namespace WrtDB;
42
43 namespace {
44 const int MAX_BUF_SIZE = 128;
45 const char* OSP_INSTALL_STR1 = "/usr/etc/package-manager/backend/tpk -iv ";
46 const char* OSP_INSTALL_STR2 = " -p ";
47 }
48
49 namespace Jobs {
50 namespace WidgetInstall {
51 TaskInstallOspsvc::TaskInstallOspsvc(InstallerContext& context) :
52     DPL::TaskDecl<TaskInstallOspsvc>(this),
53     m_context(context)
54 {
55     AddStep(&TaskInstallOspsvc::StartStep);
56     AddStep(&TaskInstallOspsvc::StepInstallOspService);
57     AddStep(&TaskInstallOspsvc::EndStep);
58 }
59
60 void TaskInstallOspsvc::StepInstallOspService()
61 {
62     _D("Step: installation for osp service");
63
64     std::ostringstream commStr;
65     commStr << OSP_INSTALL_STR1<< BashUtils::escape_arg(
66         m_context.locations->getPackageInstallationDir())
67         << OSP_INSTALL_STR2 << m_context.certLevel;
68     _D("osp install command : %s", commStr.str().c_str());
69
70     char readBuf[MAX_BUF_SIZE];
71     FILE *fd;
72     fd = popen(commStr.str().c_str(), "r");
73     if (NULL == fd) {
74         _E("Failed to installtion osp service");
75         ThrowMsg(Exceptions::InstallOspsvcFailed,
76                  "Error occurs during\
77                 install osp service");
78     }
79
80     if (fgets(readBuf, MAX_BUF_SIZE, fd) == NULL)
81     {
82         _E("Failed to installtion osp service.\
83                 Inability of reading file.");
84         ThrowMsg(Exceptions::InstallOspsvcFailed,
85                 "Error occurs during\
86                 install osp service");
87     }
88     _D("return value : %s", readBuf);
89
90     int result = atoi(readBuf);
91     if (0 != result) {
92         ThrowMsg(Exceptions::InstallOspsvcFailed,
93                  "Error occurs during\
94                 install osp service");
95     }
96
97     pclose(fd);
98 }
99
100 void TaskInstallOspsvc::StartStep()
101 {
102     _D("--------- <TaskInstallOspsvc> : START ----------");
103 }
104
105 void TaskInstallOspsvc::EndStep()
106 {
107     m_context.job->UpdateProgress(
108         InstallerContext::INSTALL_INSTALL_OSPSVC,
109         "Installed Osp servcie");
110
111     _D("--------- <TaskInstallOspsvc> : END ----------");
112 }
113 } //namespace WidgetInstall
114 } //namespace Jobs