2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @brief This is the implementation file for %Installer class.
26 #include <FIoDirectory.h>
28 #include "Installer.h"
29 #include "PermissionManager.h"
30 #include "ConfigurationManager.h"
31 #include "DatabaseManager.h"
32 #include "InstallerUtil.h"
33 #include "SignatureManager.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
39 Installer::Installer(void)
44 Installer::~Installer(void)
49 Installer::Construct(InstallationContext* pContext)
51 __pContext = pContext;
53 if (InstallerUtil::IsSymlink(PATH_OPT_APPS) == false)
55 if (File::IsFileExist(PATH_OPT_APPS) == false)
57 Directory::Create(PATH_OPT_APPS, false);
58 InstallerUtil::ChangeMode(PATH_OPT_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
62 if (File::IsFileExist(PATH_OPT_USR) == false)
64 Directory::Create(PATH_OPT_USR, false);
65 InstallerUtil::ChangeMode(PATH_OPT_USR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
68 if (File::IsFileExist(PATH_OPT_USR_APPS) == false)
70 Directory::Create(PATH_OPT_USR_APPS, false);
71 InstallerUtil::ChangeMode(PATH_OPT_USR_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
74 return INSTALLER_ERROR_NONE;
78 Installer::GetNext(InstallationStep step)
80 if (step == INSTALLER_STEP_PARSE_SIGNATURE)
82 step = INSTALLER_STEP_END;
86 step = (InstallationStep)(step + 1);
93 Installer::OnInit(void)
95 AppLog("Installer::OnInit()");
97 return INSTALLER_ERROR_NONE;
101 Installer::OnRegister(void)
103 AppLog("------------------------------------------");
104 AppLog("Installer::OnRegister() - START");
105 InstallationContext* pContext = GetContext();
106 TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "pContext is null");
108 InstallerOperation operation = pContext->GetInstallerOperation();
110 DatabaseManager databaseManager;
112 if (operation == INSTALLER_OPERATION_INSTALL)
114 databaseManager.UnregisterPackageInfo(pContext);
115 databaseManager.RegisterPackageInfo(pContext);
119 databaseManager.UnregisterPackageInfo(pContext);
121 AppLog("Installer::OnRegister() - END");
122 AppLog("------------------------------------------");
124 return INSTALLER_ERROR_NONE;
128 Installer::OnEnd(void)
130 AppLog("------------------------------------------");
131 AppLog("Installer::OnEnd() - START");
133 InstallationContext* pContext = GetContext();
134 TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "pContext is null");
136 InstallerOperation operation = pContext->GetInstallerOperation();
137 ConfigurationManager configurationManager;
138 SignatureManager sigManager;
139 sigManager.Construct(pContext);
141 pContext->SetContinue(false);
143 if (operation == INSTALLER_OPERATION_INSTALL)
145 res = configurationManager.CreateFile(pContext);
146 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "CreateFile() failed.");
148 res = PermissionManager::SetDirectory(pContext);
149 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetDirectory() failed.");
151 res = PermissionManager::SetFile(pContext);
152 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetFile() failed.");
154 res = configurationManager.PostInstall(pContext, false);
155 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "PostInstall() failed.");
157 res = sigManager.UnregisterCertInfo();
158 TryReturn(res, INSTALLER_ERROR_DATABASE, "UnregisterCertInfo() failed.");
160 res = sigManager.RegisterCertInfo();
161 TryReturn(res, INSTALLER_ERROR_DATABASE, "RegisterCertInfo() failed.");
163 else if (operation == INSTALLER_OPERATION_UNINSTALL)
165 configurationManager.RemoveFile(pContext);
166 sigManager.UnregisterCertInfo();
167 configurationManager.PostUninstall(pContext);
170 AppLog("Installer::OnEnd() - END");
171 AppLog("------------------------------------------");
173 return INSTALLER_ERROR_NONE;
177 Installer::OnError(void)
179 AppLog("Installer::OnError()");
181 InstallerOperation operation = __pContext->GetInstallerOperation();
182 ConfigurationManager configurationManager;
184 if (operation == INSTALLER_OPERATION_INSTALL)
186 configurationManager.PostInstall(__pContext, true);
190 configurationManager.PostUninstall(__pContext);
193 return INSTALLER_ERROR_NONE;
197 Installer::OnRollback(void)
199 AppLog("Installer::OnRollback()");
200 return INSTALLER_ERROR_NONE;
204 Installer::OnUserCancel(void)
206 AppLog("Installer::OnUserCancel()");
207 return INSTALLER_ERROR_NONE;
211 Installer::GetContext(void)