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"
34 #include "SmackManager.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Io;
40 Installer::Installer(void)
45 Installer::~Installer(void)
50 Installer::Construct(InstallationContext* pContext)
52 __pContext = pContext;
54 if (InstallerUtil::IsSymlink(PATH_OPT_APPS) == false)
56 if (File::IsFileExist(PATH_OPT_APPS) == false)
58 Directory::Create(PATH_OPT_APPS, false);
59 InstallerUtil::ChangeMode(PATH_OPT_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
63 if (File::IsFileExist(PATH_OPT_USR) == false)
65 Directory::Create(PATH_OPT_USR, false);
66 InstallerUtil::ChangeMode(PATH_OPT_USR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
69 if (File::IsFileExist(PATH_OPT_USR_APPS) == false)
71 Directory::Create(PATH_OPT_USR_APPS, false);
72 InstallerUtil::ChangeMode(PATH_OPT_USR_APPS, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
75 return INSTALLER_ERROR_NONE;
79 Installer::GetNext(InstallationStep step)
81 if (step == INSTALLER_STEP_PARSE_SIGNATURE)
83 step = INSTALLER_STEP_END;
87 step = (InstallationStep)(step + 1);
94 Installer::OnInit(void)
96 AppLog("Installer::OnInit()");
98 return INSTALLER_ERROR_NONE;
102 Installer::OnRegister(void)
104 AppLog("------------------------------------------");
105 AppLog("Installer::OnRegister() - START");
106 InstallationContext* pContext = GetContext();
107 TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "pContext is null");
109 InstallerOperation operation = pContext->GetInstallerOperation();
111 DatabaseManager databaseManager;
113 if (operation == INSTALLER_OPERATION_INSTALL)
115 databaseManager.UnregisterPackageInfo(pContext);
116 databaseManager.RegisterPackageInfo(pContext);
120 databaseManager.UnregisterPackageInfo(pContext);
122 AppLog("Installer::OnRegister() - END");
123 AppLog("------------------------------------------");
125 return INSTALLER_ERROR_NONE;
129 Installer::OnEnd(void)
131 AppLog("------------------------------------------");
132 AppLog("Installer::OnEnd() - START");
134 InstallationContext* pContext = GetContext();
135 TryReturn(pContext, INSTALLER_ERROR_INTERNAL_STATE, "pContext is null");
137 SmackManager smackManager;
138 smackManager.Construct(pContext);
140 InstallerOperation operation = pContext->GetInstallerOperation();
141 ConfigurationManager configurationManager;
142 SignatureManager sigManager;
143 sigManager.Construct(pContext);
145 pContext->SetContinue(false);
147 if (operation == INSTALLER_OPERATION_INSTALL)
149 res = smackManager.Install(pContext->__packageId);
150 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "smackManager.Install(%ls) failed.", pContext->__packageId.GetPointer());
152 res = configurationManager.CreateFile(pContext);
153 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "CreateFile() failed.");
155 res = PermissionManager::SetDirectory(pContext);
156 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetDirectory() failed.");
158 res = PermissionManager::SetFile(pContext);
159 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "SetFile() failed.");
161 res = configurationManager.PostInstall(pContext, false);
162 TryReturn(res, INSTALLER_ERROR_INTERNAL_STATE, "PostInstall() failed.");
164 res = sigManager.UnregisterCertInfo();
165 TryReturn(res, INSTALLER_ERROR_DATABASE, "UnregisterCertInfo() failed.");
167 res = sigManager.RegisterCertInfo();
168 TryReturn(res, INSTALLER_ERROR_DATABASE, "RegisterCertInfo() failed.");
170 else if (operation == INSTALLER_OPERATION_UNINSTALL)
172 configurationManager.RemoveFile(pContext);
173 sigManager.UnregisterCertInfo();
174 configurationManager.PostUninstall(pContext);
176 res = smackManager.Uninstall(pContext->__packageId);
177 AppLog("smackManager.Uninstall(%ls) res = [%d]", pContext->__packageId.GetPointer(), res);
180 AppLog("Installer::OnEnd() - END");
181 AppLog("------------------------------------------");
183 return INSTALLER_ERROR_NONE;
187 Installer::OnError(void)
189 AppLog("Installer::OnError()");
191 InstallerOperation operation = __pContext->GetInstallerOperation();
192 ConfigurationManager configurationManager;
194 if (operation == INSTALLER_OPERATION_INSTALL)
196 configurationManager.PostInstall(__pContext, true);
200 configurationManager.PostUninstall(__pContext);
203 return INSTALLER_ERROR_NONE;
207 Installer::OnRollback(void)
209 AppLog("Installer::OnRollback()");
210 return INSTALLER_ERROR_NONE;
214 Installer::OnUserCancel(void)
216 AppLog("Installer::OnUserCancel()");
217 return INSTALLER_ERROR_NONE;
221 Installer::GetContext(void)